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.

139 lines
3.8KB

  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. void BuildMenu();
  43. int GetID() { return m_ID; }
  44. void SetID(int s) { m_ID=s; }
  45. void SetChannel(int s) { m_Channel=s; }
  46. int GetChannel() { return m_Channel; }
  47. int GetColour() { return m_Colour; }
  48. void SetColour(int s) { m_Colour=s; }
  49. void SnapX() { if (m_GridX) x(x()-((x()-GetParentX())%m_GridX)); redraw(); }
  50. void SnapY() { if (m_GridY) y(y()-((y()-GetParentY())%m_GridY)); redraw(); }
  51. void SetName(string s) { m_Name=s; }
  52. string GetName() { return m_Name; }
  53. void SetGridX(int s) { m_GridX=s; }
  54. void SetGridY(int s) { m_GridY=s; }
  55. void LockX() { m_LockX=true; }
  56. void LockY() { m_LockY=true; }
  57. void LockResize(bool s){ m_LockResize=s; }
  58. void SetResizeGrab(int s) { m_ResizeGrab=s; }
  59. void SetSnapGap(float s)
  60. { m_SnapGap=s; if(s) m_GridX=(int)(s*(float)m_PixelsPerSec); }
  61. float GetStartTime() { return m_StartTime; }
  62. float GetLengthTime() { return m_LengthTime; }
  63. void SetLengthTime(float s) { m_LengthTime=s; w((int)(m_LengthTime*m_PixelsPerSec)); redraw(); }
  64. int GetGroup() { return (y()-GetParentY())/m_GridY; }
  65. Type GetType() { return m_Type; }
  66. void SetType(Type s) { m_Type=s; }
  67. void SetPixelsPerSec(int s, bool FirstTime=false);
  68. int GetParentX();
  69. int GetParentY();
  70. void Place(int sx, int sy) { x(sx); y(sy); }
  71. bool UpdateState(float Time);
  72. bool AtStart() { return m_FirstUpdate; }
  73. bool AtEnd() { return m_LastUpdate; }
  74. bool Killed() { return m_DelMe; }
  75. void KillMe() { m_DelMe=true; }
  76. int GetX() { return x(); }
  77. int GetY() { return y(); }
  78. int GetW() { return w(); }
  79. private:
  80. Fl_Menu_Button *m_Menu;
  81. Type m_Type;
  82. // whether we were active or not last tick
  83. bool m_LastState;
  84. // if this is the first or last update
  85. bool m_FirstUpdate;
  86. bool m_LastUpdate;
  87. string m_Name;
  88. int m_ID;
  89. int m_Colour;
  90. int m_GridX;
  91. int m_GridY;
  92. bool m_LockX;
  93. bool m_LockY;
  94. bool m_LockResize;
  95. int m_ResizeGrab;
  96. int m_PixelsPerSec;
  97. int m_Channel;
  98. float m_StartTime;
  99. float m_LengthTime;
  100. float m_SnapGap;
  101. DragMode m_CurrentDragMode;
  102. bool m_DelMe;
  103. int LastButtonPushed;
  104. };
  105. /////////////////////////////////////////////////////////
  106. class Fl_CircEvent : public Fl_SEvent
  107. {
  108. public:
  109. Fl_CircEvent(int x, int y, int w, int h, const char* label=0);
  110. Fl_CircEvent(const Fl_CircEvent &Other);
  111. virtual void draw();
  112. private:
  113. };
  114. #endif