From 94514ea97b5b4533ef775ef1949de20df58e715f Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 3 Mar 2018 18:06:55 +1100 Subject: Added FLTK.Widgets.Valuators.Dials.Line --- progress.txt | 2 +- src/c_fl_line_dial.cpp | 70 +++++++++++++++++++ src/c_fl_line_dial.h | 27 ++++++++ src/fltk-widgets-valuators-dials-line.adb | 109 ++++++++++++++++++++++++++++++ src/fltk-widgets-valuators-dials-line.ads | 38 +++++++++++ 5 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 src/c_fl_line_dial.cpp create mode 100644 src/c_fl_line_dial.h create mode 100644 src/fltk-widgets-valuators-dials-line.adb create mode 100644 src/fltk-widgets-valuators-dials-line.ads diff --git a/progress.txt b/progress.txt index de35773..598f6b8 100644 --- a/progress.txt +++ b/progress.txt @@ -51,6 +51,7 @@ FLTK.Widgets.Valuators.Counters FLTK.Widgets.Valuators.Counters.Simple FLTK.Widgets.Valuators.Dials FLTK.Widgets.Valuators.Dials.Fill +FLTK.Widgets.Valuators.Dials.Line @@ -100,7 +101,6 @@ FL_Tabs FL_Tile FL_Tree FL_Wizard -FL_Line_Dial FL_Roller FL_Slider FL_Fill_Slider diff --git a/src/c_fl_line_dial.cpp b/src/c_fl_line_dial.cpp new file mode 100644 index 0000000..874ef8e --- /dev/null +++ b/src/c_fl_line_dial.cpp @@ -0,0 +1,70 @@ + + +#include +#include "c_fl_line_dial.h" +#include "c_fl_type.h" + + + + +class My_Line_Dial : public Fl_Line_Dial { + public: + using Fl_Line_Dial::Fl_Line_Dial; + friend void line_dial_set_draw_hook(LINE_DIAL v, void * d); + friend void fl_line_dial_draw(LINE_DIAL v); + friend void line_dial_set_handle_hook(LINE_DIAL v, void * h); + friend int fl_line_dial_handle(LINE_DIAL v, 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_Line_Dial::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Line_Dial::real_draw() { + Fl_Line_Dial::draw(); +} + +int My_Line_Dial::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Line_Dial::real_handle(int e) { + return Fl_Line_Dial::handle(e); +} + +void line_dial_set_draw_hook(LINE_DIAL v, void * d) { + reinterpret_cast(v)->draw_hook = reinterpret_cast(d); +} + +void fl_line_dial_draw(LINE_DIAL v) { + reinterpret_cast(v)->real_draw(); +} + +void line_dial_set_handle_hook(LINE_DIAL v, void * h) { + reinterpret_cast(v)->handle_hook = reinterpret_cast(h); +} + +int fl_line_dial_handle(LINE_DIAL v, int e) { + return reinterpret_cast(v)->real_handle(e); +} + + + + +LINE_DIAL new_fl_line_dial(int x, int y, int w, int h, char* label) { + My_Line_Dial *v = new My_Line_Dial(x, y, w, h, label); + return v; +} + +void free_fl_line_dial(LINE_DIAL v) { + delete reinterpret_cast(v); +} + + diff --git a/src/c_fl_line_dial.h b/src/c_fl_line_dial.h new file mode 100644 index 0000000..0056939 --- /dev/null +++ b/src/c_fl_line_dial.h @@ -0,0 +1,27 @@ + + +#ifndef FL_LINE_DIAL_GUARD +#define FL_LINE_DIAL_GUARD + + + + +typedef void* LINE_DIAL; + + + + +extern "C" void line_dial_set_draw_hook(LINE_DIAL v, void * d); +extern "C" void fl_line_dial_draw(LINE_DIAL v); +extern "C" void line_dial_set_handle_hook(LINE_DIAL v, void * h); +extern "C" int fl_line_dial_handle(LINE_DIAL v, int e); + + + + +extern "C" LINE_DIAL new_fl_line_dial(int x, int y, int w, int h, char* label); +extern "C" void free_fl_line_dial(LINE_DIAL v); + + +#endif + diff --git a/src/fltk-widgets-valuators-dials-line.adb b/src/fltk-widgets-valuators-dials-line.adb new file mode 100644 index 0000000..9892ba9 --- /dev/null +++ b/src/fltk-widgets-valuators-dials-line.adb @@ -0,0 +1,109 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Valuators.Dials.Line is + + + procedure line_dial_set_draw_hook + (W, D : in System.Address); + pragma Import (C, line_dial_set_draw_hook, "line_dial_set_draw_hook"); + + procedure line_dial_set_handle_hook + (W, H : in System.Address); + pragma Import (C, line_dial_set_handle_hook, "line_dial_set_handle_hook"); + + + + + function new_fl_line_dial + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_line_dial, "new_fl_line_dial"); + + procedure free_fl_line_dial + (D : in System.Address); + pragma Import (C, free_fl_line_dial, "free_fl_line_dial"); + + + + + procedure fl_line_dial_draw + (W : in System.Address); + pragma Import (C, fl_line_dial_draw, "fl_line_dial_draw"); + + function fl_line_dial_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_line_dial_handle, "fl_line_dial_handle"); + + + + + procedure Finalize + (This : in out Line_Dial) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Line_Dial'Class + then + free_fl_line_dial (This.Void_Ptr); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Dial (This)); + end Finalize; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Line_Dial is + begin + return This : Line_Dial do + This.Void_Ptr := new_fl_line_dial + (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)); + line_dial_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + line_dial_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + + + + procedure Draw + (This : in out Line_Dial) is + begin + fl_line_dial_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Line_Dial; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_line_dial_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Valuators.Dials.Line; + diff --git a/src/fltk-widgets-valuators-dials-line.ads b/src/fltk-widgets-valuators-dials-line.ads new file mode 100644 index 0000000..020647e --- /dev/null +++ b/src/fltk-widgets-valuators-dials-line.ads @@ -0,0 +1,38 @@ + + +package FLTK.Widgets.Valuators.Dials.Line is + + + type Line_Dial is new Dial with private; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Line_Dial; + + + + + procedure Draw + (This : in out Line_Dial); + + function Handle + (This : in out Line_Dial; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Line_Dial is new Dial with null record; + + overriding procedure Finalize + (This : in out Line_Dial); + + +end FLTK.Widgets.Valuators.Dials.Line; + -- cgit