gcsx_wscroll.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* GCSx
  2. ** WSCROLL.H
  3. **
  4. ** Widget parent class to provide frame/scrollbars
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_WSCROLL_H_
  24. #define __GCSx_WSCROLL_H_
  25. class WidgetScroll : public Widget {
  26. public:
  27. enum FrameType {
  28. // Frame types (normally textbox background color)
  29. FRAMETYPE_BEVEL,
  30. FRAMETYPE_BEVEL_BK, // BKFILL background color
  31. FRAMETYPE_LINE,
  32. FRAMETYPE_NONE,
  33. };
  34. protected:
  35. enum DragType {
  36. // Drag types
  37. FRAME_DRAG_NONE,
  38. FRAME_DRAG_CLIENT,
  39. FRAME_DRAG_SCROLLBAR_HORIZ,
  40. FRAME_DRAG_SCROLLBAR_VERT,
  41. };
  42. enum DragSubType {
  43. // Drag subtypes for scrollbar
  44. FRAME_SCROLL_NONE = 0,
  45. FRAME_SCROLL_LESS, // Left/Up
  46. FRAME_SCROLL_PAGELESS, // Page Left/Up
  47. FRAME_SCROLL_MORE, // Right/Down
  48. FRAME_SCROLL_PAGEMORE, // Page Right/Down
  49. FRAME_SCROLL_TAB,
  50. };
  51. enum {
  52. // Dirty reasons, can be OR'd
  53. FRAME_DIRTY_NONE = 0,
  54. FRAME_DIRTY_SCROLLVERT = 1,
  55. FRAME_DIRTY_SCROLLHORIZ = 2,
  56. FRAME_DIRTY_ALL = 255, // If resized or scroll existence changes
  57. };
  58. FrameType frameType;
  59. Window* clientArea;
  60. Widget* clientWidget; // NULL if client is a plain window
  61. int haveFocus;
  62. int whyDirty;
  63. int scrollbarButtonSize;
  64. int scrollbarButtonXPad;
  65. int frameThickness;
  66. // (width and position of our client area- not necessarily width/position
  67. // of client window internally, which can be larger/smaller and scroll)
  68. // (main _includes_ scrollbars, Inner does not)
  69. int clientX;
  70. int clientY;
  71. int clientWidth;
  72. int clientHeight;
  73. int clientWidthInner;
  74. int clientHeightInner;
  75. // Width and height of client area
  76. // Reupdated whenever we resize()
  77. int clientActualWidth;
  78. int clientActualHeight;
  79. // Scroll offset (always zero or negative)
  80. int scrollX;
  81. int scrollY;
  82. // Scroll sizes- how much to scroll
  83. int vScrollLine;
  84. int vScrollPage;
  85. int hScrollLine;
  86. int hScrollPage;
  87. // Position to draw scrollbars; set to 0 if no scrollbars
  88. // Size of actual drawn scrollbars
  89. int vScrollbarX;
  90. int vScrollbarY;
  91. int vScrollbarWidth;
  92. int vScrollbarHeight;
  93. int vScrollbarTab; // Offset within scroll area
  94. int vScrollbarTabSize; // 0 = tab not shown
  95. int hScrollbarX;
  96. int hScrollbarY;
  97. int hScrollbarWidth;
  98. int hScrollbarHeight;
  99. int hScrollbarTab; // Offset within scroll area
  100. int hScrollbarTabSize; // 0 = tab not shown
  101. // Used for autorepeating scrollbar actions
  102. Uint32 scrollRepeatTicks;
  103. Uint32 scrollRepeatDelay;
  104. // Internal- for dragging titlebar, borders, etc.
  105. // hoverMode used just for hovering
  106. DragType dragMode;
  107. DragSubType dragItem;
  108. int dragX;
  109. int dragY;
  110. int dragItemOverflowX;
  111. int dragItemOverflowY;
  112. // Scrolls to a given -X, -Y
  113. // Automatically clips scroll to best possible
  114. // Can specify x and/or y for scrollbar tabs to force if needed
  115. void scrollTo(int sX, int sY, int tabX = -1, int tabY = -1);
  116. // Which area is a given coords in? titlebar, buttons, border, etc.
  117. // Returns a drag constant, and if applicable, a drag item (resize constant or button number)
  118. void whereCoords(int x, int y, DragType* dragType, DragSubType* dragItem) const;
  119. enum {
  120. // Sizing constants
  121. FRAME_BEVELTHICKNESS = 2,
  122. FRAME_LINETHICKNESS = 1,
  123. // Minimum size for scrollbar tab
  124. FRAME_SCROLLTABMIN = 10,
  125. // MS to wait before repeating scrollbar action initially
  126. DELAY_SCROLLBAR_REPEATSTART = 500,
  127. // MS to wait between additional repeats of scrollbar action
  128. DELAY_SCROLLBAR_REPEATAGAIN = 75,
  129. };
  130. static const std::string wtButtonUp;
  131. static const std::string wtButtonDown;
  132. static const std::string wtButtonLeft;
  133. static const std::string wtButtonRight;
  134. void construct(FrameType type, Window* client, int cWidth = -1, int cHeight = -1);
  135. public:
  136. // Width and height represent client area and default to client's current size
  137. // These can easily be changed when you run show() to display the window
  138. // Client area pointer will be deleted by us if it wantsToBeDeleted().
  139. // We don't take ownership of pointer if constructor fails.
  140. // Client can be a widget or a regular window.
  141. WidgetScroll(FrameType type, Widget* client, int cWidth = -1, int cHeight = -1);
  142. WidgetScroll(FrameType type, Window* client, int cWidth = -1, int cHeight = -1, int cId = 0);
  143. ~WidgetScroll();
  144. // Client should call this whenever it resizes to update scrollbars
  145. // Default Window::resize() will call this if appropriate
  146. void updateClientSize();
  147. // Client may call this to set scrolling amounts; if not called,
  148. // a default size is used (page amounts are automatically
  149. // determined as the full width/height minus one "line")
  150. void setScroll(int vLine, int hLine);
  151. // Scrolls to show as much of the given rectangle as possible
  152. // Automatically clips scroll to best possible
  153. void scrollToView(int sX, int sY, int sWidth, int sHeight);
  154. // Scrolls to offset from current scroll
  155. void scrollBy(int sX, int sY);
  156. // this won't resize ourselves, but adjusts scroll as needed
  157. void newClient(Window* fClient);
  158. void newClient(Widget* fClient);
  159. void newClient(); // (Sets as no client)
  160. void resize(int newWidth, int newHeight, int newViewWidth = -1, int newViewHeight = -1, int fromParent = 0);
  161. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  162. int event(int hasFocus, const SDL_Event* event);
  163. int getClientWidth() const { return clientWidth; }
  164. int getClientHeight() const { return clientHeight; }
  165. // These all simply pass down to client
  166. int stateTabId() const;
  167. int stateTabId(int wTabId);
  168. void doAction();
  169. void disable();
  170. void enable();
  171. int refuseAll() const;
  172. void load();
  173. void apply();
  174. int getId() const;
  175. char getShortcut() const;
  176. void resolutionChange(int fromW, int fromH, int fromBpp, int toW, int toH, int toBpp);
  177. void childMoved(int fromX, int fromY, int toX, int toY, Window* child);
  178. void childResized(int fromW, int fromH, int toW, int toH, Window* child);
  179. const char* tooltip(int xPos, int yPos) const;
  180. Widget* returnSelf();
  181. };
  182. #endif