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.

283 lines
6.0KB

  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 <stdio.h>
  19. #include "SeqSelectorPluginGUI.h"
  20. #include <FL/fl_draw.h>
  21. #include <FL/fl_draw.H>
  22. static const int GUI_COLOUR = 179;
  23. static const int GUIBG_COLOUR = 144;
  24. static const int GUIBG2_COLOUR = 145;
  25. ////////////////////////////////////////////
  26. CountLine::CountLine(int n) :
  27. Fl_Group(0,0,330,25,"")
  28. {
  29. box(FL_FLAT_BOX);
  30. if (n%4==0) color(GUIBG2_COLOUR);
  31. if (n%8==0) color(GUI_COLOUR);
  32. sprintf(m_Count,"%d",n);
  33. Fl_Box *Num = new Fl_Box(5,2,30,20,m_Count);
  34. Num->labelsize(10);
  35. Num->labeltype(FL_ENGRAVED_LABEL);
  36. Num->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
  37. add(Num);
  38. m_Flasher = new Fl_LED_Button(15,2,20,20,"");
  39. m_Flasher->selection_color(FL_BLUE);
  40. add(m_Flasher);
  41. for (int n=0; n<NUM_VALUES; n++)
  42. {
  43. m_Counter[n] = new Fl_Counter(30+n*35, 2, 35, 20, "");
  44. m_Counter[n]->labelsize(10);
  45. m_Counter[n]->type(FL_SIMPLE_COUNTER);
  46. m_Counter[n]->step(1);
  47. m_Counter[n]->value(0);
  48. add(m_Counter[n]);
  49. }
  50. end();
  51. redraw();
  52. }
  53. CountLine::~CountLine()
  54. {
  55. }
  56. void CountLine::SetVal(int n, float val)
  57. {
  58. // range check
  59. assert(n>=0 && n<8);
  60. m_Counter[n]->value(val);
  61. }
  62. float CountLine::GetVal(int n)
  63. {
  64. // range check
  65. assert(n>=0 && n<8);
  66. return m_Counter[n]->value();
  67. }
  68. ////////////////////////////////////////////
  69. SeqSelectorPluginGUI::SeqSelectorPluginGUI(int w, int h,SeqSelectorPlugin *o,const HostInfo *Info) :
  70. SpiralPluginGUI(w,h,o)
  71. {
  72. m_Plugin=o;
  73. m_Scroll = new Fl_Scroll(0, 20, w, h-50, "");
  74. m_Scroll->type(Fl_Scroll::VERTICAL_ALWAYS);
  75. m_Scroll->box(FL_NO_BOX);
  76. m_Scroll->position(0,0);
  77. add(m_Scroll);
  78. m_Main = new Fl_Pack(0,20,w,h-50,"");
  79. m_Main->box(FL_NO_BOX);
  80. m_Scroll->add(m_Main);
  81. m_New = new Fl_Button(5,h-25,100,20,"New");
  82. m_New->labelsize(10);
  83. m_New->callback((Fl_Callback*)cb_New);
  84. add(m_New);
  85. m_Delete = new Fl_Button(110,h-25,100,20,"Delete");
  86. m_Delete->labelsize(10);
  87. m_Delete->callback((Fl_Callback*)cb_Delete);
  88. add(m_Delete);
  89. m_Begin = new Fl_Counter(220,h-28,50,15,"Begin");
  90. m_Begin->labelsize(10);
  91. m_Begin->type(FL_SIMPLE_COUNTER);
  92. m_Begin->step(1);
  93. m_Begin->value(0);
  94. m_Begin->callback((Fl_Callback*)cb_Begin);
  95. add(m_Begin);
  96. m_End = new Fl_Counter(280,h-28,50,15,"End");
  97. m_End->labelsize(10);
  98. m_End->type(FL_SIMPLE_COUNTER);
  99. m_End->step(1);
  100. m_End->value(0);
  101. m_End->callback((Fl_Callback*)cb_End);
  102. add(m_End);
  103. m_UseRange = new Fl_Button(340,h-25,55,20,"UseRange");
  104. m_UseRange->labelsize(10);
  105. m_UseRange->type(1);
  106. m_UseRange->value(0);
  107. m_UseRange->callback((Fl_Callback*)cb_UseRange);
  108. add(m_UseRange);
  109. end();
  110. }
  111. float SeqSelectorPluginGUI::GetVal(int l, int v)
  112. {
  113. int c=0;
  114. list<CountLine*>::iterator i = m_LineVec.end();
  115. do
  116. {
  117. i--;
  118. if (l==c) return (*i)->GetVal(v);
  119. c++;
  120. }
  121. while (i!=m_LineVec.begin());
  122. return 0;
  123. }
  124. void SeqSelectorPluginGUI::AddLine(int* Val)
  125. {
  126. CountLine *NewLine = new CountLine(m_LineVec.size());
  127. // copy the last line
  128. list<CountLine*>::iterator i=m_LineVec.begin();
  129. if (Val)
  130. {
  131. for (int n=0; n<NUM_VALUES; n++)
  132. {
  133. NewLine->SetVal(n,Val[n]);
  134. }
  135. }
  136. else
  137. {
  138. if (m_LineVec.size()>0)
  139. {
  140. for (int n=0; n<NUM_VALUES; n++)
  141. {
  142. NewLine->SetVal(n,(*i)->GetVal(n));
  143. }
  144. }
  145. }
  146. m_Main->add(NewLine);
  147. m_LineVec.push_front(NewLine);
  148. redraw();
  149. Fl::check();
  150. }
  151. void SeqSelectorPluginGUI::RemoveLine()
  152. {
  153. list<CountLine*>::iterator i=m_LineVec.begin();
  154. if (m_LineVec.size()>0)
  155. {
  156. m_Main->remove(*i);
  157. delete(*i);
  158. m_LineVec.erase(i);
  159. m_Main->redraw();
  160. m_Scroll->redraw();
  161. }
  162. }
  163. void SeqSelectorPluginGUI::SetLED(int n)
  164. {
  165. int c=0;
  166. list<CountLine*>::iterator i = m_LineVec.end();
  167. do
  168. {
  169. i--;
  170. if (n==c) (*i)->SetLED(true);
  171. else (*i)->SetLED(false);
  172. c++;
  173. }
  174. while (i!=m_LineVec.begin());
  175. }
  176. void SeqSelectorPluginGUI::UpdateValues()
  177. {
  178. }
  179. inline void SeqSelectorPluginGUI::cb_New_i(Fl_Button* o, void* v)
  180. {
  181. AddLine();
  182. }
  183. void SeqSelectorPluginGUI::cb_New(Fl_Button* o, void* v)
  184. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_New_i(o,v); }
  185. inline void SeqSelectorPluginGUI::cb_Delete_i(Fl_Button* o, void* v)
  186. {
  187. RemoveLine();
  188. }
  189. void SeqSelectorPluginGUI::cb_Delete(Fl_Button* o, void* v)
  190. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_Delete_i(o,v); }
  191. inline void SeqSelectorPluginGUI::cb_Begin_i(Fl_Counter* o, void* v)
  192. {
  193. m_Plugin->SetBegin((int)o->value());
  194. }
  195. void SeqSelectorPluginGUI::cb_Begin(Fl_Counter* o, void* v)
  196. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_Begin_i(o,v); }
  197. inline void SeqSelectorPluginGUI::cb_End_i(Fl_Counter* o, void* v)
  198. {
  199. m_Plugin->SetEnd((int)o->value());
  200. }
  201. void SeqSelectorPluginGUI::cb_End(Fl_Counter* o, void* v)
  202. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_End_i(o,v); }
  203. inline void SeqSelectorPluginGUI::cb_UseRange_i(Fl_Button* o, void* v)
  204. {
  205. m_Plugin->UseRange(o->value());
  206. }
  207. void SeqSelectorPluginGUI::cb_UseRange(Fl_Button* o, void* v)
  208. { ((SeqSelectorPluginGUI*)(o->parent()))->cb_UseRange_i(o,v); }
  209. void SeqSelectorPluginGUI::StreamOut(ostream &s)
  210. {
  211. s<<m_LineVec.size()<<" ";
  212. if (m_LineVec.size()>0)
  213. {
  214. // Stream out in reverse
  215. list<CountLine*>::iterator i = m_LineVec.end();
  216. do
  217. {
  218. i--;
  219. for (int n=0; n<NUM_VALUES; n++)
  220. {
  221. s<<(*i)->GetVal(n)<<" ";
  222. }
  223. }
  224. while (i!=m_LineVec.begin());
  225. }
  226. }
  227. void SeqSelectorPluginGUI::StreamIn(istream &s)
  228. {
  229. int Num;
  230. s>>Num;
  231. for (int i=0; i<Num; i++)
  232. {
  233. int Val[8];
  234. for (int n=0; n<NUM_VALUES; n++)
  235. {
  236. s>>Val[n];
  237. }
  238. AddLine(Val);
  239. }
  240. }