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.

166 lines
4.4KB

  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. ////////////////////////////////////////////
  23. OperatorPluginGUI::OperatorPluginGUI(int w, int h,OperatorPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  24. SpiralPluginGUI(w,h,o,ch)
  25. {
  26. int KeyWidth=10,Note,Pos=0,Count=0;
  27. m_Add = new Fl_Button(5, 15, 15, 15,"+");
  28. m_Add->type(1);
  29. m_Add->value(1);
  30. m_Add->selection_color(Info->GUI_COLOUR);
  31. m_Add->callback((Fl_Callback*)cb_Add);
  32. m_Sub = new Fl_Button(5, 30, 15, 15,"-");
  33. m_Sub->type(1);
  34. m_Sub->selection_color(Info->GUI_COLOUR);
  35. m_Sub->callback((Fl_Callback*)cb_Sub);
  36. m_Mul = new Fl_Button(5, 45, 15, 15,"*");
  37. m_Mul->type(1);
  38. m_Mul->selection_color(Info->GUI_COLOUR);
  39. m_Mul->callback((Fl_Callback*)cb_Mul);
  40. m_Div = new Fl_Button(5, 60, 15, 15,"/");
  41. m_Div->type(1);
  42. m_Div->selection_color(Info->GUI_COLOUR);
  43. m_Div->callback((Fl_Callback*)cb_Div);
  44. m_Constant = new Fl_Input(25, 15, 50, 20, "Constant");
  45. m_Constant->color(Info->GUI_COLOUR);
  46. m_Constant->labelsize(8);
  47. m_Constant->align(FL_ALIGN_BOTTOM|FL_ALIGN_CENTER);
  48. m_Constant->textsize(10);
  49. m_Constant->value("0");
  50. m_Constant->when(FL_WHEN_ENTER_KEY);
  51. m_Constant->callback((Fl_Callback*)cb_Constant);
  52. end();
  53. }
  54. void OperatorPluginGUI::UpdateValues(SpiralPlugin *o)
  55. {
  56. OperatorPlugin* Plugin = (OperatorPlugin*)o;
  57. m_Add->value(false);
  58. m_Sub->value(false);
  59. m_Mul->value(false);
  60. m_Div->value(false);
  61. switch (Plugin->GetOperator())
  62. {
  63. case OperatorPlugin::ADD : m_Add->value(true); break;
  64. case OperatorPlugin::SUB : m_Sub->value(true); break;
  65. case OperatorPlugin::MUL : m_Mul->value(true); break;
  66. case OperatorPlugin::DIV : m_Div->value(true); break;
  67. }
  68. char t[256];
  69. sprintf(t,"%f",Plugin->GetConstant());
  70. m_Constant->value(t);
  71. }
  72. //// Callbacks ////
  73. inline void OperatorPluginGUI::cb_Add_i(Fl_Button* o, void* v)
  74. {
  75. if (o->value())
  76. {
  77. m_Sub->value(false);
  78. m_Mul->value(false);
  79. m_Div->value(false);
  80. m_GUICH->Set("Operator",(int)OperatorPlugin::ADD);
  81. }
  82. else
  83. {
  84. o->value(true);
  85. }
  86. }
  87. void OperatorPluginGUI::cb_Add(Fl_Button* o, void* v)
  88. { ((OperatorPluginGUI*)(o->parent()))->cb_Add_i(o,v);}
  89. inline void OperatorPluginGUI::cb_Sub_i(Fl_Button* o, void* v)
  90. {
  91. if (o->value())
  92. {
  93. m_Add->value(false);
  94. m_Mul->value(false);
  95. m_Div->value(false);
  96. m_GUICH->Set("Operator",(int)OperatorPlugin::SUB);
  97. }
  98. else
  99. {
  100. o->value(true);
  101. }
  102. }
  103. void OperatorPluginGUI::cb_Sub(Fl_Button* o, void* v)
  104. { ((OperatorPluginGUI*)(o->parent()))->cb_Sub_i(o,v);}
  105. inline void OperatorPluginGUI::cb_Mul_i(Fl_Button* o, void* v)
  106. {
  107. if (o->value())
  108. {
  109. m_Add->value(false);
  110. m_Sub->value(false);
  111. m_Div->value(false);
  112. m_GUICH->Set("Operator",(int)OperatorPlugin::MUL);
  113. }
  114. else
  115. {
  116. o->value(true);
  117. }
  118. }
  119. void OperatorPluginGUI::cb_Mul(Fl_Button* o, void* v)
  120. { ((OperatorPluginGUI*)(o->parent()))->cb_Mul_i(o,v);}
  121. inline void OperatorPluginGUI::cb_Div_i(Fl_Button* o, void* v)
  122. {
  123. if (o->value())
  124. {
  125. m_Add->value(false);
  126. m_Sub->value(false);
  127. m_Mul->value(false);
  128. m_GUICH->Set("Operator",(int)OperatorPlugin::DIV);
  129. }
  130. else
  131. {
  132. o->value(true);
  133. }
  134. }
  135. void OperatorPluginGUI::cb_Div(Fl_Button* o, void* v)
  136. { ((OperatorPluginGUI*)(o->parent()))->cb_Div_i(o,v);}
  137. inline void OperatorPluginGUI::cb_Constant_i(Fl_Input* o, void* v)
  138. {
  139. m_GUICH->Set("Constant",(float)strtod(o->value(),NULL));
  140. }
  141. void OperatorPluginGUI::cb_Constant(Fl_Input* o, void* v)
  142. { ((OperatorPluginGUI*)(o->parent()))->cb_Constant_i(o,v);}
  143. const string OperatorPluginGUI::GetHelpText(const string &loc){
  144. return string("")
  145. + "Simply performs the operation on the input data,\n"
  146. + "if there is only one input, it uses the constant.";
  147. }