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.

246 lines
6.2KB

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