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.

215 lines
5.4KB

  1. /* DeviceGUI composite Widget
  2. * Copyleft (C) 2002 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 "Fl_DeviceGUI.h"
  19. #include "Fl_Canvas.h"
  20. #include "../../SpiralSynthModularInfo.h"
  21. int Fl_DeviceGUI::Numbers[512];
  22. Fl_DeviceGUI::Fl_DeviceGUI(const DeviceGUIInfo& Info, Fl_Group *PW, Fl_Pixmap *Icon) :
  23. Fl_Group(Info.XPos, Info.YPos, Info.Width+(PortGroupWidth*2), Info.Height+TitleBarHeight, ""),
  24. m_PluginWindow(NULL),
  25. m_Icon(NULL),
  26. m_Name(Info.Name),
  27. m_ID(-1),
  28. m_DelMe(false)
  29. {
  30. for (int n=0; n<512; n++) Numbers[n]=n;
  31. type(1);
  32. box(FL_PLASTIC_UP_BOX);
  33. labeltype(FL_ENGRAVED_LABEL);
  34. align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
  35. color(SpiralSynthModularInfo::GUICOL_Device);
  36. m_Icon=Icon;
  37. m_DragBar = new Fl_DragBar(Info.XPos, Info.YPos, Info.Width+PortGroupWidth*2, TitleBarHeight, m_Name.c_str());
  38. m_DragBar->labelsize(10);
  39. m_DragBar->type(Fl_DragBar::FLDRAG);
  40. m_DragBar->color(SpiralSynthModularInfo::GUICOL_Device);
  41. m_PluginWindow = PW;
  42. //Add the input/output ports
  43. Setup(Info, true);
  44. }
  45. void Fl_DeviceGUI::Clear()
  46. {
  47. end();
  48. }
  49. int Fl_DeviceGUI::handle(int event)
  50. {
  51. int t=Fl_Group::handle(event);
  52. if (t==0)
  53. {
  54. if (event==FL_PUSH && Fl::event_button()==1)
  55. {
  56. if (m_PluginWindow && !m_DelMe)
  57. {
  58. if(!m_PluginWindow->visible())
  59. {
  60. m_PluginWindow->show();
  61. }
  62. /*else
  63. {
  64. m_PluginWindow->hide();
  65. }*/
  66. }
  67. }
  68. if (event==FL_RELEASE && Fl::event_button()==2)
  69. {
  70. m_DelMe = true;
  71. }
  72. }
  73. return t;
  74. }
  75. void Fl_DeviceGUI::draw()
  76. {
  77. Fl_Group::draw();
  78. if (m_Icon)
  79. {
  80. int Centx=x()+w()/2;
  81. int Centy=y()+h()/2;
  82. m_Icon->draw(Centx-m_Icon->w()/2,Centy-m_Icon->h()/2);
  83. }
  84. }
  85. void Fl_DeviceGUI::Setup(const DeviceGUIInfo& Info, bool FirstTime)
  86. {
  87. m_Info=Info;
  88. // Remove all current connections - it's the safest thing to do.
  89. if (parent() && !FirstTime)
  90. {
  91. ((Fl_Canvas*)(parent()))->ClearConnections(this);
  92. }
  93. // delete the current ports
  94. for(vector<Fl_Button*>::iterator i=m_PortVec.begin();
  95. i!=m_PortVec.end(); i++)
  96. {
  97. remove(*i);
  98. delete(*i);
  99. }
  100. m_PortVec.clear();
  101. int InputX=x()+2;
  102. int OutputX=x()+PortGroupWidth+Info.Width+4;
  103. int StartY=y()+TitleBarHeight;
  104. int PortDist=10;
  105. int PortNum=0;
  106. h(Info.Height+TitleBarHeight);
  107. for (int n=0; n<Info.NumInputs; n++)
  108. {
  109. Fl_Button* NewInput = new Fl_Button(InputX,StartY+PortDist*n,PortSize,PortSize,"");
  110. NewInput->type(1);
  111. NewInput->value(false);
  112. NewInput->box(FL_ROUNDED_BOX);
  113. Fl_Color col = (Fl_Color) WIRE_COL0;
  114. switch (Info.PortTypes[n]) {
  115. case 0: col = (Fl_Color) WIRE_COL0;
  116. break;
  117. case 1: col = (Fl_Color) WIRE_COL1;
  118. break;
  119. case 2: col = (Fl_Color) WIRE_COL2;
  120. break;
  121. case 3: col = (Fl_Color) WIRE_COL3;
  122. break;
  123. case 4: col = (Fl_Color) WIRE_COL4;
  124. break;
  125. default: col = (Fl_Color) WIRE_COL0;
  126. }
  127. NewInput->selection_color(col);
  128. NewInput->down_box(FL_ROUNDED_BOX);
  129. NewInput->tooltip(Info.PortTips[n].c_str());
  130. NewInput->callback((Fl_Callback*)cb_Port,(void*)&Numbers[PortNum]);
  131. m_PortVec.push_back(NewInput);
  132. add(NewInput);
  133. PortNum++;
  134. }
  135. for (int n=0; n<Info.NumOutputs; n++)
  136. {
  137. Fl_Button* NewOutput = new Fl_Button(OutputX,StartY+PortDist*n,PortSize,PortSize,"");
  138. NewOutput->type(1);
  139. NewOutput->value(false);
  140. NewOutput->box(FL_ROUNDED_BOX);
  141. Fl_Color col = (Fl_Color) WIRE_COL0;
  142. switch (Info.PortTypes[n+Info.NumInputs]) {
  143. case 0: col = (Fl_Color) WIRE_COL0;
  144. break;
  145. case 1: col = (Fl_Color) WIRE_COL1;
  146. break;
  147. case 2: col = (Fl_Color) WIRE_COL2;
  148. break;
  149. case 3: col = (Fl_Color) WIRE_COL3;
  150. break;
  151. case 4: col = (Fl_Color) WIRE_COL4;
  152. break;
  153. default: col = (Fl_Color) WIRE_COL0;
  154. }
  155. NewOutput->selection_color(col);
  156. NewOutput->down_box(FL_ROUNDED_BOX);
  157. NewOutput->tooltip(Info.PortTips[n+Info.NumInputs].c_str());
  158. NewOutput->callback((Fl_Callback*)cb_Port,(void*)&Numbers[PortNum]);
  159. m_PortVec.push_back(NewOutput);
  160. add(NewOutput);
  161. PortNum++;
  162. }
  163. }
  164. inline void Fl_DeviceGUI::cb_Port_i(Fl_Button* o, void* v)
  165. {
  166. int Port=*(int*)(v);
  167. PortType Pt;
  168. if (m_DelMe) return;
  169. // Find out if this is an input or an output.
  170. if (Port<m_Info.NumInputs)
  171. {
  172. Pt=INPUT;
  173. }
  174. else
  175. {
  176. Pt=OUTPUT;
  177. Port-=m_Info.NumInputs;
  178. }
  179. ((Fl_Canvas*)(parent()))->PortClicked(this,Pt,Port,o->value());
  180. }
  181. void Fl_DeviceGUI::cb_Port(Fl_Button* o, void* v)
  182. {((Fl_DeviceGUI*)(o->parent()))->cb_Port_i(o,v);}