Programmable real-time audio signal processing application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmGrFltk.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #ifndef cmGrFltk_h
  2. #define cmGrFltk_h
  3. class Fl_Group;
  4. class Fl_Output;
  5. class Fl_Scrollbar;
  6. class cmGrDevDrvFltk
  7. {
  8. public:
  9. cmGrDevDrvFltk();
  10. virtual ~cmGrDevDrvFltk(){}
  11. static bool create( void* user, unsigned w, unsigned h );
  12. static void destroy( void* user );
  13. static void begin_draw( void* arg );
  14. static void end_draw( void* arg );
  15. static void draw( void* arg, int x, int y );
  16. static void set_color( void* user, const cmGrColor_t c );
  17. static void get_color( void* user, cmGrColor_t* c );
  18. static void set_font_family( void* user, unsigned fontId );
  19. static unsigned get_font_family( void* user );
  20. static void set_font_style( void* user, unsigned style );
  21. static unsigned get_font_style( void* user );
  22. static void set_font_size( void* user, unsigned size );
  23. static unsigned get_font_size( void* user );
  24. static void set_pen_style( void* user, unsigned styleFlags );
  25. static unsigned get_pen_style( void* user );
  26. static void set_pen_width( void* user, unsigned w );
  27. static unsigned get_pen_width( void* user );
  28. static void draw_line( void* user, int x0, int y0, int x1, int y1 );
  29. static void draw_rect( void* user, int x0, int y0, unsigned w, unsigned h );
  30. static void fill_rect( void* user, int x0, int y0, unsigned w, unsigned h );
  31. static void draw_ellipse( void* user, int x0, int y0, unsigned w, unsigned h );
  32. static void fill_ellipse( void* user, int x0, int y0, unsigned w, unsigned h );
  33. static void draw_diamond( void* user, int x0, int y0, unsigned w, unsigned h );
  34. static void fill_diamond( void* user, int x0, int y0, unsigned w, unsigned h );
  35. static void draw_triangle( void* user, int x0, int y0, unsigned w, unsigned h, unsigned dirFlag );
  36. static void fill_triangle( void* user, int x0, int y0, unsigned w, unsigned h, unsigned dirFlag );
  37. static void draw_text( void* user, const char* text, int x, int y );
  38. static void draw_text_rot( void* user, const char* text, int x, int y, int angle );
  39. static void measure_text( void* user, const char* text, unsigned* w, unsigned* h );
  40. static void read_image( void* user, unsigned char* p, int x, int y, unsigned w, unsigned h );
  41. static void draw_image( void* user, const unsigned char* p, int x, int y, unsigned w, unsigned h );
  42. bool is_initialized() const;
  43. cmGrDev_t d;
  44. private:
  45. unsigned _fltk_pen_width;
  46. unsigned _fltk_pen_style;
  47. unsigned _fltk_font_size;
  48. unsigned _w;
  49. unsigned _h;
  50. static void _get_font_family_style( unsigned* fontId, unsigned* style );
  51. static void _set_font_family_style( void* user, unsigned fontId, unsigned style );
  52. };
  53. //--------------------------------------------------------------------------------------
  54. // Canvas Object
  55. class cmGrViewFltk : public Fl_Widget
  56. {
  57. public:
  58. cmGrViewFltk( cmCtx_t* ctx, cmGrH_t grH, int x, int y, int w, int h );
  59. virtual ~cmGrViewFltk();
  60. virtual int handle(int event);
  61. virtual void resize(int x, int y, int w, int h );
  62. void setGrH( cmGrH_t grH );
  63. private:
  64. virtual void draw();
  65. typedef struct
  66. {
  67. unsigned idx;
  68. unsigned fltk_code;
  69. char ch;
  70. cmGrKeyCodeId_t gr_code;
  71. } keyMap_t;
  72. cmGrH_t _grH;
  73. cmGrDevDrvFltk _dd;
  74. cmGrDcH_t _dcH;
  75. static keyMap_t _keymap[];
  76. const keyMap_t* _getGrKeyCode( unsigned fltk_code );
  77. cmGrKeyCodeId_t _eventKeyCode( );
  78. };
  79. //--------------------------------------------------------------------------------------
  80. // Container for multiple plots
  81. class cmGrPageFltk : public Fl_Group
  82. {
  83. public:
  84. cmGrPageFltk( cmCtx_t* ctx, cmGrPgH_t pgH, int x, int y, int w, int h );
  85. virtual ~cmGrPageFltk();
  86. virtual void createView( unsigned vwIdx );
  87. virtual void destroyView( unsigned vwIdx );
  88. virtual cmGrDcH_t devCtxHandle();
  89. virtual cmGrViewFltk* viewWidget( unsigned vwIdx );
  90. virtual void resize(int x, int y, int w, int h );
  91. private:
  92. virtual void draw();
  93. cmGrDevDrvFltk _dd;
  94. cmCtx_t* _ctx;
  95. cmGrPgH_t _pgH;
  96. cmGrDcH_t _dcH;
  97. cmGrViewFltk** _vwV;
  98. unsigned _vwN;
  99. };
  100. //--------------------------------------------------------------------------------------
  101. // Contains a single cmGrPageFltk and a control panel
  102. class cmGrPlotFltk : public Fl_Group
  103. {
  104. public:
  105. cmGrPlotFltk( cmCtx_t* ctx, int x, int y, int w, int h, int rn=1, int cn=1, int textSz=10 );
  106. virtual ~cmGrPlotFltk();
  107. virtual void resize(int x, int y, int w, int h );
  108. cmGrPgH_t pageHandle();
  109. cmGrPlH_t plotHandle();
  110. cmGrDcH_t dcHandle();
  111. virtual void initViews( int rn, int cn );
  112. virtual void setStatusText( const cmChar_t* s );
  113. virtual void on_button( unsigned id );
  114. virtual void on_scroll( Fl_Scrollbar* sb, unsigned id );
  115. virtual void on_view_create( unsigned viewIdx );
  116. virtual void on_view_destroy( unsigned viewIdx );
  117. virtual void rpt_local_pt( cmGrH_t grH );
  118. virtual void rpt_global_pt( cmGrH_t grH );
  119. virtual void on_phys_change( cmGrH_t grH );
  120. virtual void on_view_change( cmGrH_t grH );
  121. virtual void on_select_change( cmGrH_t grH );
  122. virtual void on_focused_plot( cmGrH_t grH );
  123. virtual void on_key_event( cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode );
  124. virtual bool on_plot_object( cmGrPlotCbArg_t* arg );
  125. private:
  126. enum
  127. {
  128. kHBord = 0, // dist between vertical elements (cols)
  129. kVBord = 0, // dist between horz elements (rows)
  130. kBtnH = 20, // control height
  131. kBtnW = 50, // button width
  132. kOutW = 100, // output width
  133. kLblW = 20, // output label width,
  134. kScrD = 20 // scroll bar thickness
  135. };
  136. enum
  137. {
  138. kHScrollId,
  139. kVScrollId,
  140. kShowAllId,
  141. kReportId,
  142. kZoomInId,
  143. kZoomOutId,
  144. kZoomInXId,
  145. kZoomInYId,
  146. kZoomOutXId,
  147. kZoomOutYId,
  148. };
  149. cmGrPgH_t _pgH;
  150. cmGrPlH_t _plH;
  151. cmGrPageFltk* _pg;
  152. Fl_Group* _ctl_grp;
  153. Fl_Group* _usr_grp;
  154. Fl_Output* _status; // status text output
  155. Fl_Scrollbar* _hsb; // scroll bars
  156. Fl_Scrollbar* _vsb;
  157. Fl_Output* _gx; // current global coord display
  158. Fl_Output* _gy;
  159. Fl_Output* _lx; // current local coord display
  160. Fl_Output* _ly;
  161. Fl_Output* _s0x; // seletion point
  162. Fl_Output* _s0y;
  163. Fl_Output* _s1x;
  164. Fl_Output* _s1y;
  165. Fl_Output* _sdx;
  166. Fl_Output* _sdy;
  167. int _textSz;
  168. void _layout();
  169. Fl_Group* _create_ctls();
  170. void _create_scroll_bars();
  171. void _showHideScrollBars();
  172. cmGrH_t _getFocusedView();
  173. // controls callback
  174. static void _s_ctl_cb(Fl_Widget* w, long id );
  175. // plot page callbacks
  176. static void _s_cmGrCallback( void* arg, cmGrH_t grH, cmGrCbId_t id, unsigned eventFlags, cmGrKeyCodeId_t keycode );
  177. // plot object callbacks
  178. static bool _s_cmGrPlotObjCbFunc( cmGrPlotCbArg_t* arg );
  179. };
  180. #endif