[Gtkada-wrapper-devel] SF.net SVN: gtkada-wrapper: [24] trunk
Brought to you by:
bechir_zalila
From: <bec...@us...> - 2006-11-30 20:53:52
|
Revision: 24 http://svn.sourceforge.net/gtkada-wrapper/?rev=24&view=rev Author: bechir_zalila Date: 2006-11-30 12:53:52 -0800 (Thu, 30 Nov 2006) Log Message: ----------- * Implementation of text insertion on the drawing area Modified Paths: -------------- trunk/TODO trunk/examples/basic_drawings/basic_drawings.adb trunk/examples/fractal/fractal.adb trunk/src/gtkada_wrapper.adb trunk/src/gtkada_wrapper.ads Modified: trunk/TODO =================================================================== --- trunk/TODO 2006-11-30 18:50:56 UTC (rev 23) +++ trunk/TODO 2006-11-30 20:53:52 UTC (rev 24) @@ -1,5 +1,4 @@ /src: - * Implement text display on the drawing area * Implement image insertion * Implement Text area Modified: trunk/examples/basic_drawings/basic_drawings.adb =================================================================== --- trunk/examples/basic_drawings/basic_drawings.adb 2006-11-30 18:50:56 UTC (rev 23) +++ trunk/examples/basic_drawings/basic_drawings.adb 2006-11-30 20:53:52 UTC (rev 24) @@ -28,6 +28,21 @@ begin Create_Main_Window; + Set_Color (Red); + Jump (100.0, 400.0); + + Set_Color (Red); + Insert_Text ("Basic Drawings", 10.0, Right, Center); + + Jump (100.0, 350.0); + Set_Color (Pink); + Insert_Text ("Basic Drawings", 15.0, Center, Center); + + Jump (100.0, 300.0); + Set_Color (Gray); + Insert_Text ("Basic Drawings", 20.0, Left, Center); + + Jump (250.0, 250.0); Set_Thickness (15.0); Set_Angle (0.0); Modified: trunk/examples/fractal/fractal.adb =================================================================== --- trunk/examples/fractal/fractal.adb 2006-11-30 18:50:56 UTC (rev 23) +++ trunk/examples/fractal/fractal.adb 2006-11-30 20:53:52 UTC (rev 24) @@ -38,8 +38,11 @@ begin Create_Main_Window; - Set_Color (Red); + Set_Color (Orange); + Jump (250.0, 250.0); + Insert_Text ("Fractal", 30.0, Center, Center); + Set_Color (Blue); Draw_Fractal (150.0, 100.0, 350.0, 400.0); Draw_Fractal (350.0, 400.0, 150.0, 100.0); Modified: trunk/src/gtkada_wrapper.adb =================================================================== --- trunk/src/gtkada_wrapper.adb 2006-11-30 18:50:56 UTC (rev 23) +++ trunk/src/gtkada_wrapper.adb 2006-11-30 20:53:52 UTC (rev 24) @@ -13,6 +13,7 @@ with Gdk.Color; use Gdk.Color; with Gdk.Types; use Gdk.Types; with Gdk.Event; use Gdk.Event; +with Gdk.Font; use Gdk.Font; with Gdk.Pixmap; use Gdk.Pixmap; with Gdk.Window; use Gdk.Window; with Gdk.Drawable; use Gdk.Drawable; @@ -189,7 +190,6 @@ type String_Ptr is access all String; procedure Free is new Unchecked_Deallocation (String, String_Ptr); - pragma Unreferenced (Free); type Float_Array_Access is access all Float_Array; -- To be able to have a record of unconstrained type @@ -1533,10 +1533,76 @@ ------------- procedure Do_Text (Cmd : in out Command) is - pragma Unreferenced (Cmd); + Font : Gdk_Font; + Pt_Size_Str : constant String := Natural (Cmd.Size)'Img; + X_Pix : Gint; + Y_Pix : Gint; + Lb : Gint; + Rb : Gint; + Width : Gint; + Asc : Gint; + Desc : Gint; + Font_Name : constant String := "-*-helvetica-*-r-*-*-" + & Pt_Size_Str (2 .. Pt_Size_Str'Last) + & "-*-*-*-*-*-*-*"; begin pragma Debug (O ("Do_Text: begin")); - null; -- FIXME + + -- Load a font with the given size + + pragma Debug (O ("Loading font " & Font_Name)); + Load (Font, Font_Name); + pragma Debug (O ("Font " & Font_Name & " loaded")); + + -- Get the string metrics to align it properly + + pragma Debug (O ("Get text metrics")); + String_Extents (Font, Cmd.Text.all, Lb, Rb, Width, Asc, Desc); + pragma Debug (O ("Text metrics Got")); + + case Cmd.X_Justify is + when Left => + X_Pix := Gint (Brush_X); + + when Center => + X_Pix := Gint (Brush_X) - Width / 2; + + when Right => + X_Pix := Gint (Brush_X) - Width; + end case; + + case Cmd.Y_Justify is + when Bottom => + Y_Pix := Height - Gint (Brush_Y) - Desc; + + when Center => + Y_Pix := Height - Gint (Brush_Y) + Asc / 2; + + when Top => + Y_Pix := Height - Gint (Brush_Y) + Asc; + end case; + + -- Draw the aligned text + + Draw_Text (Get_Window (Drawing_Area), + Font, + Graphic_Context, + X_Pix, + Y_Pix, + Cmd.Text.all); + + -- Backup + + Draw_Text (Pixmap, + Font, + Graphic_Context, + X_Pix, + Y_Pix, + Cmd.Text.all); + + -- Deallocate the text + + Free (Cmd.Text); pragma Debug (O ("Do_Text: done")); end Do_Text; Modified: trunk/src/gtkada_wrapper.ads =================================================================== --- trunk/src/gtkada_wrapper.ads 2006-11-30 18:50:56 UTC (rev 23) +++ trunk/src/gtkada_wrapper.ads 2006-11-30 20:53:52 UTC (rev 24) @@ -59,8 +59,8 @@ -- Create an RGB (Red Green Blue) color. All the given parameter -- are considered modulo 65536, the maximal value of a color -- composant. - -- IMPORTANT NOTE: All custom colors must be declared - -- *before* the call to Create_Main_Window + -- IMPORTANT NOTE: All custom colors must be declared *before* the + -- call to Create_Main_Window Black : constant Color_Type; Red : constant Color_Type; @@ -167,7 +167,7 @@ X_Justification : X_Justification_Type := Center; Y_Justification : Y_Justification_Type := Center); -- Draw a text string justified at the virtual brush's current - -- location. The size is expressed in points. + -- location. The size is expressed in pixels. procedure Draw_Circle (Radius : Float); -- Draw a circle with radius 'Radius' and with the center at the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |