diff options
author | Jed Barber <jjbarber@y7mail.com> | 2018-03-03 11:36:05 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2018-03-03 11:36:05 +1100 |
commit | 624318b4c5bd9ce18f232a1b180fd68c59493628 (patch) | |
tree | fcd10f2d9ff58601eeb53780dc56e17e18c6e2bd | |
parent | de5fa364a30e187fd450bf4420019936f09fd9ab (diff) |
Added FLTK.Widgets.Progress_Bars
-rw-r--r-- | progress.txt | 2 | ||||
-rw-r--r-- | src/c_fl_progress.cpp | 96 | ||||
-rw-r--r-- | src/c_fl_progress.h | 37 | ||||
-rw-r--r-- | src/fltk-widgets-progress_bars.adb | 193 | ||||
-rw-r--r-- | src/fltk-widgets-progress_bars.ads | 65 |
5 files changed, 392 insertions, 1 deletions
diff --git a/progress.txt b/progress.txt index 7ac0834..3df776b 100644 --- a/progress.txt +++ b/progress.txt @@ -45,6 +45,7 @@ FLTK.Widgets.Inputs.Outputs FLTK.Widgets.Inputs.Outputs.Multiline FLTK.Widgets.Inputs.Secret FLTK.Widgets.Menus.Menu_Bars +FLTK.Widgets.Progress_Bars @@ -93,7 +94,6 @@ FL_Tabs FL_Tile FL_Tree FL_Wizard -FL_Progress FL_Valuator FL_Adjuster FL_Counter diff --git a/src/c_fl_progress.cpp b/src/c_fl_progress.cpp new file mode 100644 index 0000000..5fff1ae --- /dev/null +++ b/src/c_fl_progress.cpp @@ -0,0 +1,96 @@ + + +#include <FL/Fl_Progress.H> +#include "c_fl_progress.h" +#include "c_fl_type.h" + + + + +class My_Progress : public Fl_Progress { + public: + using Fl_Progress::Fl_Progress; + friend void progress_set_draw_hook(PROGRESS p, void * d); + friend void fl_progress_draw(PROGRESS p); + friend void progress_set_handle_hook(PROGRESS p, void * h); + friend int fl_progress_handle(PROGRESS p, 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_Progress::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Progress::real_draw() { + Fl_Progress::draw(); +} + +int My_Progress::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Progress::real_handle(int e) { + return Fl_Progress::handle(e); +} + +void progress_set_draw_hook(PROGRESS p, void * d) { + reinterpret_cast<My_Progress*>(p)->draw_hook = reinterpret_cast<d_hook_p>(d); +} + +void fl_progress_draw(PROGRESS p) { + reinterpret_cast<My_Progress*>(p)->real_draw(); +} + +void progress_set_handle_hook(PROGRESS p, void * h) { + reinterpret_cast<My_Progress*>(p)->handle_hook = reinterpret_cast<h_hook_p>(h); +} + +int fl_progress_handle(PROGRESS p, int e) { + return reinterpret_cast<My_Progress*>(p)->real_handle(e); +} + + + + +PROGRESS new_fl_progress(int x, int y, int w, int h, char* label) { + My_Progress *p = new My_Progress(x, y, w, h, label); + return p; +} + +void free_fl_progress(PROGRESS p) { + delete reinterpret_cast<My_Progress*>(p); +} + + + + +float fl_progress_get_minimum(PROGRESS p) { + return reinterpret_cast<My_Progress*>(p)->minimum(); +} + +void fl_progress_set_minimum(PROGRESS p, float t) { + reinterpret_cast<My_Progress*>(p)->minimum(t); +} + +float fl_progress_get_maximum(PROGRESS p) { + return reinterpret_cast<My_Progress*>(p)->maximum(); +} + +void fl_progress_set_maximum(PROGRESS p, float t) { + reinterpret_cast<My_Progress*>(p)->maximum(t); +} + +float fl_progress_get_value(PROGRESS p) { + return reinterpret_cast<My_Progress*>(p)->value(); +} + +void fl_progress_set_value(PROGRESS p, float t) { + reinterpret_cast<My_Progress*>(p)->value(t); +} + diff --git a/src/c_fl_progress.h b/src/c_fl_progress.h new file mode 100644 index 0000000..0254bfd --- /dev/null +++ b/src/c_fl_progress.h @@ -0,0 +1,37 @@ + + +#ifndef FL_PROGRESS_GUARD +#define FL_PROGRESS_GUARD + + + + +typedef void* PROGRESS; + + + + +extern "C" void progress_set_draw_hook(PROGRESS p, void * d); +extern "C" void fl_progress_draw(PROGRESS p); +extern "C" void progress_set_handle_hook(PROGRESS p, void * h); +extern "C" int fl_progress_handle(PROGRESS p, int e); + + + + +extern "C" PROGRESS new_fl_progress(int x, int y, int w, int h, char* label); +extern "C" void free_fl_progress(PROGRESS p); + + + + +extern "C" float fl_progress_get_minimum(PROGRESS p); +extern "C" void fl_progress_set_minimum(PROGRESS p, float t); +extern "C" float fl_progress_get_maximum(PROGRESS p); +extern "C" void fl_progress_set_maximum(PROGRESS p, float t); +extern "C" float fl_progress_get_value(PROGRESS p); +extern "C" void fl_progress_set_value(PROGRESS p, float t); + + +#endif + diff --git a/src/fltk-widgets-progress_bars.adb b/src/fltk-widgets-progress_bars.adb new file mode 100644 index 0000000..9f9cd06 --- /dev/null +++ b/src/fltk-widgets-progress_bars.adb @@ -0,0 +1,193 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Progress_Bars is + + + procedure progress_set_draw_hook + (W, D : in System.Address); + pragma Import (C, progress_set_draw_hook, "progress_set_draw_hook"); + + procedure progress_set_handle_hook + (W, H : in System.Address); + pragma Import (C, progress_set_handle_hook, "progress_set_handle_hook"); + + + + + function new_fl_progress + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_progress, "new_fl_progress"); + + procedure free_fl_progress + (P : in System.Address); + pragma Import (C, free_fl_progress, "free_fl_progress"); + + + + + function fl_progress_get_minimum + (P : in System.Address) + return Interfaces.C.C_float; + pragma Import (C, fl_progress_get_minimum, "fl_progress_get_minimum"); + + procedure fl_progress_set_minimum + (P : in System.Address; + T : in Interfaces.C.C_float); + pragma Import (C, fl_progress_set_minimum, "fl_progress_set_minimum"); + + function fl_progress_get_maximum + (P : in System.Address) + return Interfaces.C.C_float; + pragma Import (C, fl_progress_get_maximum, "fl_progress_get_maximum"); + + procedure fl_progress_set_maximum + (P : in System.Address; + T : in Interfaces.C.C_float); + pragma Import (C, fl_progress_set_maximum, "fl_progress_set_maximum"); + + function fl_progress_get_value + (P : in System.Address) + return Interfaces.C.C_float; + pragma Import (C, fl_progress_get_value, "fl_progress_get_value"); + + procedure fl_progress_set_value + (P : in System.Address; + T : in Interfaces.C.C_float); + pragma Import (C, fl_progress_set_value, "fl_progress_set_value"); + + + + + procedure fl_progress_draw + (P : in System.Address); + pragma Import (C, fl_progress_draw, "fl_progress_draw"); + + function fl_progress_handle + (P : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_progress_handle, "fl_progress_handle"); + + + + + procedure Finalize + (This : in out Progress_Bar) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Progress_Bar'Class + then + free_fl_progress (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 Progress_Bar is + begin + return This : Progress_Bar do + This.Void_Ptr := new_fl_progress + (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)); + progress_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + progress_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + + + + + function Get_Minimum + (This : in Progress_Bar) + return Float is + begin + return Float (fl_progress_get_minimum (This.Void_Ptr)); + end Get_Minimum; + + + procedure Set_Minimum + (This : in out Progress_Bar; + To : in Float) is + begin + fl_progress_set_minimum (This.Void_Ptr, Interfaces.C.C_float (To)); + end Set_Minimum; + + + function Get_Maximum + (This : in Progress_Bar) + return Float is + begin + return Float (fl_progress_get_maximum (This.Void_Ptr)); + end Get_Maximum; + + + procedure Set_Maximum + (This : in out Progress_Bar; + To : in Float) is + begin + fl_progress_set_maximum (This.Void_Ptr, Interfaces.C.C_float (To)); + end Set_Maximum; + + + function Get_Value + (This : in Progress_Bar) + return Float is + begin + return Float (fl_progress_get_value (This.Void_Ptr)); + end Get_Value; + + + procedure Set_Value + (This : in out Progress_Bar; + To : in Float) is + begin + fl_progress_set_value (This.Void_Ptr, Interfaces.C.C_float (To)); + end Set_Value; + + + + + procedure Draw + (This : in out Progress_Bar) is + begin + fl_progress_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Progress_Bar; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_progress_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Progress_Bars; + diff --git a/src/fltk-widgets-progress_bars.ads b/src/fltk-widgets-progress_bars.ads new file mode 100644 index 0000000..252657b --- /dev/null +++ b/src/fltk-widgets-progress_bars.ads @@ -0,0 +1,65 @@ + + +package FLTK.Widgets.Progress_Bars is + + + type Progress_Bar is new Widget with private; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Progress_Bar; + + + + + function Get_Minimum + (This : in Progress_Bar) + return Float; + + procedure Set_Minimum + (This : in out Progress_Bar; + To : in Float); + + function Get_Maximum + (This : in Progress_Bar) + return Float; + + procedure Set_Maximum + (This : in out Progress_Bar; + To : in Float); + + function Get_Value + (This : in Progress_Bar) + return Float; + + procedure Set_Value + (This : in out Progress_Bar; + To : in Float); + + + + + procedure Draw + (This : in out Progress_Bar); + + function Handle + (This : in out Progress_Bar; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Progress_Bar is new Widget with null record; + + overriding procedure Finalize + (This : in out Progress_Bar); + + +end FLTK.Widgets.Progress_Bars; + |