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.

141 lines
4.7KB

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