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.

136 lines
3.7KB

  1. /* Event Widget
  2. * Copyleft (C) 2001 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/Fl.H>
  19. #include <FL/Fl_Group.H>
  20. #include <FL/Fl_Button.H>
  21. #include <FL/Fl_Window.H>
  22. #include <iostream>
  23. #include <map>
  24. #include <string>
  25. #include <vector>
  26. #ifndef SEVENT
  27. #define SEVENT
  28. using namespace std;
  29. class Fl_EventMap;
  30. class Fl_SEvent : public Fl_Button
  31. {
  32. public:
  33. enum Type{NO_TYPE,MELODY,PERCUSSION};
  34. enum DragMode{NONE,MOVING,RESIZING};
  35. Fl_SEvent(int x, int y, int w, int h, const char* label=0);
  36. Fl_SEvent(const Fl_SEvent &Other);
  37. virtual ~Fl_SEvent();
  38. virtual void draw();
  39. virtual int handle(int event);
  40. int GetID() { return m_ID; }
  41. void SnapX() { if (m_GridX) x(x()-((x()-GetParentX())%m_GridX)); redraw(); }
  42. void SnapY() { if (m_GridY) y(y()-((y()-GetParentY())%m_GridY)); redraw(); }
  43. void SetName(string s) { m_Name=s; }
  44. string GetName() { return m_Name; }
  45. void SetID(int s) { m_ID=s; }
  46. void SetGridX(int s) { m_GridX=s; }
  47. void SetGridY(int s) { m_GridY=s; }
  48. void LockX() { m_LockX=true; }
  49. void LockY() { m_LockY=true; }
  50. void LockResize(bool s){ m_LockResize=s; }
  51. void SetResizeGrab(int s) { m_ResizeGrab=s; }
  52. void SetSnapGap(float s)
  53. { m_SnapGap=s; if(s) m_GridX=(int)(s*(float)m_PixelsPerSec); }
  54. float GetStartTime() { return m_StartTime; }
  55. float GetLengthTime() { return m_LengthTime; }
  56. void SetLengthTime(float s) { m_LengthTime=s; w((int)(m_LengthTime*m_PixelsPerSec)); redraw(); }
  57. int GetGroup() { return (y()-GetParentY())/m_GridY; }
  58. Type GetType() { return m_Type; }
  59. void SetType(Type s) { m_Type=s; }
  60. void SetPixelsPerSec(int s, bool FirstTime=false);
  61. int GetParentX();
  62. int GetParentY();
  63. void Place(int sx, int sy) { x(sx); y(sy); }
  64. bool UpdateState(float Time);
  65. bool AtStart() { return m_FirstUpdate; }
  66. bool AtEnd() { return m_LastUpdate; }
  67. bool Killed() { return m_DelMe; }
  68. int GetX() { return x(); }
  69. int GetY() { return y(); }
  70. int GetW() { return w(); }
  71. private:
  72. Type m_Type;
  73. // whether we were active or not last tick
  74. bool m_LastState;
  75. // if this is the first or last update
  76. bool m_FirstUpdate;
  77. bool m_LastUpdate;
  78. string m_Name;
  79. int m_ID;
  80. int m_GridX;
  81. int m_GridY;
  82. bool m_LockX;
  83. bool m_LockY;
  84. bool m_LockResize;
  85. int m_ResizeGrab;
  86. int m_PixelsPerSec;
  87. float m_StartTime;
  88. float m_LengthTime;
  89. float m_SnapGap;
  90. DragMode m_CurrentDragMode;
  91. bool m_DelMe;
  92. int LastButtonPushed;
  93. };
  94. /////////////////////////////////////////////////////////
  95. class Fl_TriEvent : public Fl_SEvent
  96. {
  97. public:
  98. Fl_TriEvent(int x, int y, int w, int h, const char* label=0);
  99. Fl_TriEvent(const Fl_TriEvent &Other);
  100. virtual void draw();
  101. private:
  102. };
  103. /////////////////////////////////////////////////////////
  104. class Fl_CircEvent : public Fl_SEvent
  105. {
  106. public:
  107. Fl_CircEvent(int x, int y, int w, int h, const char* label=0);
  108. Fl_CircEvent(const Fl_CircEvent &Other);
  109. virtual void draw();
  110. private:
  111. };
  112. #endif