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.

253 lines
6.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 "LogicPluginGUI.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. LogicPluginGUI::LogicPluginGUI(int w, int h,LogicPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
  27. SpiralPluginGUI(w,h,o,ch)
  28. {
  29. int Width=32,Depth=20,Pos=0,Count=0;
  30. m_AND = new Fl_Button(5, 15, Width, Depth, "AND");
  31. m_AND->type(1);
  32. m_AND->value(1);
  33. m_AND->labelsize(10);
  34. m_AND->selection_color(GUI_COLOUR);
  35. m_AND->callback((Fl_Callback*)cb_AND);
  36. m_OR = new Fl_Button(5, 35, Width, Depth,"OR");
  37. m_OR->type(1);
  38. m_OR->labelsize(10);
  39. m_OR->selection_color(GUI_COLOUR);
  40. m_OR->callback((Fl_Callback*)cb_OR);
  41. m_NOT = new Fl_Button(5, 55, Width, Depth,"NOT");
  42. m_NOT->type(1);
  43. m_NOT->labelsize(10);
  44. m_NOT->selection_color(GUI_COLOUR);
  45. m_NOT->callback((Fl_Callback*)cb_NOT);
  46. m_NAND = new Fl_Button(5, 75, Width, Depth,"NAND");
  47. m_NAND->type(1);
  48. m_NAND->labelsize(10);
  49. m_NAND->selection_color(GUI_COLOUR);
  50. m_NAND->callback((Fl_Callback*)cb_NAND);
  51. m_NOR = new Fl_Button(37, 15, Width, Depth,"NOR");
  52. m_NOR->type(1);
  53. m_NOR->labelsize(10);
  54. m_NOR->selection_color(GUI_COLOUR);
  55. m_NOR->callback((Fl_Callback*)cb_NOR);
  56. m_XOR = new Fl_Button(37, 35, Width, Depth,"XOR");
  57. m_XOR->type(1);
  58. m_XOR->labelsize(10);
  59. m_XOR->selection_color(GUI_COLOUR);
  60. m_XOR->callback((Fl_Callback*)cb_XOR);
  61. m_XNOR = new Fl_Button(37, 55, Width, Depth,"XNOR");
  62. m_XNOR->type(1);
  63. m_XNOR->labelsize(10);
  64. m_XNOR->selection_color(GUI_COLOUR);
  65. m_XNOR->callback((Fl_Callback*)cb_XNOR);
  66. // Andy Preston - multiple inputs
  67. m_Inputs = new Fl_Counter (17, 97, 40, 20, "Inputs");
  68. m_Inputs->labelsize (10);
  69. m_Inputs->type (FL_SIMPLE_COUNTER);
  70. m_Inputs->step (1);
  71. m_Inputs->value (2);
  72. m_Inputs->callback ((Fl_Callback*) cb_Inputs);
  73. end();
  74. }
  75. void LogicPluginGUI::ClearButtons()
  76. {
  77. m_AND->value(false);
  78. m_OR->value(false);
  79. m_NOT->value(false);
  80. m_NAND->value(false);
  81. m_NOR->value(false);
  82. m_XOR->value(false);
  83. m_XNOR->value(false);
  84. }
  85. void LogicPluginGUI::UpdateValues(SpiralPlugin *o)
  86. {
  87. LogicPlugin* Plugin = (LogicPlugin*)o;
  88. ClearButtons();
  89. switch (Plugin->GetOperator())
  90. {
  91. case LogicPlugin::AND : m_AND->value(true); break;
  92. case LogicPlugin::OR : m_OR->value(true); break;
  93. case LogicPlugin::NOT : m_NOT->value(true); break;
  94. case LogicPlugin::NAND : m_NAND->value(true); break;
  95. case LogicPlugin::NOR : m_NOR->value(true); break;
  96. case LogicPlugin::XOR : m_XOR->value(true); break;
  97. case LogicPlugin::XNOR : m_XNOR->value(true); break;
  98. }
  99. // Andy Preston - multiple inputs
  100. m_Inputs->value (Plugin->GetInputs());
  101. }
  102. //// Callbacks ////
  103. // Andy Preston - multiple inputs
  104. inline void LogicPluginGUI::cb_Inputs_i (Fl_Counter* o, void* v) {
  105. if (o->value() < 2) o->value(2);
  106. else {
  107. m_GUICH->Set ("Inputs", int (o->value ()));
  108. m_GUICH->SetCommand (LogicPlugin::SETINPUTS);
  109. }
  110. }
  111. void LogicPluginGUI::cb_Inputs (Fl_Counter* o, void* v) {
  112. ((LogicPluginGUI*) (o->parent ())) -> cb_Inputs_i (o, v);
  113. }
  114. inline void LogicPluginGUI::cb_AND_i(Fl_Button* o, void* v)
  115. {
  116. if (o->value())
  117. {
  118. ClearButtons();
  119. o->value(true);
  120. m_GUICH->Set("Operator",(int)LogicPlugin::AND);
  121. }
  122. else
  123. {
  124. o->value(true);
  125. }
  126. }
  127. void LogicPluginGUI::cb_AND(Fl_Button* o, void* v)
  128. { ((LogicPluginGUI*)(o->parent()))->cb_AND_i(o,v);}
  129. inline void LogicPluginGUI::cb_OR_i(Fl_Button* o, void* v)
  130. {
  131. if (o->value())
  132. {
  133. ClearButtons();
  134. o->value(true);
  135. m_GUICH->Set("Operator",(int)LogicPlugin::OR);
  136. }
  137. else
  138. {
  139. o->value(true);
  140. }
  141. }
  142. void LogicPluginGUI::cb_OR(Fl_Button* o, void* v)
  143. { ((LogicPluginGUI*)(o->parent()))->cb_OR_i(o,v);}
  144. inline void LogicPluginGUI::cb_NOT_i(Fl_Button* o, void* v)
  145. {
  146. if (o->value())
  147. {
  148. ClearButtons();
  149. o->value(true);
  150. m_GUICH->Set("Operator",(int)LogicPlugin::NOT);
  151. }
  152. else
  153. {
  154. o->value(true);
  155. }
  156. }
  157. void LogicPluginGUI::cb_NOT(Fl_Button* o, void* v)
  158. { ((LogicPluginGUI*)(o->parent()))->cb_NOT_i(o,v);}
  159. inline void LogicPluginGUI::cb_NAND_i(Fl_Button* o, void* v)
  160. {
  161. if (o->value())
  162. {
  163. ClearButtons();
  164. o->value(true);
  165. m_GUICH->Set("Operator",(int)LogicPlugin::NAND);
  166. }
  167. else
  168. {
  169. o->value(true);
  170. }
  171. }
  172. void LogicPluginGUI::cb_NAND(Fl_Button* o, void* v)
  173. { ((LogicPluginGUI*)(o->parent()))->cb_NAND_i(o,v);}
  174. inline void LogicPluginGUI::cb_NOR_i(Fl_Button* o, void* v)
  175. {
  176. if (o->value())
  177. {
  178. ClearButtons();
  179. o->value(true);
  180. m_GUICH->Set("Operator",(int)LogicPlugin::NOR);
  181. }
  182. else
  183. {
  184. o->value(true);
  185. }
  186. }
  187. void LogicPluginGUI::cb_NOR(Fl_Button* o, void* v)
  188. { ((LogicPluginGUI*)(o->parent()))->cb_NOR_i(o,v);}
  189. inline void LogicPluginGUI::cb_XOR_i(Fl_Button* o, void* v)
  190. {
  191. if (o->value())
  192. {
  193. ClearButtons();
  194. o->value(true);
  195. m_GUICH->Set("Operator",(int)LogicPlugin::XOR);
  196. }
  197. else
  198. {
  199. o->value(true);
  200. }
  201. }
  202. void LogicPluginGUI::cb_XOR(Fl_Button* o, void* v)
  203. { ((LogicPluginGUI*)(o->parent()))->cb_XOR_i(o,v);}
  204. inline void LogicPluginGUI::cb_XNOR_i(Fl_Button* o, void* v)
  205. {
  206. if (o->value())
  207. {
  208. ClearButtons();
  209. o->value(true);
  210. m_GUICH->Set("Operator",(int)LogicPlugin::XNOR);
  211. }
  212. else
  213. {
  214. o->value(true);
  215. }
  216. }
  217. void LogicPluginGUI::cb_XNOR(Fl_Button* o, void* v)
  218. { ((LogicPluginGUI*)(o->parent()))->cb_XNOR_i(o,v);}
  219. const string LogicPluginGUI::GetHelpText(const string &loc){
  220. return string("")
  221. + "Note that NOT only uses input 1,\nand XOR/XNOR only use inputs 1 and 2\n\n"
  222. + "1001010111010101101111101010100101010101010100010100100101\n"
  223. + "0010101010111010010010101010001010011110001010101000101010\n"
  224. + "1110111101101001000010101010111110101010101010101111010101\n"
  225. + "0011011111010101101000001010101010001010100001100111010111";
  226. }