diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-05-01 12:49:40 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-05-01 12:49:40 +1000 |
commit | e9dc75679fcac3bf2024e47641941d0a5ef0899d (patch) | |
tree | 49081bd61ecf5aa074b3a59340d9e56eb3d0a2d2 | |
parent | 9348c8013431bbd5de165d8fbac13b783d983324 (diff) |
Draw method implemented for Boxes/Inputs
-rw-r--r-- | src/c_fl_box.cpp | 44 | ||||
-rw-r--r-- | src/c_fl_box.h | 3 | ||||
-rw-r--r-- | src/c_fl_input.cpp | 48 | ||||
-rw-r--r-- | src/c_fl_input.h | 3 | ||||
-rw-r--r-- | src/c_fl_int_input.cpp | 48 | ||||
-rw-r--r-- | src/c_fl_int_input.h | 3 | ||||
-rw-r--r-- | src/fltk-widgets-boxes.adb | 33 | ||||
-rw-r--r-- | src/fltk-widgets-boxes.ads | 7 | ||||
-rw-r--r-- | src/fltk-widgets-inputs-int.adb | 33 | ||||
-rw-r--r-- | src/fltk-widgets-inputs-int.ads | 8 | ||||
-rw-r--r-- | src/fltk-widgets-inputs.adb | 33 | ||||
-rw-r--r-- | src/fltk-widgets-inputs.ads | 7 |
12 files changed, 262 insertions, 8 deletions
diff --git a/src/c_fl_box.cpp b/src/c_fl_box.cpp index eeee320..18afb1a 100644 --- a/src/c_fl_box.cpp +++ b/src/c_fl_box.cpp @@ -4,13 +4,53 @@ #include "c_fl_box.h" +typedef void (hook)(void*); +typedef hook* hook_p; + + + + +class My_Box : public Fl_Box { + public: + using Fl_Box::Fl_Box; + friend void box_set_draw_hook(BOX n, void * d); + friend void fl_box_draw(BOX n); + protected: + void draw(); + void real_draw(); + hook_p draw_hook; +}; + + +void My_Box::draw() { + (*draw_hook)(this->user_data()); +} + + +void My_Box::real_draw() { + Fl_Box::draw(); +} + + +void box_set_draw_hook(BOX n, void * d) { + reinterpret_cast<My_Box*>(n)->draw_hook = reinterpret_cast<hook_p>(d); +} + + +void fl_box_draw(BOX n) { + reinterpret_cast<My_Box*>(n)->real_draw(); +} + + + + BOX new_fl_box(int x, int y, int w, int h, char* label) { - Fl_Box *b = new Fl_Box(x, y, w, h, label); + My_Box *b = new My_Box(x, y, w, h, label); return b; } void free_fl_box(BOX b) { - delete reinterpret_cast<Fl_Box*>(b); + delete reinterpret_cast<My_Box*>(b); } diff --git a/src/c_fl_box.h b/src/c_fl_box.h index df7b629..d1b69b1 100644 --- a/src/c_fl_box.h +++ b/src/c_fl_box.h @@ -7,6 +7,9 @@ typedef void* BOX; +extern "C" void box_set_draw_hook(BOX n, void * d); +extern "C" void fl_box_draw(BOX n); + extern "C" BOX new_fl_box(int x, int y, int w, int h, char * label); extern "C" void free_fl_box(BOX b); diff --git a/src/c_fl_input.cpp b/src/c_fl_input.cpp index 4f19bd1..fde9ea8 100644 --- a/src/c_fl_input.cpp +++ b/src/c_fl_input.cpp @@ -4,18 +4,60 @@ #include "c_fl_input.h" +typedef void (hook)(void*); +typedef hook* hook_p; + + + + +class My_Input : public Fl_Input { + public: + using Fl_Input::Fl_Input; + friend void input_set_draw_hook(INPUT n, void * d); + friend void fl_input_draw(INPUT n); + protected: + void draw(); + void real_draw(); + hook_p draw_hook; +}; + + +void My_Input::draw() { + (*draw_hook)(this->user_data()); +} + + +void My_Input::real_draw() { + Fl_Input::draw(); +} + + +void input_set_draw_hook(INPUT n, void * d) { + reinterpret_cast<My_Input*>(n)->draw_hook = reinterpret_cast<hook_p>(d); +} + + +void fl_input_draw(INPUT n) { + reinterpret_cast<My_Input*>(n)->real_draw(); +} + + + + INPUT new_fl_input(int x, int y, int w, int h, char* label) { - Fl_Input *i = new Fl_Input(x, y, w, h, label); + My_Input *i = new My_Input(x, y, w, h, label); return i; } void free_fl_input(INPUT i) { - delete reinterpret_cast<Fl_Input*>(i); + delete reinterpret_cast<My_Input*>(i); } + + const char * fl_input_get_value(INPUT i) { - return reinterpret_cast<Fl_Input*>(i)->value(); + return reinterpret_cast<My_Input*>(i)->value(); } diff --git a/src/c_fl_input.h b/src/c_fl_input.h index cb40d42..2262a2f 100644 --- a/src/c_fl_input.h +++ b/src/c_fl_input.h @@ -7,6 +7,9 @@ typedef void* INPUT; +extern "C" void input_set_draw_hook(INPUT n, void * d); +extern "C" void fl_input_draw(INPUT n); + extern "C" INPUT new_fl_input(int x, int y, int w, int h, char* label); extern "C" void free_fl_input(INPUT i); diff --git a/src/c_fl_int_input.cpp b/src/c_fl_int_input.cpp index 2224857..45c5bc5 100644 --- a/src/c_fl_int_input.cpp +++ b/src/c_fl_int_input.cpp @@ -4,18 +4,60 @@ #include "c_fl_int_input.h" +typedef void (hook)(void*); +typedef hook* hook_p; + + + + +class My_Int_Input : public Fl_Int_Input { + public: + using Fl_Int_Input::Fl_Int_Input; + friend void int_input_set_draw_hook(INT_INPUT n, void * d); + friend void fl_int_input_draw(INT_INPUT n); + protected: + void draw(); + void real_draw(); + hook_p draw_hook; +}; + + +void My_Int_Input::draw() { + (*draw_hook)(this->user_data()); +} + + +void My_Int_Input::real_draw() { + Fl_Int_Input::draw(); +} + + +void int_input_set_draw_hook(INT_INPUT n, void * d) { + reinterpret_cast<My_Int_Input*>(n)->draw_hook = reinterpret_cast<hook_p>(d); +} + + +void fl_int_input_draw(INT_INPUT n) { + reinterpret_cast<My_Int_Input*>(n)->real_draw(); +} + + + + INT_INPUT new_fl_int_input(int x, int y, int w, int h, char* label) { - Fl_Int_Input *i = new Fl_Int_Input(x, y, w, h, label); + My_Int_Input *i = new My_Int_Input(x, y, w, h, label); return i; } void free_fl_int_input(INT_INPUT i) { - delete reinterpret_cast<Fl_Int_Input*>(i); + delete reinterpret_cast<My_Int_Input*>(i); } + + const char * fl_int_input_get_value(INT_INPUT i) { - return reinterpret_cast<Fl_Int_Input*>(i)->value(); + return reinterpret_cast<My_Int_Input*>(i)->value(); } diff --git a/src/c_fl_int_input.h b/src/c_fl_int_input.h index 5d99c3f..7bfd74d 100644 --- a/src/c_fl_int_input.h +++ b/src/c_fl_int_input.h @@ -7,6 +7,9 @@ typedef void* INT_INPUT; +extern "C" void int_input_set_draw_hook(INT_INPUT n, void * d); +extern "C" void fl_int_input_draw(INT_INPUT n); + extern "C" INT_INPUT new_fl_int_input(int x, int y, int w, int h, char* label); extern "C" void free_fl_int_input(INT_INPUT i); diff --git a/src/fltk-widgets-boxes.adb b/src/fltk-widgets-boxes.adb index 7b70f01..2efc591 100644 --- a/src/fltk-widgets-boxes.adb +++ b/src/fltk-widgets-boxes.adb @@ -8,6 +8,14 @@ use type System.Address; package body FLTK.Widgets.Boxes is + procedure box_set_draw_hook + (W, D : in System.Address); + pragma Import (C, box_set_draw_hook, "box_set_draw_hook"); + + procedure fl_box_draw + (W : in System.Address); + pragma Import (C, fl_box_draw, "fl_box_draw"); + function new_fl_box (X, Y, W, H : in Interfaces.C.int; Text : in Interfaces.C.char_array) @@ -21,6 +29,30 @@ package body FLTK.Widgets.Boxes is + procedure Draw_Hook (U : in System.Address); + pragma Convention (C, Draw_Hook); + + procedure Draw_Hook + (U : in System.Address) + is + Ada_Box : access Box'Class := + Box_Convert.To_Pointer (U); + begin + Ada_Box.Draw; + end Draw_Hook; + + + + + procedure Draw + (This : in out Box) is + begin + fl_box_draw (This.Void_Ptr); + end Draw; + + + + procedure Finalize (This : in out Box) is begin @@ -50,6 +82,7 @@ package body FLTK.Widgets.Boxes is fl_widget_set_user_data (This.Void_Ptr, Widget_Convert.To_Address (This'Unchecked_Access)); + box_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); end return; end Create; diff --git a/src/fltk-widgets-boxes.ads b/src/fltk-widgets-boxes.ads index 00f84d4..feeae91 100644 --- a/src/fltk-widgets-boxes.ads +++ b/src/fltk-widgets-boxes.ads @@ -15,6 +15,10 @@ package FLTK.Widgets.Boxes is private + procedure Draw + (This : in out Box); + + type Box is new Widget with null record; @@ -22,5 +26,8 @@ private (This : in out Box); + package Box_Convert is new System.Address_To_Access_Conversions (Box'Class); + + end FLTK.Widgets.Boxes; diff --git a/src/fltk-widgets-inputs-int.adb b/src/fltk-widgets-inputs-int.adb index 30f3d01..42cb22b 100644 --- a/src/fltk-widgets-inputs-int.adb +++ b/src/fltk-widgets-inputs-int.adb @@ -8,6 +8,14 @@ use type System.Address; package body FLTK.Widgets.Inputs.Int is + procedure int_input_set_draw_hook + (W, D : in System.Address); + pragma Import (C, int_input_set_draw_hook, "int_input_set_draw_hook"); + + procedure fl_int_input_draw + (W : in System.Address); + pragma Import (C, fl_int_input_draw, "fl_int_input_draw"); + function new_fl_int_input (X, Y, W, H : in Interfaces.C.int; Text : in Interfaces.C.char_array) @@ -26,6 +34,30 @@ package body FLTK.Widgets.Inputs.Int is + procedure Draw_Hook (U : in System.Address); + pragma Convention (C, Draw_Hook); + + procedure Draw_Hook + (U : in System.Address) + is + Ada_Input : access Integer_Input'Class := + Integer_Input_Convert.To_Pointer (U); + begin + Ada_Input.Draw; + end Draw_Hook; + + + + + procedure Draw + (This : in out Integer_Input) is + begin + fl_int_input_draw (This.Void_Ptr); + end Draw; + + + + procedure Finalize (This : in out Integer_Input) is begin @@ -55,6 +87,7 @@ package body FLTK.Widgets.Inputs.Int is fl_widget_set_user_data (This.Void_Ptr, Widget_Convert.To_Address (This'Unchecked_Access)); + int_input_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); end return; end Create; diff --git a/src/fltk-widgets-inputs-int.ads b/src/fltk-widgets-inputs-int.ads index 2777f54..18c2482 100644 --- a/src/fltk-widgets-inputs-int.ads +++ b/src/fltk-widgets-inputs-int.ads @@ -20,6 +20,10 @@ package FLTK.Widgets.Inputs.Int is private + procedure Draw + (This : in out Integer_Input); + + type Integer_Input is new Input with null record; @@ -27,5 +31,9 @@ private (This : in out Integer_Input); + package Integer_Input_Convert is new System.Address_To_Access_Conversions + (Integer_Input'Class); + + end FLTK.Widgets.Inputs.Int; diff --git a/src/fltk-widgets-inputs.adb b/src/fltk-widgets-inputs.adb index 9af8e87..83420ff 100644 --- a/src/fltk-widgets-inputs.adb +++ b/src/fltk-widgets-inputs.adb @@ -9,6 +9,14 @@ use type System.Address; package body FLTK.Widgets.Inputs is + procedure input_set_draw_hook + (W, D : in System.Address); + pragma Import (C, input_set_draw_hook, "input_set_draw_hook"); + + procedure fl_input_draw + (W : in System.Address); + pragma Import (C, fl_input_draw, "fl_input_draw"); + function new_fl_input (X, Y, W, H : in Interfaces.C.int; Text : in Interfaces.C.char_array) @@ -27,6 +35,30 @@ package body FLTK.Widgets.Inputs is + procedure Draw_Hook (U : in System.Address); + pragma Convention (C, Draw_Hook); + + procedure Draw_Hook + (U : in System.Address) + is + Ada_Input : access Input'Class := + Input_Convert.To_Pointer (U); + begin + Ada_Input.Draw; + end Draw_Hook; + + + + + procedure Draw + (This : in out Input) is + begin + fl_input_draw (This.Void_Ptr); + end Draw; + + + + procedure Finalize (This : in out Input) is begin @@ -56,6 +88,7 @@ package body FLTK.Widgets.Inputs is fl_widget_set_user_data (This.Void_Ptr, Widget_Convert.To_Address (This'Unchecked_Access)); + input_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); end return; end Create; diff --git a/src/fltk-widgets-inputs.ads b/src/fltk-widgets-inputs.ads index 0f818ac..c268e72 100644 --- a/src/fltk-widgets-inputs.ads +++ b/src/fltk-widgets-inputs.ads @@ -20,6 +20,10 @@ package FLTK.Widgets.Inputs is private + procedure Draw + (This : in out Input); + + type Input is new Widget with null record; @@ -27,5 +31,8 @@ private (This : in out Input); + package Input_Convert is new System.Address_To_Access_Conversions (Input'Class); + + end FLTK.Widgets.Inputs; |