diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/c_fl_cairo_window.cpp | 110 | ||||
-rw-r--r-- | src/c_fl_cairo_window.h | 29 | ||||
-rw-r--r-- | src/fltk-widgets-groups-windows-double-cairo.adb | 221 | ||||
-rw-r--r-- | src/fltk-widgets-groups-windows-double-cairo.ads | 101 |
4 files changed, 461 insertions, 0 deletions
diff --git a/src/c_fl_cairo_window.cpp b/src/c_fl_cairo_window.cpp new file mode 100644 index 0000000..59b03ed --- /dev/null +++ b/src/c_fl_cairo_window.cpp @@ -0,0 +1,110 @@ + + +// Programmed by Jedidiah Barber +// Released into the public domain + + +#include <FL/Fl_Cairo_Window.H> +#include <FL/Fl_Double_Window.H> +#include "c_fl_cairo_window.h" + + + + +// Exports from Ada + +extern "C" void widget_draw_hook(void * ud); +extern "C" int widget_handle_hook(void * ud, int e); + + + + +// Attaching all relevant hooks and friends + +class My_Cairo_Window : +#ifdef FLTK_HAVE_CAIRO +public Fl_Cairo_Window +#else +public Fl_Double_Window +#endif +{ +public: +#ifdef FLTK_HAVE_CAIRO + using Fl_Cairo_Window::Fl_Cairo_Window; +#else + using Fl_Double_Window::Fl_Double_Window; +#endif + + friend void fl_cairo_window_draw(CAIROWINDOW w); + + int handle(int e); + +protected: + void draw(); +}; + + +void My_Cairo_Window::draw() { + widget_draw_hook(this->user_data()); +} + +int My_Cairo_Window::handle(int e) { + return widget_handle_hook(this->user_data(), e); +} + + + + +// Flattened C API begins here + +CAIROWINDOW new_fl_cairo_window(int x, int y, int w, int h, char * label) { + My_Cairo_Window *c = new My_Cairo_Window(x, y, w, h, label); + return c; +} + +CAIROWINDOW new_fl_cairo_window2(int w, int h, char * label) { + My_Cairo_Window *c = new My_Cairo_Window(w, h, label); + return c; +} + +CAIROWINDOW new_fl_cairo_window3(int w, int h) { + My_Cairo_Window *c = new My_Cairo_Window(w, h); + return c; +} + +void free_fl_cairo_window(CAIROWINDOW w) { + delete reinterpret_cast<My_Cairo_Window*>(w); +} + + + + +void fl_cairo_window_set_draw_cb(CAIROWINDOW w, void * cb) { + #ifdef FLTK_HAVE_CAIRO + reinterpret_cast<Fl_Cairo_Window*>(w)->set_draw_cb(reinterpret_cast<cairo_draw_cb>(cb)); + #else + (void)(w); + (void)(cb); + #endif +} + + + + +void fl_cairo_window_draw(CAIROWINDOW w) { + #ifdef FLTK_HAVE_CAIRO + reinterpret_cast<My_Cairo_Window*>(w)->Fl_Cairo_Window::draw(); + #else + reinterpret_cast<My_Cairo_Window*>(w)->Fl_Double_Window::draw(); + #endif +} + +int fl_cairo_window_handle(CAIROWINDOW w, int e) { + #ifdef FLTK_HAVE_CAIRO + return reinterpret_cast<My_Cairo_Window*>(w)->Fl_Cairo_Window::handle(e); + #else + return reinterpret_cast<My_Cairo_Window*>(w)->Fl_Double_Window::handle(e); + #endif +} + + diff --git a/src/c_fl_cairo_window.h b/src/c_fl_cairo_window.h new file mode 100644 index 0000000..e9a1437 --- /dev/null +++ b/src/c_fl_cairo_window.h @@ -0,0 +1,29 @@ + + +// Programmed by Jedidiah Barber +// Released into the public domain + + +#ifndef FL_CAIRO_WINDOW_GUARD +#define FL_CAIRO_WINDOW_GUARD + + +typedef void* CAIROWINDOW; + + +extern "C" CAIROWINDOW new_fl_cairo_window(int x, int y, int w, int h, char * label); +extern "C" CAIROWINDOW new_fl_cairo_window2(int w, int h, char * label); +extern "C" CAIROWINDOW new_fl_cairo_window3(int w, int h); +extern "C" void free_fl_cairo_window(CAIROWINDOW w); + + +extern "C" void fl_cairo_window_set_draw_cb(CAIROWINDOW w, void * cb); + + +extern "C" void fl_cairo_window_draw(CAIROWINDOW w); +extern "C" int fl_cairo_window_handle(CAIROWINDOW w, int e); + + +#endif + + diff --git a/src/fltk-widgets-groups-windows-double-cairo.adb b/src/fltk-widgets-groups-windows-double-cairo.adb new file mode 100644 index 0000000..61ea232 --- /dev/null +++ b/src/fltk-widgets-groups-windows-double-cairo.adb @@ -0,0 +1,221 @@ + + +-- Programmed by Jedidiah Barber +-- Released into the public domain + + +with + + Interfaces.C, + System.Address_To_Access_Conversions; + + +package body FLTK.Widgets.Groups.Windows.Double.Cairo is + + + ------------------------ + -- Functions From C -- + ------------------------ + + function new_fl_cairo_window + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return Storage.Integer_Address; + pragma Import (C, new_fl_cairo_window, "new_fl_cairo_window"); + pragma Inline (new_fl_cairo_window); + + function new_fl_cairo_window2 + (W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return Storage.Integer_Address; + pragma Import (C, new_fl_cairo_window2, "new_fl_cairo_window2"); + pragma Inline (new_fl_cairo_window2); + + function new_fl_cairo_window3 + (W, H : in Interfaces.C.int) + return Storage.Integer_Address; + pragma Import (C, new_fl_cairo_window3, "new_fl_cairo_window3"); + pragma Inline (new_fl_cairo_window3); + + procedure free_fl_cairo_window + (W : in Storage.Integer_Address); + pragma Import (C, free_fl_cairo_window, "free_fl_cairo_window"); + pragma Inline (free_fl_cairo_window); + + + + + procedure fl_cairo_window_set_draw_cb + (W, F : in Storage.Integer_Address); + pragma Import (C, fl_cairo_window_set_draw_cb, "fl_cairo_window_set_draw_cb"); + pragma Inline (fl_cairo_window_set_draw_cb); + + + + + procedure fl_cairo_window_draw + (W : in Storage.Integer_Address); + pragma Import (C, fl_cairo_window_draw, "fl_cairo_window_draw"); + pragma Inline (fl_cairo_window_draw); + + function fl_cairo_window_handle + (W : in Storage.Integer_Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_cairo_window_handle, "fl_cairo_window_handle"); + pragma Inline (fl_cairo_window_handle); + + + + + ---------------------- + -- Callback Hooks -- + ---------------------- + + package Cairo_Convert is new System.Address_To_Access_Conversions (Cairo_Window'Class); + + + procedure Cairo_Draw_Hook + (C_Addr, Cairo_Addr : in Storage.Integer_Address); + + pragma Convention (C, Cairo_Draw_Hook); + + procedure Cairo_Draw_Hook + (C_Addr, Cairo_Addr : in Storage.Integer_Address) + is + Ada_Addr : System.Address := + Storage.To_Address (fl_widget_get_user_data (C_Addr)); + Ada_Object : access Cairo_Window'Class := + Cairo_Convert.To_Pointer (Ada_Addr); + begin + if Ada_Object.My_Func /= null then + Ada_Object.My_Func (Cairo_Window (Ada_Object.all), Storage.To_Address (Cairo_Addr)); + end if; + end Cairo_Draw_Hook; + + + + + ------------------- + -- Destructors -- + ------------------- + + procedure Extra_Final + (This : in out Cairo_Window) is + begin + Extra_Final (Double_Window (This)); + end Extra_Final; + + + procedure Finalize + (This : in out Cairo_Window) is + begin + Extra_Final (This); + if This.Void_Ptr /= Null_Pointer and This.Needs_Dealloc then + free_fl_cairo_window (This.Void_Ptr); + This.Void_Ptr := Null_Pointer; + end if; + end Finalize; + + + + + -------------------- + -- Constructors -- + -------------------- + + procedure Extra_Init + (This : in out Cairo_Window; + X, Y, W, H : in Integer; + Text : in String) is + begin + fl_cairo_window_set_draw_cb (This.Void_Ptr, Storage.To_Integer (Cairo_Draw_Hook'Address)); + Extra_Init (Double_Window (This), X, Y, W, H, Text); + end Extra_Init; + + + package body Forge is + + function Create + (X, Y, W, H : in Integer; + Text : in String := "") + return Cairo_Window is + begin + return This : Cairo_Window do + This.Void_Ptr := new_fl_cairo_window + (Interfaces.C.int (X), + Interfaces.C.int (Y), + Interfaces.C.int (W), + Interfaces.C.int (H), + Interfaces.C.To_C (Text)); + Extra_Init (This, X, Y, W, H, Text); + end return; + end Create; + + + function Create + (W, H : in Integer; + Text : in String := "") + return Cairo_Window is + begin + return This : Cairo_Window do + This.Void_Ptr := new_fl_cairo_window2 + (Interfaces.C.int (W), + Interfaces.C.int (H), + Interfaces.C.To_C (Text)); + Extra_Init (This, This.Get_X, This.Get_Y, W, H, Text); + end return; + end Create; + + + function Create + (W, H : in Integer) + return Cairo_Window is + begin + return This : Cairo_Window do + This.Void_Ptr := new_fl_cairo_window3 + (Interfaces.C.int (W), + Interfaces.C.int (H)); + Extra_Init (This, This.Get_X, This.Get_Y, W, H, This.Get_Label); + end return; + end Create; + + end Forge; + + + + + ------------------------ + -- Cairo Window API -- + ------------------------ + + procedure Set_Cairo_Draw + (This : in out Cairo_Window; + Func : in Cairo_Callback) is + begin + This.My_Func := Func; + end Set_Cairo_Draw; + + + + + procedure Draw + (This : in out Cairo_Window) is + begin + fl_cairo_window_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Cairo_Window; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_cairo_window_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Groups.Windows.Double.Cairo; + + diff --git a/src/fltk-widgets-groups-windows-double-cairo.ads b/src/fltk-widgets-groups-windows-double-cairo.ads new file mode 100644 index 0000000..111f7ac --- /dev/null +++ b/src/fltk-widgets-groups-windows-double-cairo.ads @@ -0,0 +1,101 @@ + + +-- Programmed by Jedidiah Barber +-- Released into the public domain + + +with + + System; + + +package FLTK.Widgets.Groups.Windows.Double.Cairo is + + + -- If FLTK has not been built with Cairo support then + -- this will just be a duplicate of Double_Window and the + -- callback set with Set_Cairo_Draw will never be triggered. + + -- Building with Cairo support requires either of + -- 1. CMake option FLTK_OPTION_CAIRO_WINDOW + -- 2. configure -enable-cairo + -- when building FLTK itself. + + + type Cairo_Window is new Double_Window with private; + + type Cairo_Window_Reference (Data : not null access Cairo_Window'Class) is + limited null record with Implicit_Dereference => Data; + + type Cairo_Callback is access procedure + (This : in out Cairo_Window; + Context : in System.Address); + + + + + package Forge is + + function Create + (X, Y, W, H : in Integer; + Text : in String := "") + return Cairo_Window; + + function Create + (W, H : in Integer; + Text : in String := "") + return Cairo_Window; + + function Create + (W, H : in Integer) + return Cairo_Window; + + end Forge; + + + + + procedure Set_Cairo_Draw + (This : in out Cairo_Window; + Func : in Cairo_Callback); + + + + + procedure Draw + (This : in out Cairo_Window); + + function Handle + (This : in out Cairo_Window; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Cairo_Window is new Double_Window with record + My_Func : Cairo_Callback; + end record; + + overriding procedure Finalize + (This : in out Cairo_Window); + + procedure Extra_Init + (This : in out Cairo_Window; + X, Y, W, H : in Integer; + Text : in String); + + procedure Extra_Final + (This : in out Cairo_Window); + + + pragma Inline (Set_Cairo_Draw); + + pragma Inline (Draw); + pragma Inline (Handle); + + +end FLTK.Widgets.Groups.Windows.Double.Cairo; + + |