@@ -109,6 +109,8 @@ package body Ada_GUI is
109
109
Context : Ada_GUI.Gnoga.Gui.Element.Canvas.Context_2D.Context_2D_Access;
110
110
Width : Positive;
111
111
Height : Positive;
112
+ when Image =>
113
+ Img : Gnoga.Gui.Element.Common.IMG_Access;
112
114
when Password_Box =>
113
115
Password : Gnoga.Gui.Element.Form.Password_Access;
114
116
Password_Label : Gnoga.Gui.Element.Form.Label_Access;
@@ -250,6 +252,24 @@ package body Ada_GUI is
250
252
return ID;
251
253
end New_Graphic_Area ;
252
254
255
+ function New_Image (Row : Positive := 1 ;
256
+ Column : Positive := 1 ;
257
+ Source : String := " " ;
258
+ Description : String := " " ;
259
+ Break_Before : Boolean := False)
260
+ return Widget_ID is
261
+ ID : constant Widget_ID := (Value => Widget_List.Last_Index + 1 );
262
+
263
+ Widget : Widget_Info (Kind => Image);
264
+ begin -- New_Image
265
+ Break (Desired => Break_Before, Row => Row, Column => Adjusted (Row, Column) );
266
+ Widget.Img := new Gnoga.Gui.Element.Common.IMG_Type;
267
+ Widget.Img.Create (Parent => Form (Row, Adjusted (Row, Column) ), URl_Source => Source, Alternative_Text => Description);
268
+ Widget_List.Append (New_Item => Widget);
269
+
270
+ return ID;
271
+ end New_Image ;
272
+
253
273
function New_Password_Box (Row : Positive := 1 ;
254
274
Column : Positive := 1 ;
255
275
Text : String := " " ;
@@ -447,6 +467,8 @@ package body Ada_GUI is
447
467
Widget.Check_Label.Hidden (Value => Hidden);
448
468
when Graphic_Area =>
449
469
Widget.Canvas.Hidden (Value => Hidden);
470
+ when Image =>
471
+ Widget.Img.Hidden (Value => Hidden);
450
472
when Password_Box =>
451
473
Widget.Password.Hidden (Value => Hidden);
452
474
Widget.Password_Label.Hidden (Value => Hidden);
@@ -482,6 +504,8 @@ package body Ada_GUI is
482
504
Widget.Check_Label.Visible (Value => Visible);
483
505
when Graphic_Area =>
484
506
Widget.Canvas.Visible (Value => Visible);
507
+ when Image =>
508
+ Widget.Img.Visible (Value => Visible);
485
509
when Password_Box =>
486
510
Widget.Password.Visible (Value => Visible);
487
511
Widget.Password_Label.Visible (Value => Visible);
@@ -526,7 +550,11 @@ package body Ada_GUI is
526
550
procedure Set_Source (ID : in Widget_ID; Source : in String) is
527
551
Widget : Widget_Info := Widget_List.Element (ID.Value);
528
552
begin -- Set_Source
529
- Widget.Audio.Media_Source (Source => Source);
553
+ if ID.Kind = Audio_Player then
554
+ Widget.Audio.Media_Source (Source => Source);
555
+ else
556
+ Widget.Img.URL_Source (Value => Source);
557
+ end if ;
530
558
end Set_Source ;
531
559
532
560
function Source (ID : Widget_ID) return String is
@@ -763,6 +791,8 @@ package body Ada_GUI is
763
791
Widget.Check_Label.Background_Color (RGBA => Gnoga_Color (Color) );
764
792
when Graphic_Area =>
765
793
Widget.Canvas.Background_Color (RGBA => Gnoga_Color (Color) );
794
+ when Image =>
795
+ Widget.Img.Background_Color (RGBA => Gnoga_Color (Color) );
766
796
when Password_Box =>
767
797
Widget.Password.Background_Color (RGBA => Gnoga_Color (Color) );
768
798
Widget.Password_Label.Background_Color (RGBA => Gnoga_Color (Color) );
@@ -798,6 +828,8 @@ package body Ada_GUI is
798
828
Widget.Check_Label.Color (RGBA => Gnoga_Color (Color) );
799
829
when Graphic_Area =>
800
830
Widget.Canvas.Color (RGBA => Gnoga_Color (Color) );
831
+ when Image =>
832
+ Widget.Img.Color (RGBA => Gnoga_Color (Color) );
801
833
when Password_Box =>
802
834
Widget.Password.Color (RGBA => Gnoga_Color (Color) );
803
835
Widget.Password_Label.Color (RGBA => Gnoga_Color (Color) );
@@ -1009,30 +1041,49 @@ package body Ada_GUI is
1009
1041
procedure Replace_Pixels (ID : in Widget_ID; Image : in Widget_ID; X : in Integer := 0 ; Y : in Integer := 0 ) is
1010
1042
Widget : Widget_Info := Widget_List.Element (ID.Value);
1011
1043
begin -- Replace_Pixels
1012
- Widget.Context.Draw_Image (Image => Widget_List.Element (Image.Value).Canvas.all , X => X, Y => Y);
1044
+ if Image.Kind = Graphic_Area then
1045
+ Widget.Context.Draw_Image (Image => Widget_List.Element (Image.Value).Canvas.all , X => X, Y => Y);
1046
+ else
1047
+ Widget.Context.Draw_Image (Image => Widget_List.Element (Image.Value).Img.all , X => X, Y => Y);
1048
+ end if ;
1013
1049
end Replace_Pixels ;
1014
1050
1015
1051
procedure Replace_Pixels (ID : in Widget_ID; Image : in Image_Data; X : in Integer := 0 ; Y : in Integer := 0 ) is
1016
- Widget : Widget_Info := Widget_List.Element (ID.Value);
1052
+ Widget : Widget_Info := Widget_List.Element (ID.Value);
1053
+ Pixel : Gnoga.Pixel_Data_Type (1 .. Image'Length (2 ), 1 .. Image'Length (1 ) );
1054
+ Img : Gnoga.Gui.Element.Canvas.Context_2D.Image_Data_Type;
1017
1055
begin -- Replace_Pixels
1018
- All_Rows : for R in Image'Range (1 ) loop
1019
- All_Columns : for C in Image'Range (2 ) loop
1020
- Widget.Context.Pixel (X => X + C, Y => Y + R, Color => Gnoga_Pixel (Image (R, C) ) );
1021
- end loop All_Columns;
1022
- end loop All_Rows;
1056
+ Pixel_Rows : for R in Image'Range (1 ) loop -- This is a three-step process: 1. Convert Image into Pixel
1057
+ Pixel_Columns : for C in Image'Range (2 ) loop
1058
+ Pixel (C + 1 , R + 1 ) := Gnoga_Pixel (Image (R, C) );
1059
+ end loop Pixel_Columns;
1060
+ end loop Pixel_Rows;
1061
+
1062
+ Widget.Context.Create_Image_Data (Image_Data => Img, Width => Image'Length (2 ), Height => Image'Length (1 ) );
1063
+ Img.Data (Value => Pixel); -- 2. Put Pixel into Img
1064
+ Widget.Context.Put_Image_Data (Image_Data => Img, Left => X, Top => Y); -- 3. Display Img in Context at X, Y
1023
1065
end Replace_Pixels ;
1024
1066
1025
1067
function Data (ID : in Widget_ID) return Image_Data is
1026
- Widget : Widget_Info := Widget_List.Element (ID.Value);
1027
- Result : Image_Data ( 0 .. Widget.Height - 1 , 0 .. Widget.Width - 1 ) ;
1068
+ Widget : Widget_Info := Widget_List.Element (ID.Value);
1069
+ Img : Gnoga.Gui.Element.Canvas.Context_2D.Image_Data_Type ;
1028
1070
begin -- Data
1029
- All_Rows : for Y in Result' Range ( 1 ) loop
1030
- All_Columns : for X in Result' Range ( 2 ) loop
1031
- Result (Y, X) := AG_Color (Widget.Context.Pixel (X, Y) );
1032
- end loop All_Columns;
1033
- end loop All_Rows;
1071
+ -- This is a three-step process: 1. Extract the image in Context into Img
1072
+ Widget.Context.Get_Image_Data (Image_Data => Img, Left => 0 , Top => 0 , Width => Widget.Width, Height => Widget.Height);
1073
+
1074
+ Get_Data : declare -- 2. Get the data from Img into Pixel
1075
+ Pixel : constant Gnoga.Pixel_Data_Type := Img.Data; -- 1st dimension X/columns; 2nd, Y/rows
1034
1076
1035
- return Result;
1077
+ Result : Image_Data (0 .. Widget.Height - 1 , 0 .. Widget.Width - 1 );
1078
+ begin -- Get_Data
1079
+ All_Rows : for Y in Result'Range (1 ) loop -- 3. Convert Pixel into Result and return it
1080
+ All_Columns : for X in Result'Range (2 ) loop
1081
+ Result (Y, X) := AG_Color (Pixel (X + 1 , Y + 1 ) );
1082
+ end loop All_Columns;
1083
+ end loop All_Rows;
1084
+
1085
+ return Result;
1086
+ end Get_Data ;
1036
1087
end Data ;
1037
1088
1038
1089
procedure Write_BMP (Name : in String; Image : in Image_Data) is
0 commit comments