[Gtkada-wrapper-devel] SF.net SVN: gtkada-wrapper: [15] trunk
Brought to you by:
bechir_zalila
From: <bec...@us...> - 2006-11-26 23:48:19
|
Revision: 15 http://svn.sourceforge.net/gtkada-wrapper/?rev=15&view=rev Author: bechir_zalila Date: 2006-11-26 15:48:18 -0800 (Sun, 26 Nov 2006) Log Message: ----------- * Fixed a bug in the color allocation. All color have to be allocated at before the execution of the Gtk main loop. * Finished the basic drawings examples Modified Paths: -------------- trunk/TODO trunk/examples/basic_drawings/basic_drawings.adb trunk/examples/basic_drawings/basic_drawings.gpr trunk/examples/empty_window/empty_window.adb trunk/examples/empty_window/empty_window.gpr trunk/src/gtkada_wrapper.adb trunk/src/gtkada_wrapper.ads Modified: trunk/TODO =================================================================== --- trunk/TODO 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/TODO 2006-11-26 23:48:18 UTC (rev 15) @@ -1,5 +1,6 @@ /src: - * Implement custom colors + * Implement fill color + * Implement forms * Implement Text area * Remove the Idle loop Modified: trunk/examples/basic_drawings/basic_drawings.adb =================================================================== --- trunk/examples/basic_drawings/basic_drawings.adb 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/examples/basic_drawings/basic_drawings.adb 2006-11-26 23:48:18 UTC (rev 15) @@ -4,7 +4,7 @@ -- This example tests some basic drawings using GTKAda Wrapper -with GTKAda_Wrapper; use GTKAda_Wrapper; +with Gtkada_Wrapper; use Gtkada_Wrapper; with Ada.Text_IO; @@ -22,6 +22,9 @@ Magenta, Cyan, Orange); + + My_Color_1 : constant Color_Type := RGB (30000, 30000, 30000); + My_Color_2 : constant Color_Type := RGB (50000, 50000, 0); begin Create_Main_Window; @@ -34,6 +37,22 @@ Rotate (45.0); end loop; + Set_Line_Color (My_Color_1); + Jump (50.0, 50.0); + Spot (20.0); + + Jump (100.0, 100.0); + Spot (10.0); + + Set_Line_Color (My_Color_2); + Jump (100.0, 400.0); + Spot (10.0); + + Set_Line_Color (My_Color_2); + Set_Thickness (8.0); + Line (100.0, 100.0, 200.0, 400.0); + Line (100.0, 100.0, 100.0, 400.0); + Rafresh; Get_Mouse_Pointer (X, Y, Button); Modified: trunk/examples/basic_drawings/basic_drawings.gpr =================================================================== --- trunk/examples/basic_drawings/basic_drawings.gpr 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/examples/basic_drawings/basic_drawings.gpr 2006-11-26 23:48:18 UTC (rev 15) @@ -2,4 +2,9 @@ project Basic_Drawings is for main use ("basic_drawings.adb"); + + Build : GTKAda_Wrapper.Build_Type := External ("BUILD", "debug"); + + package Compiler renames GTKAda_Wrapper.Compiler; + package Binder renames GTKAda_Wrapper.Binder; end Basic_Drawings; Modified: trunk/examples/empty_window/empty_window.adb =================================================================== --- trunk/examples/empty_window/empty_window.adb 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/examples/empty_window/empty_window.adb 2006-11-26 23:48:18 UTC (rev 15) @@ -4,7 +4,7 @@ -- This example, creates an empty default main window then exits -with GTKAda_Wrapper; use GTKAda_Wrapper; +with Gtkada_Wrapper; use Gtkada_Wrapper; with Ada.Text_IO; Modified: trunk/examples/empty_window/empty_window.gpr =================================================================== --- trunk/examples/empty_window/empty_window.gpr 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/examples/empty_window/empty_window.gpr 2006-11-26 23:48:18 UTC (rev 15) @@ -2,4 +2,9 @@ project Empty_Window is for main use ("empty_window.adb"); + + Build : GTKAda_Wrapper.Build_Type := External ("BUILD", "debug"); + + package Compiler renames GTKAda_Wrapper.Compiler; + package Binder renames GTKAda_Wrapper.Binder; end Empty_Window; Modified: trunk/src/gtkada_wrapper.adb =================================================================== --- trunk/src/gtkada_wrapper.adb 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/src/gtkada_wrapper.adb 2006-11-26 23:48:18 UTC (rev 15) @@ -31,7 +31,7 @@ with Protected_Queue; -pragma Debug_Policy (Ignore); -- 'Ignore' Or 'Check' +pragma Debug_Policy (Check); -- 'Ignore' Or 'Check' package body Gtkada_Wrapper is @@ -76,9 +76,9 @@ Y_End : Float); -- Draw a line with the current graphic properties - procedure Allocate_Predefined_Colors; - -- Allocate the predefined colors. This is necessary for them to - -- be valid. + procedure Allocate_Colors; + -- Allocate the predefined colors and the user colors. This is + -- necessary for them to be valid. ---------------------- -- Global Variables -- @@ -126,6 +126,10 @@ -- The table of colors. Predefined colors are allocated at the -- beginning of the table. User colors are allocated after. + N_Predefined_Colors : constant Color_Type := 13; + -- IMPRTANT: Youmust edit this variable each time the predefined + -- color set is modified. + -- User_Task : Task_Id := Null_Task_ID; -- Task that sets up world. -- Pixmap : Gdk_Pixmap; -- Pixmap used as backing store. -- Pausing : Boolean := False; @@ -454,7 +458,7 @@ -- Allocate predefined colors - Allocate_Predefined_Colors; + Allocate_Colors; Set_Foreground (Graphic_Context, To_Gdk_Color (Line_Color)); Set_Background (Graphic_Context, To_Gdk_Color (Fill_Color)); @@ -466,11 +470,11 @@ end Main_Window_Type; - -------------------------------- - -- Allocate_Predefined_Colors -- - -------------------------------- + --------------------- + -- Allocate_Colors -- + --------------------- - procedure Allocate_Predefined_Colors is + procedure Allocate_Colors is procedure Allocate_Predefined_Color (Col : Color_Type; R : Guint16; @@ -497,6 +501,11 @@ Color_Table.Set_Item (Col, Gdk_Col); end Allocate_Predefined_Color; begin + -- Allocate predefined colors + + -- IMPORTANT: Don't forget to update N_Predefined_Colors each + -- time the predefined color set is edited. + Allocate_Predefined_Color (Black, 0, 0, 0); Allocate_Predefined_Color (Red, 65535, 0, 0); Allocate_Predefined_Color (Green, 0, 65535, 0); @@ -510,8 +519,15 @@ Allocate_Predefined_Color (Gray, 32767, 32767, 32767); Allocate_Predefined_Color (Light_Gray, 46003, 46003, 46003); Allocate_Predefined_Color (White, 65535, 65535, 65535); - end Allocate_Predefined_Colors; + -- Allocate user colors, which exist already in the color table + + for I in N_Predefined_Colors + 1 .. Color_Table.Last loop + Alloc (Colormap => Gtk.Widget.Get_Default_Colormap, + Color => Color_Table.Table (I)); + end loop; + end Allocate_Colors; + ------------------------------ -- Assert_Main_Window_Exits -- ------------------------------ @@ -903,7 +919,7 @@ X_Start : constant Float := Cmd.X_Start; Y_Start : constant Float := Cmd.Y_Start; X_End : constant Float := Cmd.X_End; - Y_End : constant Float := Cmd.X_End; + Y_End : constant Float := Cmd.Y_End; begin pragma Debug (O ("Do_Line_With_Start_End: begin")); Draw_Line (X_Start, Y_Start, X_End, Y_End); @@ -1551,13 +1567,29 @@ --------- function RGB (R : Integer; G : Integer; B : Integer) return Color_Type is - Gdk_Col : Gdk_Color; + use Color_Table; + + Gdk_Col : Gdk_Color; + Position : Color_Type; begin - Color_Table.Increment_Last; - Set_Rgb (Gdk_Col, Guint16 (R), Guint16 (G), Guint16 (B)); - Alloc (Colormap => Gtk.Widget.Get_Default_Colormap, - Color => Gdk_Col); - return Color_Table.Last; + if Main_Window /= null then + raise Program_Error with "RGB must be calle BEFORE the" + & " creation of the main window"; + end if; + + Increment_Last; + if Last > N_Predefined_Colors + 1 then + Position := Last + 1; + else + Position := N_Predefined_Colors + 1; + end if; + + Set_Rgb (Gdk_Col, + Guint16 (R), + Guint16 (G), + Guint16 (B)); + Set_Item (Position, Gdk_Col); + return Position; end RGB; ------------ Modified: trunk/src/gtkada_wrapper.ads =================================================================== --- trunk/src/gtkada_wrapper.ads 2006-11-26 22:41:08 UTC (rev 14) +++ trunk/src/gtkada_wrapper.ads 2006-11-26 23:48:18 UTC (rev 15) @@ -12,6 +12,8 @@ package Gtkada_Wrapper is + pragma Elaborate_Body; + Lost_Main_Window : exception; -- This exception is raised if the user tries to manipulate the -- windows before creating it or after destroying it. @@ -55,7 +57,10 @@ function RGB (R : Integer; G : Integer; B : Integer) return Color_Type; -- Create an RGB (Red Green Blue) color. All the given parameter - -- are considered modulo 256. + -- are considered modulo 65536, the maximal value of a color + -- composant. + -- IMPORTANT NOTE: All custom color must be declared *before* the + -- call to Create_Main_Window Black : constant Color_Type; Red : constant Color_Type; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |