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.

170 lines
4.5KB

  1. /* SpiralPlugin
  2. * Copyleft (C) 2000 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "OperatorPluginGUI.h"
  19. #include <FL/fl_draw.h>
  20. #include <FL/fl_draw.H>
  21. #include <stdio.h>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. ////////////////////////////////////////////
  26. OperatorPluginGUI::OperatorPluginGUI(int w, int h,OperatorPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  27. SpiralPluginGUI(w,h,o,ch)
  28. {
  29. int KeyWidth=10,Note,Pos=0,Count=0;
  30. m_Add = new Fl_Button(5, 15, 15, 15,"+");
  31. m_Add->type(1);
  32. m_Add->value(1);
  33. m_Add->selection_color(GUI_COLOUR);
  34. m_Add->callback((Fl_Callback*)cb_Add);
  35. m_Sub = new Fl_Button(5, 30, 15, 15,"-");
  36. m_Sub->type(1);
  37. m_Sub->selection_color(GUI_COLOUR);
  38. m_Sub->callback((Fl_Callback*)cb_Sub);
  39. m_Mul = new Fl_Button(5, 45, 15, 15,"*");
  40. m_Mul->type(1);
  41. m_Mul->selection_color(GUI_COLOUR);
  42. m_Mul->callback((Fl_Callback*)cb_Mul);
  43. m_Div = new Fl_Button(5, 60, 15, 15,"/");
  44. m_Div->type(1);
  45. m_Div->selection_color(GUI_COLOUR);
  46. m_Div->callback((Fl_Callback*)cb_Div);
  47. m_Constant = new Fl_Input(25, 15, 50, 20, "Constant");
  48. m_Constant->color(GUI_COLOUR);
  49. m_Constant->labelsize(8);
  50. m_Constant->align(FL_ALIGN_BOTTOM|FL_ALIGN_CENTER);
  51. m_Constant->textsize(10);
  52. m_Constant->value("0");
  53. m_Constant->when(FL_WHEN_ENTER_KEY);
  54. m_Constant->callback((Fl_Callback*)cb_Constant);
  55. end();
  56. }
  57. void OperatorPluginGUI::UpdateValues(SpiralPlugin *o)
  58. {
  59. OperatorPlugin* Plugin = (OperatorPlugin*)o;
  60. m_Add->value(false);
  61. m_Sub->value(false);
  62. m_Mul->value(false);
  63. m_Div->value(false);
  64. switch (Plugin->GetOperator())
  65. {
  66. case OperatorPlugin::ADD : m_Add->value(true); break;
  67. case OperatorPlugin::SUB : m_Sub->value(true); break;
  68. case OperatorPlugin::MUL : m_Mul->value(true); break;
  69. case OperatorPlugin::DIV : m_Div->value(true); break;
  70. }
  71. char t[256];
  72. sprintf(t,"%f",Plugin->GetConstant());
  73. m_Constant->value(t);
  74. }
  75. //// Callbacks ////
  76. inline void OperatorPluginGUI::cb_Add_i(Fl_Button* o, void* v)
  77. {
  78. if (o->value())
  79. {
  80. m_Sub->value(false);
  81. m_Mul->value(false);
  82. m_Div->value(false);
  83. m_GUICH->Set("Operator",(int)OperatorPlugin::ADD);
  84. }
  85. else
  86. {
  87. o->value(true);
  88. }
  89. }
  90. void OperatorPluginGUI::cb_Add(Fl_Button* o, void* v)
  91. { ((OperatorPluginGUI*)(o->parent()))->cb_Add_i(o,v);}
  92. inline void OperatorPluginGUI::cb_Sub_i(Fl_Button* o, void* v)
  93. {
  94. if (o->value())
  95. {
  96. m_Add->value(false);
  97. m_Mul->value(false);
  98. m_Div->value(false);
  99. m_GUICH->Set("Operator",(int)OperatorPlugin::SUB);
  100. }
  101. else
  102. {
  103. o->value(true);
  104. }
  105. }
  106. void OperatorPluginGUI::cb_Sub(Fl_Button* o, void* v)
  107. { ((OperatorPluginGUI*)(o->parent()))->cb_Sub_i(o,v);}
  108. inline void OperatorPluginGUI::cb_Mul_i(Fl_Button* o, void* v)
  109. {
  110. if (o->value())
  111. {
  112. m_Add->value(false);
  113. m_Sub->value(false);
  114. m_Div->value(false);
  115. m_GUICH->Set("Operator",(int)OperatorPlugin::MUL);
  116. }
  117. else
  118. {
  119. o->value(true);
  120. }
  121. }
  122. void OperatorPluginGUI::cb_Mul(Fl_Button* o, void* v)
  123. { ((OperatorPluginGUI*)(o->parent()))->cb_Mul_i(o,v);}
  124. inline void OperatorPluginGUI::cb_Div_i(Fl_Button* o, void* v)
  125. {
  126. if (o->value())
  127. {
  128. m_Add->value(false);
  129. m_Sub->value(false);
  130. m_Mul->value(false);
  131. m_GUICH->Set("Operator",(int)OperatorPlugin::DIV);
  132. }
  133. else
  134. {
  135. o->value(true);
  136. }
  137. }
  138. void OperatorPluginGUI::cb_Div(Fl_Button* o, void* v)
  139. { ((OperatorPluginGUI*)(o->parent()))->cb_Div_i(o,v);}
  140. inline void OperatorPluginGUI::cb_Constant_i(Fl_Input* o, void* v)
  141. {
  142. m_GUICH->Set("Constant",(float)strtod(o->value(),NULL));
  143. }
  144. void OperatorPluginGUI::cb_Constant(Fl_Input* o, void* v)
  145. { ((OperatorPluginGUI*)(o->parent()))->cb_Constant_i(o,v);}
  146. const string OperatorPluginGUI::GetHelpText(const string &loc){
  147. return string("")
  148. + "Simply performs the operation on the input data,\n"
  149. + "if there is only one input, it uses the constant.";
  150. }