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.

189 lines
3.9KB

  1. /* TriggerWidget
  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 "Fl_Trigger.h"
  19. #include <iostream>
  20. #include <FL/fl_draw.H>
  21. #include <math.h>
  22. #include <stdio.h>
  23. #include "Fl_Loop.h"
  24. /////////////////////////////////////////////////////////////////////////////
  25. static const float RADCONV = 0.017453292;
  26. Fl_Trigger::Fl_Trigger(int x, int y, int w, int h, const char* label) :
  27. Fl_Widget(x,y,w,h,label),
  28. m_ID(0),
  29. m_Channel(0),
  30. m_CentreX(0),
  31. m_CentreY(0),
  32. m_CentreRadius(0),
  33. m_Dragging(false),
  34. m_Loop(0),
  35. m_Passes(0),
  36. m_Count(0),
  37. m_Angle(0),
  38. m_MaxLoops(10),
  39. m_MaxPasses(10),
  40. m_Snap(false),
  41. m_SnapDegrees(45)
  42. {
  43. }
  44. void Fl_Trigger::draw()
  45. {
  46. x(parent()->x()+(int)((sin(m_Angle*RADCONV)*m_CentreRadius)+m_CentreX-w()/2));
  47. y(parent()->y()+(int)((cos(m_Angle*RADCONV)*m_CentreRadius)+m_CentreY-h()/2));
  48. fl_font(fl_font(),8);
  49. fl_color(255,255,255);
  50. fl_arc(x(), y(), w(), h(), 0, 360);
  51. int cx=x()+w()/2;
  52. int cy=y()+h()/2;
  53. char text[32];
  54. //sprintf(text,"%d",m_Loop);
  55. //fl_draw(text, cx-2, cy-h()+5);
  56. //sprintf(text,"%d",m_Passes);
  57. //fl_draw(text, cx+w()-5, cy+3);
  58. sprintf(text,"%d",m_Channel);
  59. fl_draw(text, cx, cy);
  60. //char t[32];
  61. //sprintf(t,"%d",m_Count);
  62. //fl_draw(t, cx-2, cy-h()+5);
  63. }
  64. int Fl_Trigger::handle(int event)
  65. {
  66. static int LastButtonPushed=0;
  67. // call base
  68. if (!Fl_Widget::handle(event))
  69. {
  70. int ww,hh;
  71. ww = w();
  72. hh = h();
  73. int mx = Fl::event_x();
  74. int my = Fl::event_y();
  75. switch (event)
  76. {
  77. case FL_PUSH:
  78. LastButtonPushed=Fl::event_button();
  79. if (LastButtonPushed==1)
  80. {
  81. m_Dragging=true;
  82. }
  83. if (LastButtonPushed==3)
  84. {
  85. m_Channel++;
  86. if (m_Channel>7)
  87. {
  88. m_Channel=0;
  89. }
  90. redraw();
  91. Fl_Loop *p=(Fl_Loop*)parent();
  92. p->DrawEveryThing();
  93. p->redraw();
  94. }
  95. // fall through
  96. case FL_DRAG:
  97. {
  98. if (LastButtonPushed==2)
  99. {
  100. }
  101. else if (LastButtonPushed==1)
  102. {
  103. if (m_Dragging)
  104. {
  105. int px = mx-(m_CentreX+parent()->x());
  106. int py = my-(m_CentreY+parent()->y());
  107. double angle = 90+atan2((float)-py, (float)px)*180/M_PI;
  108. while (angle < m_Angle-180) angle += 360;
  109. while (angle > m_Angle+180) angle -= 360;
  110. while (angle < 0) angle += 360;
  111. while (angle > 360) angle -= 360;
  112. m_Angle=angle;
  113. // snap
  114. if (m_Snap)
  115. {
  116. m_Angle-=(int)m_Angle%m_SnapDegrees;
  117. }
  118. redraw();
  119. }
  120. }
  121. else if (LastButtonPushed==3)
  122. {
  123. }
  124. }
  125. break;
  126. case FL_RELEASE:
  127. {
  128. m_Dragging=false;
  129. Fl_Loop *p=(Fl_Loop*)parent();
  130. p->DrawEveryThing();
  131. p->redraw();
  132. do_callback();
  133. }
  134. break;
  135. default:
  136. return 0;
  137. }
  138. }
  139. return 1;
  140. }
  141. istream &operator>>(istream &s, Fl_Trigger &o)
  142. {
  143. s>>o.m_CentreX>>o.m_CentreY>>o.m_CentreRadius>>o.m_Dragging>>o.m_ID>>o.m_Passes>>
  144. o.m_Count>>o.m_Angle>>o.m_MaxLoops>>o.m_MaxPasses;
  145. return s;
  146. }
  147. ostream &operator<<(ostream &s, Fl_Trigger &o)
  148. {
  149. s<<o.m_CentreX<<" "<<o.m_CentreY<<" "<<o.m_CentreRadius<<" "<<o.m_Dragging<<" "<<
  150. o.m_ID<<" "<<o.m_Passes<<" "<<o.m_Count<<" "<<o.m_Angle<<" "<<
  151. o.m_MaxLoops<<" "<<o.m_MaxPasses<<" ";
  152. return s;
  153. }