Author: jluke
Date: 2005-04-21 16:11:03 -0400 (Thu, 21 Apr 2005)
New Revision: 43417
Added:
trunk/gtk-sharp/sample/GtkDemo/DemoRotatedText.cs
Modified:
trunk/gtk-sharp/sample/GtkDemo/Makefile.am
trunk/gtk-sharp/sample/GtkDemo/TODO
Log:
add rotated text demo
Added: trunk/gtk-sharp/sample/GtkDemo/DemoRotatedText.cs
===================================================================
--- trunk/gtk-sharp/sample/GtkDemo/DemoRotatedText.cs 2005-04-21 20:00:20 UTC
(rev 43416)
+++ trunk/gtk-sharp/sample/GtkDemo/DemoRotatedText.cs 2005-04-21 20:11:03 UTC
(rev 43417)
@@ -0,0 +1,94 @@
+using System;
+using Gtk;
+using Pango;
+
+namespace GtkDemo
+{
+ [Demo ("Rotated Text", "DemoRotatedText.cs")]
+ public class DemoRotatedText : Window
+ {
+ const int RADIUS = 150;
+ const int N_WORDS = 10;
+
+ public DemoRotatedText () : base ("Rotated text")
+ {
+ DrawingArea drawingArea = new DrawingArea ();
+ Gdk.Color white = new Gdk.Color (0xff, 0xff, 0xff);
+
+ // This overrides the background color from the theme
+ drawingArea.ModifyBg (StateType.Normal, white);
+ drawingArea.ExposeEvent += new ExposeEventHandler
(RotatedTextExposeEvent);
+
+ this.Add (drawingArea);
+ this.DeleteEvent += new DeleteEventHandler
(OnWinDelete);
+ this.SetDefaultSize (2 * RADIUS, 2 * RADIUS);
+ this.ShowAll ();
+ }
+
+ void RotatedTextExposeEvent (object sender, ExposeEventArgs a)
+ {
+ DrawingArea drawingArea = sender as DrawingArea;
+
+ int width = drawingArea.Allocation.Width;
+ int height = drawingArea.Allocation.Height;
+
+ double deviceRadius;
+
+ // Get the default renderer for the screen, and set it
up for drawing
+ Gdk.PangoRenderer renderer = new Gdk.PangoRenderer
(drawingArea.Screen);
+ renderer.Drawable = drawingArea.GdkWindow;
+ renderer.Gc = drawingArea.Style.BlackGC;
+
+ // Set up a transformation matrix so that the user
space coordinates for
+ // the centered square where we draw are [-RADIUS,
RADIUS], [-RADIUS, RADIUS]
+ // We first center, then change the scale
+ deviceRadius = Math.Min (width, height) / 2;
+ Matrix matrix = new Matrix ();
+ matrix.Translate (deviceRadius + (width - 2 *
deviceRadius) / 2, deviceRadius + (height - 2 * deviceRadius) / 2);
+ matrix.Scale (deviceRadius / RADIUS, deviceRadius /
RADIUS);
+
+ // Create a PangoLayout, set the font and text
+ Context context = drawingArea.CreatePangoContext ();
+ Pango.Layout layout = new Pango.Layout (context);
+ layout.SetText ("Text");
+ FontDescription desc = FontDescription.FromString
("Sans Bold 27");
+ layout.FontDescription = desc;
+
+ // Draw the layout N_WORDS times in a circle
+ for (int i = 0; i < N_WORDS; i++)
+ {
+ Gdk.Color color = new Gdk.Color ();
+ Matrix rotatedMatrix = matrix;
+ int w, h;
+ double angle = (360 * i) / N_WORDS;
+
+ // Gradient from red at angle == 60 to blue at
angle == 300
+ color.Red = (ushort) (65535 * (1 + Math.Cos
((angle - 60) * Math.PI / 180)) / 2);
+ color.Green = 0;
+ color.Blue = (ushort) (65535 - color.Red);
+
+ renderer.SetOverrideColor
(RenderPart.Foreground, color);
+
+ rotatedMatrix.Rotate (angle);
+ context.Matrix = rotatedMatrix;
+
+ // Inform Pango to re-layout the text with the
new transformation matrix
+ layout.ContextChanged ();
+ layout.GetSize (out w, out h);
+ renderer.DrawLayout (layout, - w / 2, (int) (-
RADIUS * Pango.Scale.PangoScale));
+ }
+
+ // Clean up default renderer, since it is shared
+ renderer.SetOverrideColor (RenderPart.Foreground,
Gdk.Color.Zero);
+ renderer.Drawable = null;
+ renderer.Gc = null;
+ }
+
+ void OnWinDelete (object sender, DeleteEventArgs a)
+ {
+ this.Hide ();
+ this.Dispose ();
+ }
+ }
+}
+
Modified: trunk/gtk-sharp/sample/GtkDemo/Makefile.am
===================================================================
--- trunk/gtk-sharp/sample/GtkDemo/Makefile.am 2005-04-21 20:00:20 UTC (rev
43416)
+++ trunk/gtk-sharp/sample/GtkDemo/Makefile.am 2005-04-21 20:11:03 UTC (rev
43417)
@@ -25,6 +25,7 @@
DemoMenus.cs \
DemoPanes.cs \
DemoPixbuf.cs \
+ DemoRotatedText.cs \
DemoSizeGroup.cs \
DemoStockBrowser.cs \
DemoTextView.cs \
Modified: trunk/gtk-sharp/sample/GtkDemo/TODO
===================================================================
--- trunk/gtk-sharp/sample/GtkDemo/TODO 2005-04-21 20:00:20 UTC (rev 43416)
+++ trunk/gtk-sharp/sample/GtkDemo/TODO 2005-04-21 20:11:03 UTC (rev 43417)
@@ -6,9 +6,12 @@
DemoMain
- syntax highlighting
-"Change Display" is missing
+RotatedText
+ - doesn't quite work yet
-Future
-------
-IconView - gtk 2.6
-RotatedText - pango 1.6
+IconView
+ - missing
+
+Chang Display
+ - missing
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches