#ifndef cmGrFltk_h #define cmGrFltk_h class Fl_Group; class Fl_Output; class Fl_Scrollbar; class cmGrDevDrvFltk { public: cmGrDevDrvFltk(); virtual ~cmGrDevDrvFltk(){} static bool create( void* user, unsigned w, unsigned h ); static void destroy( void* user ); static void begin_draw( void* arg ); static void end_draw( void* arg ); static void draw( void* arg, int x, int y ); static void set_color( void* user, const cmGrColor_t c ); static void get_color( void* user, cmGrColor_t* c ); static void set_font_family( void* user, unsigned fontId ); static unsigned get_font_family( void* user ); static void set_font_style( void* user, unsigned style ); static unsigned get_font_style( void* user ); static void set_font_size( void* user, unsigned size ); static unsigned get_font_size( void* user ); static void set_pen_style( void* user, unsigned styleFlags ); static unsigned get_pen_style( void* user ); static void set_pen_width( void* user, unsigned w ); static unsigned get_pen_width( void* user ); static void draw_line( void* user, int x0, int y0, int x1, int y1 ); static void draw_rect( void* user, int x0, int y0, unsigned w, unsigned h ); static void fill_rect( void* user, int x0, int y0, unsigned w, unsigned h ); static void draw_ellipse( void* user, int x0, int y0, unsigned w, unsigned h ); static void fill_ellipse( void* user, int x0, int y0, unsigned w, unsigned h ); static void draw_diamond( void* user, int x0, int y0, unsigned w, unsigned h ); static void fill_diamond( void* user, int x0, int y0, unsigned w, unsigned h ); static void draw_triangle( void* user, int x0, int y0, unsigned w, unsigned h, unsigned dirFlag ); static void fill_triangle( void* user, int x0, int y0, unsigned w, unsigned h, unsigned dirFlag ); static void draw_text( void* user, const char* text, int x, int y ); static void draw_text_rot( void* user, const char* text, int x, int y, int angle ); static void measure_text( void* user, const char* text, unsigned* w, unsigned* h ); static void read_image( void* user, unsigned char* p, int x, int y, unsigned w, unsigned h ); static void draw_image( void* user, const unsigned char* p, int x, int y, unsigned w, unsigned h ); bool is_initialized() const; cmGrDev_t d; private: unsigned _fltk_pen_width; unsigned _fltk_pen_style; unsigned _fltk_font_size; unsigned _w; unsigned _h; static void _get_font_family_style( unsigned* fontId, unsigned* style ); static void _set_font_family_style( void* user, unsigned fontId, unsigned style ); }; //-------------------------------------------------------------------------------------- // Canvas Object class cmGrViewFltk : public Fl_Widget { public: cmGrViewFltk( cmCtx_t* ctx, cmGrH_t grH, int x, int y, int w, int h ); virtual ~cmGrViewFltk(); virtual int handle(int event); virtual void resize(int x, int y, int w, int h ); void setGrH( cmGrH_t grH ); private: virtual void draw(); typedef struct { unsigned idx; unsigned fltk_code; char ch; cmGrKeyCodeId_t gr_code; } keyMap_t; cmGrH_t _grH; cmGrDevDrvFltk _dd; cmGrDcH_t _dcH; static keyMap_t _keymap[]; const keyMap_t* _getGrKeyCode( unsigned fltk_code ); cmGrKeyCodeId_t _eventKeyCode( ); }; //-------------------------------------------------------------------------------------- // Container for multiple plots class cmGrPageFltk : public Fl_Group { public: cmGrPageFltk( cmCtx_t* ctx, cmGrPgH_t pgH, int x, int y, int w, int h ); virtual ~cmGrPageFltk(); virtual void createView( unsigned vwIdx ); virtual void destroyView( unsigned vwIdx ); virtual cmGrDcH_t devCtxHandle(); virtual cmGrViewFltk* viewWidget( unsigned vwIdx ); virtual void resize(int x, int y, int w, int h ); private: virtual void draw(); cmGrDevDrvFltk _dd; cmCtx_t* _ctx; cmGrPgH_t _pgH; cmGrDcH_t _dcH; cmGrViewFltk** _vwV; unsigned _vwN; }; //-------------------------------------------------------------------------------------- // Contains a single cmGrPageFltk and a control panel class cmGrPlotFltk : public Fl_Group { public: cmGrPlotFltk( cmCtx_t* ctx, int x, int y, int w, int h, int rn=1, int cn=1, int textSz=10 ); virtual ~cmGrPlotFltk(); virtual void resize(int x, int y, int w, int h ); cmGrPgH_t pageHandle(); cmGrPlH_t plotHandle(); cmGrDcH_t dcHandle(); virtual void initViews( int rn, int cn ); virtual void setStatusText( const cmChar_t* s ); virtual void on_button( unsigned id ); virtual void on_scroll( Fl_Scrollbar* sb, unsigned id ); virtual void on_view_create( unsigned viewIdx ); virtual void on_view_destroy( unsigned viewIdx ); virtual void rpt_local_pt( cmGrH_t grH ); virtual void rpt_global_pt( cmGrH_t grH ); virtual void on_phys_change( cmGrH_t grH ); virtual void on_view_change( cmGrH_t grH ); virtual void on_select_change( cmGrH_t grH ); virtual void on_focused_plot( cmGrH_t grH ); virtual void on_key_event( cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode ); virtual bool on_plot_object( cmGrPlotCbArg_t* arg ); private: enum { kHBord = 0, // dist between vertical elements (cols) kVBord = 0, // dist between horz elements (rows) kBtnH = 20, // control height kBtnW = 50, // button width kOutW = 100, // output width kLblW = 20, // output label width, kScrD = 20 // scroll bar thickness }; enum { kHScrollId, kVScrollId, kShowAllId, kReportId, kZoomInId, kZoomOutId, kZoomInXId, kZoomInYId, kZoomOutXId, kZoomOutYId, }; cmGrPgH_t _pgH; cmGrPlH_t _plH; cmGrPageFltk* _pg; Fl_Group* _ctl_grp; Fl_Group* _usr_grp; Fl_Output* _status; // status text output Fl_Scrollbar* _hsb; // scroll bars Fl_Scrollbar* _vsb; Fl_Output* _gx; // current global coord display Fl_Output* _gy; Fl_Output* _lx; // current local coord display Fl_Output* _ly; Fl_Output* _s0x; // seletion point Fl_Output* _s0y; Fl_Output* _s1x; Fl_Output* _s1y; Fl_Output* _sdx; Fl_Output* _sdy; int _textSz; void _layout(); Fl_Group* _create_ctls(); void _create_scroll_bars(); void _showHideScrollBars(); cmGrH_t _getFocusedView(); // controls callback static void _s_ctl_cb(Fl_Widget* w, long id ); // plot page callbacks static void _s_cmGrCallback( void* arg, cmGrH_t grH, cmGrCbId_t id, unsigned eventFlags, cmGrKeyCodeId_t keycode ); // plot object callbacks static bool _s_cmGrPlotObjCbFunc( cmGrPlotCbArg_t* arg ); }; #endif