ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
widget.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) by Fred Klaus *
3  * development@fkweb.de *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef SDLTK_WIDGET_H
21 #define SDLTK_WIDGET_H
22 
23 #include "canvas.h"
24 #include "SDL.h"
25 
26 
27 namespace sdltk
28 {
29 
30  class Color;
31  class Gui;
32  class Rect;
33  class Size;
34  class Point;
35 
37  class Widget
38  {
39 
40  public:
42  Widget(Canvas * const canvas);
44  Widget(Widget * const parent = nullptr);
46  virtual ~Widget() ROLAND_DEFAULT
47 
49  virtual void draw() = 0;
51  virtual void onMouseMotion (SDL_MouseMotionEvent * event) {}
53  virtual void onMouseButton (SDL_MouseButtonEvent * event) {}
55  virtual bool onKeyboard (SDL_KeyboardEvent * event) {return false;}
57  virtual bool onUser (SDL_UserEvent * event) {return false;}
58 
60  virtual void setPos(int x, int y)
61  {mRect.setX(x), mRect.setY(y);}
63  virtual void setSize(int width, int height)
64  {mRect.setWidth(width), mRect.setHeight(height);}
65 
67  virtual void setCanvas(Canvas * const canvas);
68 
70  void setParent (Widget * const parent) {mParent = parent;}
72  const Widget * parent() const {return mParent;}
73 
75  void setColor(const Color & color) {mColor = color;}
77  void setColor(int r, int g, int b, int a=255) {mColor.set(r,g,b,a);}
79  Color color() const {return mColor;}
80 
82  void setEnabled (bool val) {mEnabled = val;}
84  void setWantEvents(bool val) {mWantEvents = val;}
86  void setMouseOver (bool val) {mMouseOver = val;}
87 
89  bool enabled() const {return mEnabled;}
91  bool wantEvents() const {return mWantEvents;}
93  bool mouseOver() const {return mMouseOver;}
95  bool hasMouseGrab() const {return mMouseGrab;}
96 
98  Sint16 x() const {return mRect.x();}
100  Sint16 y() const {return mRect.y();}
102  Point pos() const {return mRect.pos();}
104  Uint16 width() const {return mRect.width();}
106  Uint16 height() const {return mRect.height();}
108  Size size() const {return mRect.size();}
109 
110  Point relativePos(Sint16 x, Sint16 y) const
111  {return Point(x - mRect.x(), y - mRect.y());}
112  void relativePos(Sint16 x, Sint16 y, Point & target) const
113  {return target.set(x - mRect.x(), y - mRect.y());}
114 
115  const Rect & rect() const {return mRect;}
116  const Rect & canvasrect() const {return mCanvasRect;}
117 
118  protected:
121 
125 
126  bool mEnabled;
130  };
131 
132 } // sdltk
133 
134 #endif // SDLTK_WIDGET_H
135 
136 
137 
void setEnabled(bool val)
Set Widget enabled.
Definition: widget.h:82
virtual void setSize(int width, int height)
Sets the Size.
Definition: widget.h:63
void set(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255)
Definition: color.cpp:30
Sint16 x() const
Definition: rect.h:102
virtual void setCanvas(Canvas *const canvas)
Sets the Canvas to draw on.
Definition: widget.cpp:41
bool hasMouseGrab() const
Returns whether the Widget has MouseGrab.
Definition: widget.h:95
bool wantEvents() const
Returns whether the Widget wants Events.
Definition: widget.h:91
bool mMouseGrab
Definition: widget.h:128
GLuint GLfloat GLenum cap GLsizei GLuint *textures GLenum GLint *params void GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLfloat GLfloat y GLubyte GLubyte GLubyte b
Definition: glfunclist.h:27
void setMouseOver(bool val)
Sets whehther to catch MouseOver.
Definition: widget.h:86
Sint16 y() const
Returns the y position of the upper left corner.
Definition: widget.h:100
virtual bool onUser(SDL_UserEvent *event)
Catch UserEvents.
Definition: widget.h:57
Color color() const
Returns the Color of the Widget.
Definition: widget.h:79
const Size & size
Definition: rect.h:39
bool mouseOver() const
Returns whether the Widget receives MouseOver.
Definition: widget.h:93
Rect mCanvasRect
Definition: widget.h:123
Widget(Canvas *const canvas)
Constructor with Canvas.
Definition: widget.cpp:25
GLuint GLfloat GLenum cap GLsizei GLuint *textures GLenum GLint *params void GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLfloat GLfloat y GLubyte r
Definition: glfunclist.h:27
GLuint GLfloat GLenum cap GLsizei GLuint *textures GLenum GLint *params void GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLfloat GLfloat y GLubyte GLubyte g
Definition: glfunclist.h:27
Widget * mParent
Definition: widget.h:120
Point pos() const
Definition: rect.h:99
Sint16 x() const
Returns the x position of the upper left corner.
Definition: widget.h:98
virtual void onMouseButton(SDL_MouseButtonEvent *event)
Catch MouseButton events.
Definition: widget.h:53
Color mColor
Definition: widget.h:124
const Rect & rect() const
Definition: widget.h:115
Definition: canvas.h:40
const Rect & canvasrect() const
Definition: widget.h:116
bool mWantEvents
Definition: widget.h:129
Uint16 width() const
Returns the width of the Widget.
Definition: widget.h:104
bool mEnabled
Definition: widget.h:126
virtual void onMouseMotion(SDL_MouseMotionEvent *event)
Catch MouseMotion events.
Definition: widget.h:51
Point pos() const
Returns the position of the upper left corner.
Definition: widget.h:102
void setHeight(Uint16 h)
Definition: rect.h:96
void setColor(const Color &color)
Sets the Color of the Widget by Color.
Definition: widget.h:75
bool mMouseOver
Definition: widget.h:127
void setWantEvents(bool val)
Sets whether to catch Events.
Definition: widget.h:84
void setColor(int r, int g, int b, int a=255)
Sets the Color of the Widget by RGB(A)
Definition: widget.h:77
Sint16 y
Definition: rect.h:69
virtual ~Widget() ROLAND_DEFAULT virtual void draw()=0
Standarddestructor.
GLuint GLfloat GLenum cap GLsizei GLuint *textures GLenum GLint *params void GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum target
Definition: glfunclist.h:21
Uint16 height() const
Returns the height of the Widget.
Definition: widget.h:106
Canvas * mCanvas
Definition: widget.h:119
bool enabled() const
Returns whether the Widget is enabled.
Definition: widget.h:89
virtual bool onKeyboard(SDL_KeyboardEvent *event)
Catch Keyboard events.
Definition: widget.h:55
#define ROLAND_DEFAULT
Definition: compspec.h:46
Baseclass for all Widgets.
Definition: widget.h:37
Size size() const
Returns the Size of the Widget.
Definition: widget.h:108
Defines a 2D point (x, y)
Definition: point.h:28
Uint16 height() const
Definition: rect.h:105
void setX(Sint16 x)
Definition: rect.h:93
defines a planar size (width, height)
Definition: size.h:30
Rect mRect
Definition: widget.h:122
void setY(Sint16 y)
Definition: rect.h:94
void setWidth(Uint16 w)
Definition: rect.h:95
RGBA Color Type.
Definition: color.h:30
Definition: rect.h:32
void relativePos(Sint16 x, Sint16 y, Point &target) const
Definition: widget.h:112
Uint16 width() const
Definition: rect.h:104
virtual void setPos(int x, int y)
Sets the Position.
Definition: widget.h:60
the SDL based Stuff
Definition: audio.cpp:22
const Widget * parent() const
Returns the parent.
Definition: widget.h:72
Point relativePos(Sint16 x, Sint16 y) const
Definition: widget.h:110
void setParent(Widget *const parent)
Sets the parent Widget.
Definition: widget.h:70