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.

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