summaryrefslogtreecommitdiff
path: root/src/fltk-devices-surface.adb
blob: a6ef6ccc37e12053c4e4a60ff2d7dff8b721d148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180


--  Programmed by Jedidiah Barber
--  Released into the public domain


package body FLTK.Devices.Surface is


    ------------------------
    --  Functions From C  --
    ------------------------

    function new_fl_surface_device
           (G : in Storage.Integer_Address)
        return Storage.Integer_Address;
    pragma Import (C, new_fl_surface_device, "new_fl_surface_device");
    pragma Inline (new_fl_surface_device);

    procedure free_fl_surface_device
           (S : in Storage.Integer_Address);
    pragma Import (C, free_fl_surface_device, "free_fl_surface_device");
    pragma Inline (free_fl_surface_device);




    procedure fl_surface_device_set_current
           (S : in Storage.Integer_Address);
    pragma Import (C, fl_surface_device_set_current, "fl_surface_device_set_current");
    pragma Inline (fl_surface_device_set_current);

    function fl_surface_device_get_surface
        return Storage.Integer_Address;
    pragma Import (C, fl_surface_device_get_surface, "fl_surface_device_get_surface");
    pragma Inline (fl_surface_device_get_surface);




    function fl_surface_device_get_driver
           (S : in Storage.Integer_Address)
        return Storage.Integer_Address;
    pragma Import (C, fl_surface_device_get_driver, "fl_surface_device_get_driver");
    pragma Inline (fl_surface_device_get_driver);

    procedure fl_surface_device_set_driver
           (S, G : in Storage.Integer_Address);
    pragma Import (C, fl_surface_device_set_driver, "fl_surface_device_set_driver");
    pragma Inline (fl_surface_device_set_driver);




    -------------------
    --  Destructors  --
    -------------------

    procedure Finalize
           (This : in out Surface_Device) is
    begin
        if This.Void_Ptr /= Null_Pointer and This.Needs_Dealloc then
            free_fl_surface_device (This.Void_Ptr);
            This.Void_Ptr := Null_Pointer;
        end if;
    end Finalize;




    --------------------
    --  Constructors  --
    --------------------

    package body Forge is

        function Create
               (Graphics : in out FLTK.Devices.Graphics.Graphics_Driver)
            return Surface_Device is
        begin
            return This : Surface_Device do
                This.Void_Ptr := new_fl_surface_device (Wrapper (Graphics).Void_Ptr);
                This.My_Driver := Graphics'Unchecked_Access;
            end return;
        end Create;

    end Forge;




    -------------------------
    --  Static Attributes  --
    -------------------------

    Original_Surface  : aliased Surface_Device;
    Original_Graphics : aliased FLTK.Devices.Graphics.Graphics_Driver;

    Current_Surface : access Surface_Device'Class := Original_Surface'Access;


    procedure Set_Current_Bookkeep
           (Surface : in out Surface_Device'Class) is
    begin
        Current_Surface := Surface'Unchecked_Access;
    end Set_Current_Bookkeep;




    -----------------------
    --  API Subprograms  --
    -----------------------

    function Get_Current
        return Surface_Device_Reference is
    begin
        return Ref : Surface_Device_Reference (Data => Current_Surface);
    end Get_Current;


    procedure Set_Current
           (This : in out Surface_Device) is
    begin
        fl_surface_device_set_current (This.Void_Ptr);
        This.Set_Current_Bookkeep;
    end Set_Current;


    function Get_Original
        return Surface_Device_Reference is
    begin
        return Ref : Surface_Device_Reference (Data => Original_Surface'Access);
    end Get_Original;




    function Has_Driver
           (This : in Surface_Device)
        return Boolean is
    begin
        return This.My_Driver /= null and then
            Wrapper (This.My_Driver.all).Void_Ptr /= Null_Pointer;
    end Has_Driver;


    function Get_Driver
           (This : in out Surface_Device)
        return FLTK.Devices.Graphics.Graphics_Driver_Reference is
    begin
        return Ref : FLTK.Devices.Graphics.Graphics_Driver_Reference (Data => This.My_Driver);
    end Get_Driver;


    procedure Set_Driver
           (This   : in out Surface_Device;
            Driver : in out FLTK.Devices.Graphics.Graphics_Driver'Class) is
    begin
        fl_surface_device_set_driver (This.Void_Ptr, Wrapper (Driver).Void_Ptr);
        This.My_Driver := Driver'Unchecked_Access;
    end Set_Driver;


begin


    Original_Surface.Void_Ptr := fl_surface_device_get_surface;
    Original_Surface.Needs_Dealloc := False;

    Wrapper (Original_Graphics).Void_Ptr :=
        fl_surface_device_get_driver (Original_Surface.Void_Ptr);
    Wrapper (Original_Graphics).Needs_Dealloc := False;

    Original_Surface.My_Driver := Original_Graphics'Access;


end FLTK.Devices.Surface;