diff options
-rw-r--r-- | progress.txt | 2 | ||||
-rw-r--r-- | src/c_fl_clock.cpp | 97 | ||||
-rw-r--r-- | src/c_fl_clock.h | 39 | ||||
-rw-r--r-- | src/fltk-widgets-clocks.adb | 203 | ||||
-rw-r--r-- | src/fltk-widgets-clocks.ads | 76 |
5 files changed, 416 insertions, 1 deletions
diff --git a/progress.txt b/progress.txt index a474201..19047a4 100644 --- a/progress.txt +++ b/progress.txt @@ -30,6 +30,7 @@ FLTK.Widgets.Buttons.Light.Round.Radio FLTK.Widgets.Buttons.Radio FLTK.Widgets.Buttons.Repeat FLTK.Widgets.Buttons.Toggle +FLTK.Widgets.Clocks FLTK.Widgets.Groups.Scrolls FLTK.Widgets.Groups.Text_Displays.Text_Editors FLTK.Widgets.Groups.Windows.Double @@ -73,7 +74,6 @@ FL_XPM_Image FL_Shared_Image FL_Tiled_Image FL_Chart -FL_Clock_Output FL_Clock FL_Round_Clock FL_Browser diff --git a/src/c_fl_clock.cpp b/src/c_fl_clock.cpp new file mode 100644 index 0000000..1c16d75 --- /dev/null +++ b/src/c_fl_clock.cpp @@ -0,0 +1,97 @@ + + +#include <FL/Fl_Clock.H> +#include "c_fl_clock.h" +#include "c_fl_type.h" + + + + +class My_Clock : public Fl_Clock { + public: + using Fl_Clock::Fl_Clock; + friend void clock_set_draw_hook(CLOCK c, void * d); + friend void fl_clock_draw(CLOCK c); + friend void clock_set_handle_hook(CLOCK c, void * h); + friend int fl_clock_handle(CLOCK c, int e); + protected: + void draw(); + void real_draw(); + int handle(int e); + int real_handle(int e); + d_hook_p draw_hook; + h_hook_p handle_hook; +}; + +void My_Clock::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Clock::real_draw() { + Fl_Clock::draw(); +} + +int My_Clock::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Clock::real_handle(int e) { + return Fl_Clock::handle(e); +} + +void clock_set_draw_hook(CLOCK c, void * d) { + reinterpret_cast<My_Clock*>(c)->draw_hook = reinterpret_cast<d_hook_p>(d); +} + +void fl_clock_draw(CLOCK c) { + reinterpret_cast<My_Clock*>(c)->real_draw(); +} + +void clock_set_handle_hook(CLOCK c, void * h) { + reinterpret_cast<My_Clock*>(c)->handle_hook = reinterpret_cast<h_hook_p>(h); +} + +int fl_clock_handle(CLOCK c, int e) { + return reinterpret_cast<My_Clock*>(c)->real_handle(e); +} + + + + +CLOCK new_fl_clock(int x, int y, int w, int h, char* label) { + My_Clock *c = new My_Clock(x, y, w, h, label); + return c; +} + +void free_fl_clock(CLOCK c) { + delete reinterpret_cast<My_Clock*>(c); +} + + + + +int fl_clock_get_hour(CLOCK c) { + return reinterpret_cast<My_Clock*>(c)->hour(); +} + +int fl_clock_get_minute(CLOCK c) { + return reinterpret_cast<My_Clock*>(c)->minute(); +} + +int fl_clock_get_second(CLOCK c) { + return reinterpret_cast<My_Clock*>(c)->second(); +} + + +ulong fl_clock_get_value(CLOCK c) { + return reinterpret_cast<My_Clock*>(c)->value(); +} + +void fl_clock_set_value(CLOCK c, ulong v) { + reinterpret_cast<My_Clock*>(c)->value(v); +} + +void fl_clock_set_value2(CLOCK c, int h, int m, int s) { + reinterpret_cast<My_Clock*>(c)->value(h,m,s); +} + diff --git a/src/c_fl_clock.h b/src/c_fl_clock.h new file mode 100644 index 0000000..3b93456 --- /dev/null +++ b/src/c_fl_clock.h @@ -0,0 +1,39 @@ + + +#ifndef FL_CLOCK_GUARD +#define FL_CLOCK_GUARD + + + + +typedef void* CLOCK; + + + + +extern "C" void clock_set_draw_hook(CLOCK c, void * d); +extern "C" void fl_clock_draw(CLOCK c); +extern "C" void clock_set_handle_hook(CLOCK c, void * h); +extern "C" int fl_clock_handle(CLOCK c, int e); + + + + +extern "C" CLOCK new_fl_clock(int x, int y, int w, int h, char* label); +extern "C" void free_fl_clock(CLOCK c); + + + + +extern "C" int fl_clock_get_hour(CLOCK c); +extern "C" int fl_clock_get_minute(CLOCK c); +extern "C" int fl_clock_get_second(CLOCK c); + + +extern "C" ulong fl_clock_get_value(CLOCK c); +extern "C" void fl_clock_set_value(CLOCK c, ulong v); +extern "C" void fl_clock_set_value2(CLOCK c, int h, int m, int s); + + +#endif + diff --git a/src/fltk-widgets-clocks.adb b/src/fltk-widgets-clocks.adb new file mode 100644 index 0000000..da53d11 --- /dev/null +++ b/src/fltk-widgets-clocks.adb @@ -0,0 +1,203 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Clocks is + + + procedure clock_set_draw_hook + (W, D : in System.Address); + pragma Import (C, clock_set_draw_hook, "clock_set_draw_hook"); + + procedure clock_set_handle_hook + (W, H : in System.Address); + pragma Import (C, clock_set_handle_hook, "clock_set_handle_hook"); + + + + + function new_fl_clock + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_clock, "new_fl_clock"); + + procedure free_fl_clock + (F : in System.Address); + pragma Import (C, free_fl_clock, "free_fl_clock"); + + + + + function fl_clock_get_hour + (C : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_clock_get_hour, "fl_clock_get_hour"); + + function fl_clock_get_minute + (C : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_clock_get_minute, "fl_clock_get_minute"); + + function fl_clock_get_second + (C : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_clock_get_second, "fl_clock_get_second"); + + + + + function fl_clock_get_value + (C : in System.Address) + return Interfaces.C.unsigned_long; + pragma Import (C, fl_clock_get_value, "fl_clock_get_value"); + + procedure fl_clock_set_value + (C : in System.Address; + V : in Interfaces.C.unsigned_long); + pragma Import (C, fl_clock_set_value, "fl_clock_set_value"); + + procedure fl_clock_set_value2 + (C : in System.Address; + H, M, S : in Interfaces.C.int); + pragma Import (C, fl_clock_set_value2, "fl_clock_set_value2"); + + + + + procedure fl_clock_draw + (W : in System.Address); + pragma Import (C, fl_clock_draw, "fl_clock_draw"); + + function fl_clock_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_clock_handle, "fl_clock_handle"); + + + + + procedure Finalize + (This : in out Clock) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Clock'Class + then + free_fl_clock (This.Void_Ptr); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Widget (This)); + end Finalize; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Clock is + begin + return This : Clock do + This.Void_Ptr := new_fl_clock + (Interfaces.C.int (X), + Interfaces.C.int (Y), + Interfaces.C.int (W), + Interfaces.C.int (H), + Interfaces.C.To_C (Text)); + fl_widget_set_user_data + (This.Void_Ptr, + Widget_Convert.To_Address (This'Unchecked_Access)); + clock_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + clock_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + + + + function Get_Hour + (This : in Clock) + return Hour is + begin + return Hour (fl_clock_get_hour (This.Void_Ptr)); + end Get_Hour; + + + function Get_Minute + (This : in Clock) + return Minute is + begin + return Minute (fl_clock_get_minute (This.Void_Ptr)); + end Get_Minute; + + + function Get_Second + (This : in Clock) + return Second is + begin + return Second (fl_clock_get_second (This.Void_Ptr)); + end Get_Second; + + + + + function Get_Time + (This : in Clock) + return Time_Value is + begin + return Time_Value (fl_clock_get_value (This.Void_Ptr)); + end Get_Time; + + + procedure Set_Time + (This : in out Clock; + To : in Time_Value) is + begin + fl_clock_set_value (This.Void_Ptr, Interfaces.C.unsigned_long (To)); + end Set_Time; + + + procedure Set_Time + (This : in out Clock; + Hours : in Hour; + Minutes : in Minute; + Seconds : in Second) is + begin + fl_clock_set_value2 + (This.Void_Ptr, + Interfaces.C.int (Hours), + Interfaces.C.int (Minutes), + Interfaces.C.int (Seconds)); + end Set_Time; + + + + + procedure Draw + (This : in out Clock) is + begin + fl_clock_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Clock; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_clock_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Clocks; + diff --git a/src/fltk-widgets-clocks.ads b/src/fltk-widgets-clocks.ads new file mode 100644 index 0000000..d78fd45 --- /dev/null +++ b/src/fltk-widgets-clocks.ads @@ -0,0 +1,76 @@ + + +package FLTK.Widgets.Clocks is + + + type Clock is new Widget with private; + + subtype Hour is Integer range 0 .. 23; + subtype Minute is Integer range 0 .. 59; + subtype Second is Integer range 0 .. 60; + + type Time_Value is mod 2 ** 32; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Clock; + + + + + function Get_Hour + (This : in Clock) + return Hour; + + function Get_Minute + (This : in Clock) + return Minute; + + function Get_Second + (This : in Clock) + return Second; + + + + + function Get_Time + (This : in Clock) + return Time_Value; + + procedure Set_Time + (This : in out Clock; + To : in Time_Value); + + procedure Set_Time + (This : in out Clock; + Hours : in Hour; + Minutes : in Minute; + Seconds : in Second); + + + + + procedure Draw + (This : in out Clock); + + function Handle + (This : in out Clock; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Clock is new Widget with null record; + + overriding procedure Finalize + (This : in out Clock); + + +end FLTK.Widgets.Clocks; + |