Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
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.

126 lines
3.9KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #pragma once
  19. /* Just like an Fl_Input, except that when not being edited it
  20. * displays just like a label. */
  21. #include <FL/fl_draw.H>
  22. #include <FL/Fl.H>
  23. #include <FL/Fl_Window.H>
  24. #include <FL/Fl_Input.H>
  25. class Fl_Sometimes_Input : public Fl_Input
  26. {
  27. Fl_Boxtype _up_box;
  28. char *_text;
  29. public:
  30. Fl_Sometimes_Input ( int X, int Y, int W, int H, const char *L=0 )
  31. : Fl_Input( X, Y, W, H, L )
  32. {
  33. clear_visible_focus();
  34. up_box( FL_NO_BOX );
  35. when(FL_WHEN_ENTER_KEY);
  36. }
  37. void up_box ( Fl_Boxtype b ) { _up_box = b; }
  38. Fl_Boxtype up_box ( void ) const { return _up_box; }
  39. virtual void
  40. draw ( void )
  41. {
  42. if ( this == Fl::focus() )
  43. Fl_Input::draw();
  44. else
  45. {
  46. fl_draw_box( up_box(), x(), y(), w(), h(), color() );
  47. Fl_Color c = textcolor();// fl_contrast( textcolor(), color() );
  48. fl_color( active_r() ? c : fl_inactive( c ) );
  49. fl_font( textfont(), textsize() );
  50. fl_draw( value(), x(), y(), w(), h(), (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_CLIP) );
  51. }
  52. }
  53. virtual void
  54. take_focus ( void )
  55. {
  56. set_visible_focus();
  57. Fl_Widget::take_focus();
  58. clear_visible_focus();
  59. }
  60. virtual int
  61. handle ( int m )
  62. {
  63. int r = 0;
  64. switch ( m )
  65. {
  66. case FL_KEYDOWN:
  67. {
  68. if ( ( Fl::event_key() == FL_Enter ||
  69. Fl::event_key() == FL_Tab ) )
  70. {
  71. do_callback();
  72. free( _text );
  73. Fl::focus( NULL );
  74. r = 1;
  75. }
  76. else if ( Fl::event_key() == FL_Escape )
  77. {
  78. value( _text );
  79. Fl::focus( NULL );
  80. r = 1;
  81. }
  82. break;
  83. }
  84. case FL_FOCUS:
  85. _text = strdup( value() );
  86. redraw();
  87. r = 1;
  88. break;
  89. case FL_UNFOCUS:
  90. _text = NULL;
  91. redraw();
  92. r = 1;
  93. break;
  94. case FL_PUSH:
  95. take_focus();
  96. redraw();
  97. r = 1;
  98. break;
  99. case FL_DND_ENTER:
  100. return 0;
  101. case FL_PASTE:
  102. return 0;
  103. default:
  104. break;
  105. }
  106. return Fl_Input::handle( m ) | r;
  107. }
  108. };