diff options
| author | Jed Barber <jjbarber@y7mail.com> | 2017-05-10 17:45:59 +1000 | 
|---|---|---|
| committer | Jed Barber <jjbarber@y7mail.com> | 2017-05-10 17:45:59 +1000 | 
| commit | 9dcf299b63268278b0a9a27ed2dc600f19e458b2 (patch) | |
| tree | 27de461d6c8b41afe76ca9ec9a55a294bf13515b /src | |
| parent | 1a184730dae07956109c476824d1536552b2e139 (diff) | |
Output widgets added
Diffstat (limited to 'src')
| -rw-r--r-- | src/c_fl_output.cpp | 57 | ||||
| -rw-r--r-- | src/c_fl_output.h | 19 | ||||
| -rw-r--r-- | src/fltk-widgets-inputs-outputs.adb | 94 | ||||
| -rw-r--r-- | src/fltk-widgets-inputs-outputs.ads | 30 | 
4 files changed, 200 insertions, 0 deletions
| diff --git a/src/c_fl_output.cpp b/src/c_fl_output.cpp new file mode 100644 index 0000000..de2ad49 --- /dev/null +++ b/src/c_fl_output.cpp @@ -0,0 +1,57 @@ + + +#include <FL/Fl_Output.H> +#include "c_fl_output.h" + + +typedef void (hook)(void*); +typedef hook* hook_p; + + + + +class My_Output : public Fl_Output { +    public: +        using Fl_Output::Fl_Output; +        friend void output_set_draw_hook(OUTPUTT n, void * d); +        friend void fl_output_draw(OUTPUTT n); +    protected: +        void draw(); +        void real_draw(); +        hook_p draw_hook; +}; + + +void My_Output::draw() { +    (*draw_hook)(this->user_data()); +} + + +void My_Output::real_draw() { +    Fl_Output::draw(); +} + + +void output_set_draw_hook(OUTPUTT n, void * d) { +    reinterpret_cast<My_Output*>(n)->draw_hook = reinterpret_cast<hook_p>(d); +} + + +void fl_output_draw(OUTPUTT n) { +    reinterpret_cast<My_Output*>(n)->real_draw(); +} + + + + +OUTPUTT new_fl_output(int x, int y, int w, int h, char* label) { +    My_Output *i = new My_Output(x, y, w, h, label); +    return i; +} + + +void free_fl_output(OUTPUTT i) { +    delete reinterpret_cast<My_Output*>(i); +} + + diff --git a/src/c_fl_output.h b/src/c_fl_output.h new file mode 100644 index 0000000..da88cb1 --- /dev/null +++ b/src/c_fl_output.h @@ -0,0 +1,19 @@ + + +#ifndef FL_OUTPUT_GUARD +#define FL_OUTPUT_GUARD + + +//  using just "OUTPUT" doesn't compile for some reason +typedef void* OUTPUTT; + + +extern "C" void output_set_draw_hook(OUTPUTT n, void * d); +extern "C" void fl_output_draw(OUTPUTT n); + +extern "C" OUTPUTT new_fl_output(int x, int y, int w, int h, char* label); +extern "C" void free_fl_output(OUTPUTT i); + + +#endif + diff --git a/src/fltk-widgets-inputs-outputs.adb b/src/fltk-widgets-inputs-outputs.adb new file mode 100644 index 0000000..8aa7021 --- /dev/null +++ b/src/fltk-widgets-inputs-outputs.adb @@ -0,0 +1,94 @@ + + +with Interfaces.C.Strings; +with System; +use type System.Address; + + +package body FLTK.Widgets.Inputs.Outputs is + + +    procedure output_set_draw_hook +           (W, D : in System.Address); +    pragma Import (C, output_set_draw_hook, "output_set_draw_hook"); + +    procedure fl_output_draw +           (W : in System.Address); +    pragma Import (C, fl_output_draw, "fl_output_draw"); + +    function new_fl_output +           (X, Y, W, H : in Interfaces.C.int; +            Text       : in Interfaces.C.char_array) +        return System.Address; +    pragma Import (C, new_fl_output, "new_fl_output"); + +    procedure free_fl_output +           (F : in System.Address); +    pragma Import (C, free_fl_output, "free_fl_output"); + + + + +    procedure Draw_Hook (U : in System.Address); +    pragma Convention (C, Draw_Hook); + +    procedure Draw_Hook +           (U : in System.Address) +    is +        package Output_Convert is new +            System.Address_To_Access_Conversions (Output'Class); + +        Ada_Output : access Output'Class := +            Output_Convert.To_Pointer (U); +    begin +        Ada_Output.Draw; +    end Draw_Hook; + + + + +    procedure Draw +           (This : in out Output) is +    begin +        fl_output_draw (This.Void_Ptr); +    end Draw; + + + + +    procedure Finalize +           (This : in out Output) is +    begin +        if  This in Output and then +            This.Void_Ptr /= System.Null_Address +        then +            free_fl_output (This.Void_Ptr); +        end if; +        Finalize (Input (This)); +    end Finalize; + + + + +    function Create +           (X, Y, W, H : in Integer; +            Text       : in String) +        return Output is +    begin +        return This : Output do +            This.Void_Ptr := new_fl_output +                   (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)); +            output_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); +        end return; +    end Create; + + +end FLTK.Widgets.Inputs.Outputs; + diff --git a/src/fltk-widgets-inputs-outputs.ads b/src/fltk-widgets-inputs-outputs.ads new file mode 100644 index 0000000..84c4a1f --- /dev/null +++ b/src/fltk-widgets-inputs-outputs.ads @@ -0,0 +1,30 @@ + + +package FLTK.Widgets.Inputs.Outputs is + + +    type Output is new Input with private; + + +    function Create +           (X, Y, W, H : in Integer; +            Text       : in String) +        return Output; + + +    procedure Draw +           (This : in out Output); + + +private + + +    type Output is new Input with null record; + + +    overriding procedure Finalize +           (This : in out Output); + + +end FLTK.Widgets.Inputs.Outputs; + | 
