PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PlatformCanvas Class Reference

Validator platform canvas - no pixel buffer, used only for compilation. More...

#include <PlatformCanvas.h>

Inheritance diagram for PlatformCanvas:
PlatformWidget PCanvas PlatformWidget PCanvas PWidget PWidget PWidget PWidget PWidget PWidget PEBLObjectBase PEBLObjectBase PEBLObjectBase PEBLObjectBase PEBLObjectBase PEBLObjectBase

Public Member Functions

 PlatformCanvas (int width, int height, Variant bg)
 
 PlatformCanvas (int width, int height)
 
 PlatformCanvas (const PlatformCanvas &canv)
 This copy constructor isn't const because the font is shared.
 
virtual ~PlatformCanvas ()
 Standard Destructor.
 
virtual bool SetProperty (std::string, Variant v)
 
virtual bool Reset ()
 
virtual std::string ObjectName () const
 
virtual bool Draw ()
 This method initiates everything needed to display the main window

 
virtual void SetWidth (pInt h)
 
virtual void SetHeight (pInt h)
 
virtual void SetZoomX (double h)
 
virtual void SetZoomY (double h)
 
 PlatformCanvas (int width, int height)
 
 PlatformCanvas (int width, int height, Variant color)
 
virtual ~PlatformCanvas ()
 
virtual bool Draw ()
 This method initiates everything needed to display the main window

 
virtual std::string ObjectName () const
 
virtual bool SetProperty (std::string name, Variant v)
 
virtual ObjectValidationError ValidateProperty (std::string name, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string name) const
 
- Public Member Functions inherited from PlatformWidget
 PlatformWidget ()
 
virtual ~PlatformWidget ()
 
virtual SDL_Texture * GetSDL_Texture ()
 Used to extract an SDL surface from the widget. Used by children drawing themselves on their parent.
 
void SetParent (PlatformWidget *parent)
 
SDL_Surface * GetSurface ()
 
virtual bool SetRenderer (SDL_Renderer *renderer)
 
SDL_Renderer * GetRenderer ()
 
virtual bool AddToParentWidget (PlatformWidget *parent)
 
virtual bool AddSubWidget (PlatformWidget *widget)
 
virtual bool RemoveSubWidget (PlatformWidget *widget)
 
virtual bool RemoveSubWidgets ()
 
virtual bool RotoZoom (double angle, double zoomx, double zoomy, int smooth)
 This uses the SDL_gfx package to 'rotozoom'.
 
bool SetPoint (int x, int y, PColor col)
 
PColor GetPixel (int x, int y)
 
 PlatformWidget ()
 
 PlatformWidget (pInt x, pInt y, pInt width, pInt height, bool visible)
 
virtual ~PlatformWidget ()
 
virtual bool RotoZoom (pDouble angle, pDouble zoomx, pDouble zoomy, pInt smooth)
 
virtual bool SetPoint (pInt x, pInt y, PColor col)
 
virtual PColor GetPixel (pInt x, pInt y)
 
- Public Member Functions inherited from PWidget
 PWidget ()
 
 PWidget (const PWidget &pw)
 
 PWidget (pInt x, pInt y, pInt width, pInt height, bool visible)
 
virtual ~PWidget ()
 
virtual void SetParent (PWidget *widget)
 This unconditionally sets the parent widget.
 
virtual PWidgetGetParent ()
 
virtual bool IsParent (PWidget *parent)
 
virtual void SetZoomX (pDouble x)
 This sets the widget's position on its parent widget.
 
virtual void SetZoomY (pDouble x)
 This sets the widget's position on its parent widget.
 
virtual void SetRotation (pDouble x)
 This sets the widget's position on its parent widget.
 
virtual pInt GetX () const
 
virtual pInt GetY () const
 
virtual pInt GetWidth () const
 
virtual pInt GetHeight () const
 
virtual void SetBackgroundColor (const PColor &color)
 
virtual PColor GetBackgroundColor ()
 
virtual bool AddSubWidget (PWidget *widget)
 
virtual bool RemoveSubWidget (PWidget *widget)
 
virtual bool RemoveLastSubWidget ()
 This is probably pretty useless.
 
virtual void Show ()
 
virtual void Hide ()
 
virtual bool IsVisible () const
 
- Public Member Functions inherited from PEBLObjectBase
 PEBLObjectBase ()
 Standard Constructor.
 
 PEBLObjectBase (ComplexDataType cdt)
 Standard Constructor.
 
 PEBLObjectBase (const PEBLObjectBase &pob)
 
virtual ~PEBLObjectBase ()
 Standard Destructor.
 
virtual bool InitializeProperty (std::string name, Variant v)
 
Variant GetProperty (std::string) const
 
ComplexDataType GetType ()
 
virtual std::ostream & PrintProperties (std::ostream &out)
 
virtual Variant GetPropertyList ()
 
- Public Member Functions inherited from PCanvas
 PCanvas ()
 
 PCanvas (int width, int height, Variant color)
 
 PCanvas (int width, int height)
 
 PCanvas (PCanvas &canvas)
 
virtual ~PCanvas ()
 
virtual Variant GetProperty (std::string) const
 
virtual void SetPosition (pInt x, pInt y)
 This sets the widget's position on its parent widget.
 
virtual void SetHeight (int h)
 
virtual void SetWidth (int w)
 
virtual void SetColor (Variant col)
 
virtual bool GetDrawBackground () const
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 An inheritable printing class used by PEBLObjectBase::operator<<.
 
virtual std::ostream & SendToStream (std::ostream &out) const
 An inheritable printing class used by PEBLObjectBase::operator<<.
 
- Protected Member Functions inherited from PlatformWidget
virtual void PrintSubWidgets (std::ostream &out) const
 
virtual bool LockSurface ()
 This needs to be used on some platforms/video cards.
 
virtual bool UnlockSurface ()
 This needs to be used on some platforms/video cards.
 

Additional Inherited Members

- Protected Attributes inherited from PlatformWidget
pInt mTextureWidth
 
pInt mTextureHeight
 
bool mNeedsTexture
 
SDL_Texture * mTexture
 
SDL_Surface * mSurface
 
SDL_Renderer * mRenderer
 
- Protected Attributes inherited from PWidget
pInt mX
 
pInt mY
 
pInt mDrawX
 
pInt mDrawY
 
pInt mWidth
 
pInt mHeight
 
pDouble mZoomX
 
pDouble mZoomY
 
pDouble mRotation
 
PColor mBackgroundColor
 The background color of the widget. if alpha = 0, will not be painted.
 
std::list< PWidget * > mSubWidgets
 
bool mIsVisible
 
PWidgetmParent
 
- Protected Attributes inherited from PEBLObjectBase
ComplexDataType mCDT
 
std::map< std::string, VariantmProperties
 
- Protected Attributes inherited from PCanvas
bool mDrawBackground
 
bool mReset
 

Detailed Description

Validator platform canvas - no pixel buffer, used only for compilation.

This class defines an SDL-specific drawable canvas in which individual pixels can be drawn to.

Definition at line 43 of file sdl/PlatformCanvas.h.

Constructor & Destructor Documentation

◆ PlatformCanvas() [1/5]

PlatformCanvas::PlatformCanvas ( int  width,
int  height,
Variant  bg 
)

Definition at line 52 of file sdl/PlatformCanvas.cpp.

52 :
53
54 PCanvas(width, height,bg),
55 mPixels(NULL),
57
58{
59
60 mTextureWidth = width;
61 mTextureHeight = height;
62
64 InitializeProperty("BGCOLOR",bg);
65 SetColor(bg);
66
67 mSurface = NULL;
69 mTexture = NULL;
70 mNeedsTexture = true;
71 Reset();
72 Draw();
73
74}
#define NULL
Definition BinReloc.cpp:317
@ CDT_CANVAS
Definition PEBLObject.h:63
virtual void SetColor(Variant col)
Definition PCanvas.cpp:112
PCanvas()
Definition PCanvas.cpp:39
virtual bool InitializeProperty(std::string name, Variant v)
ComplexDataType mCDT
Definition PEBLObject.h:109
virtual bool Draw()
This method initiates everything needed to display the main window
SDL_Surface * mSurface
SDL_Texture * mTexture
SDL_Renderer * mRenderer

References CDT_CANVAS, Draw(), PEBLObjectBase::InitializeProperty(), PEBLObjectBase::mCDT, PlatformWidget::mNeedsTexture, PlatformWidget::mRenderer, PlatformWidget::mSurface, PlatformWidget::mTexture, PlatformWidget::mTextureHeight, PlatformWidget::mTextureWidth, NULL, Reset(), and PCanvas::SetColor().

◆ PlatformCanvas() [2/5]

PlatformCanvas::PlatformCanvas ( int  width,
int  height 
)

Definition at line 78 of file sdl/PlatformCanvas.cpp.

78 :
79 mCanvasWidth(0),
80 mCanvasHeight(0),
81 mPixels(NULL),
83 PCanvas(width, height)
84{
85
86 mTextureWidth = width;
87 mTextureHeight = height;
88
89 mWidth =width;
90 mHeight = height;
91
93
94 mSurface = NULL;
95 mTexture = NULL;
97 mNeedsTexture = true;
98 Reset();
99 //Draw();
100
101}
pInt mWidth
Definition PWidget.h:136
pInt mHeight
Definition PWidget.h:136

References CDT_CANVAS, PEBLObjectBase::mCDT, PWidget::mHeight, PlatformWidget::mNeedsTexture, PlatformWidget::mRenderer, PlatformWidget::mSurface, PlatformWidget::mTexture, PlatformWidget::mTextureHeight, PlatformWidget::mTextureWidth, PWidget::mWidth, NULL, and Reset().

◆ PlatformCanvas() [3/5]

PlatformCanvas::PlatformCanvas ( const PlatformCanvas canv)

This copy constructor isn't const because the font is shared.

Definition at line 106 of file sdl/PlatformCanvas.cpp.

106 :
109 PCanvas()
110{
111
112 PCanvas::mDrawBackground = canvas.GetDrawBackground();
114 mWidth = canvas.GetWidth();
115 mHeight = canvas.GetHeight();
118
119 mTexture = NULL;
120 mSurface = NULL;
121 mNeedsTexture = true;
122 Reset(); //reset initializes the canvas
123 //Draw();
124
125}
bool mDrawBackground
Definition PCanvas.h:66
PEBLObjectBase()
Standard Constructor.

References CDT_CANVAS, PCanvas::GetDrawBackground(), PWidget::GetHeight(), PWidget::GetWidth(), PEBLObjectBase::mCDT, PCanvas::mDrawBackground, PWidget::mHeight, PlatformWidget::mNeedsTexture, PlatformWidget::mSurface, PlatformWidget::mTexture, PlatformWidget::mTextureHeight, PlatformWidget::mTextureWidth, PWidget::mWidth, NULL, and Reset().

◆ ~PlatformCanvas() [1/2]

PlatformCanvas::~PlatformCanvas ( )
virtual

Standard Destructor.

Definition at line 129 of file sdl/PlatformCanvas.cpp.

130{
131
132 // PlatformWidget frees mSurface,
133 // and should free children...
134
135}

◆ PlatformCanvas() [4/5]

PlatformCanvas::PlatformCanvas ( int  width,
int  height 
)

◆ PlatformCanvas() [5/5]

PlatformCanvas::PlatformCanvas ( int  width,
int  height,
Variant  color 
)

◆ ~PlatformCanvas() [2/2]

virtual PlatformCanvas::~PlatformCanvas ( )
virtual

Member Function Documentation

◆ Draw() [1/2]

bool PlatformCanvas::Draw ( )
virtual

This method initiates everything needed to display the main window

Reimplemented from PlatformWidget.

Definition at line 268 of file sdl/PlatformCanvas.cpp.

269{
270 //Can we only reset if something has changed on a child?
271 mReset = true;
272 if(mReset)
273 {
274 }
275 Reset();
276
277
278 bool ret = PlatformWidget::Draw();
279 mReset = false;
280
281
282 return ret;
283}
bool mReset
Definition PCanvas.h:67
virtual bool Draw()
This method initiates everything needed to display the main window

References PlatformWidget::Draw(), PCanvas::mReset, and Reset().

Referenced by PlatformCanvas().

◆ Draw() [2/2]

virtual bool PlatformCanvas::Draw ( )
virtual

This method initiates everything needed to display the main window

Reimplemented from PlatformWidget.

◆ ObjectName() [1/2]

virtual std::string PlatformCanvas::ObjectName ( ) const
inlinevirtual

Reimplemented from PWidget.

Definition at line 60 of file sdl/PlatformCanvas.h.

60{return "PlatformCanvas";} ;

◆ ObjectName() [2/2]

virtual std::string PlatformCanvas::ObjectName ( ) const
inlinevirtual

Reimplemented from PWidget.

Definition at line 39 of file validator/PlatformCanvas.h.

39{ return "PlatformCanvas (validator)"; }

◆ Reset()

bool PlatformCanvas::Reset ( )
virtual

This method should be called when the canvas is initialized or something is changed. It will make the mSurface pointer hold the appropriate image.

Definition at line 149 of file sdl/PlatformCanvas.cpp.

150{
151
152
153
154 //create a new surface on which to render the text.
155
156 if(mSurface)
157 {
158 delete mSurface;
159 mSurface = NULL;
160 }
161
162 //Make a transparent surface of the prescribed size.
163
164#if 0
165 SDL_Surface * tmp = NULL;
166 // SDL_CreateRGBSurface(SDL_SWSURFACE,
167 // mWidth, mHeight,
168 // 32, rmask, gmask, bmask, amask);
169 if(!tmp) PError::SignalFatalError("Surface not created in Canvas::Reset.");
170
171#endif
172
173#ifdef SD2_DELETE
174
175 SDL_SetAlpha(mSurface,0,SDL_ALPHA_TRANSPARENT);
176 // SDL_SetAlpha( tmp, 0, SDL_ALPHA_OPAQUE );
177#endif
178
179
180
181 //Fill the box with the background color
182 // std::cout << mBackgroundColor << "|alpha:|" << mBackgroundColor.GetAlpha() << std::endl;
183
184
185
186 // if(mBackgroundColor.GetAlpha() <.000001)
187
188 // {
189 // std::cout << "Setting transparency\n";
190 //SDL_SetAlpha(mSurface,0,0);
191
192 // }
193 mReset = false; //Reset the reset flag.
194
195
196 //we can only render onto a texture if renderer exists.
197 //i.e., the canvas needs to be on a window.
198
199 if(mTexture)
200 {
201
202 SDL_DestroyTexture(mTexture);
203 mTexture =NULL;
204 mReset = true;
205 }
206 else
207 {
208 mReset = true;
209 }
210
211 if(mRenderer)
212 {
213
214
215 //we create texture from hidden surface to allow drawing on surface.
216 //mTexture = SDL_CreateTextureFromSurface(mRenderer,tmp);
217
218 mTexture = SDL_CreateTexture(mRenderer,
219 SDL_PIXELFORMAT_RGBA8888,
220 SDL_TEXTUREACCESS_TARGET,
221 (int)mTextureWidth,(int)mTextureHeight);
222
223 SDL_Rect screensize = {0,0,(int)(mTextureWidth),
224 (int)mTextureHeight};
225 SDL_SetRenderTarget(mRenderer,mTexture);
226 SDL_RenderClear( mRenderer );
227
228
229 SDL_SetRenderDrawColor(mRenderer, (mBackgroundColor.GetRed()),
233
234 SDL_RenderFillRect(mRenderer,&screensize);
235
236
237 SDL_SetRenderTarget(mRenderer,NULL);
238
239 //SDL_FreeSurface(tmp);
240
241 }else{
242 mReset = true;
243 }
244
245
246 if(mTexture)
247 return true;
248 else
249 {
250 mReset = true;
251 return false;
252 }
253}
int GetRed() const
Definition PColor.cpp:226
int GetAlpha() const
Definition PColor.cpp:229
int GetBlue() const
Definition PColor.cpp:228
int GetGreen() const
Definition PColor.cpp:227
PColor mBackgroundColor
The background color of the widget. if alpha = 0, will not be painted.
Definition PWidget.h:144
void SignalFatalError(const std::string &message)

References PColor::GetAlpha(), PColor::GetBlue(), PColor::GetGreen(), PColor::GetRed(), PWidget::mBackgroundColor, PlatformWidget::mRenderer, PCanvas::mReset, PlatformWidget::mSurface, PlatformWidget::mTexture, PlatformWidget::mTextureHeight, PlatformWidget::mTextureWidth, NULL, and PError::SignalFatalError().

Referenced by Draw(), PlatformCanvas(), PlatformCanvas(), and PlatformCanvas().

◆ SendToStream() [1/2]

std::ostream & PlatformCanvas::SendToStream ( std::ostream &  out) const
protectedvirtual

An inheritable printing class used by PEBLObjectBase::operator<<.

Reimplemented from PlatformWidget.

Definition at line 43 of file validator/PlatformCanvas.cpp.

43 {
44 out << "PlatformCanvas (validator)";
45 return out;
46}

◆ SendToStream() [2/2]

virtual std::ostream & PlatformCanvas::SendToStream ( std::ostream &  out) const
protectedvirtual

An inheritable printing class used by PEBLObjectBase::operator<<.

Reimplemented from PlatformWidget.

◆ SetHeight()

void PlatformCanvas::SetHeight ( pInt  h)
virtual

Reimplemented from PWidget.

Definition at line 285 of file sdl/PlatformCanvas.cpp.

286{
287 mHeight = h;
288 mTextureHeight = h;
290
291}
virtual bool SetProperty(std::string name, Variant v)

References PWidget::mHeight, PlatformWidget::mTextureHeight, and PEBLObjectBase::SetProperty().

◆ SetProperty() [1/2]

virtual bool PlatformCanvas::SetProperty ( std::string  name,
Variant  v 
)
inlinevirtual

Reimplemented from PWidget.

Definition at line 42 of file validator/PlatformCanvas.h.

42 {
43 return PCanvas::SetProperty(name, v);
44 }
virtual bool SetProperty(std::string, Variant v)
Definition PCanvas.cpp:84

References PCanvas::SetProperty().

◆ SetProperty() [2/2]

bool PlatformCanvas::SetProperty ( std::string  name,
Variant  v 
)
virtual

Reimplemented from PWidget.

Definition at line 256 of file sdl/PlatformCanvas.cpp.

257{
258
259 //we need to handle zooming separately
260 if(name == "ZOOMX") SetZoomX((pDouble)v);
261 else if(name=="ZOOMY") SetZoomY((pDouble)v);
262 else return PCanvas::SetProperty(name,v);
263
264 return true;
265}
#define pDouble
Definition Defs.h:7
virtual void SetZoomX(double h)
virtual void SetZoomY(double h)

References pDouble, PCanvas::SetProperty(), SetZoomX(), and SetZoomY().

Referenced by SetZoomX(), and SetZoomY().

◆ SetWidth()

void PlatformCanvas::SetWidth ( pInt  h)
virtual

Reimplemented from PWidget.

Definition at line 293 of file sdl/PlatformCanvas.cpp.

294{
295
296 mWidth = w;
297 mTextureWidth = w;
299
300}

References PlatformWidget::mTextureWidth, PWidget::mWidth, and PEBLObjectBase::SetProperty().

◆ SetZoomX()

void PlatformCanvas::SetZoomX ( double  h)
virtual

Definition at line 302 of file sdl/PlatformCanvas.cpp.

303{
304
305 mZoomX = x;
307 SetProperty("X",mX); //reset X as it matters for images/labels
308 mWidth = (int)(mTextureWidth*mZoomX);
310
311
312}
pDouble mZoomX
Definition PWidget.h:139
pInt mX
Definition PWidget.h:125
virtual bool SetProperty(std::string, Variant v)

References PlatformWidget::mTextureWidth, PWidget::mWidth, PWidget::mX, PWidget::mZoomX, PEBLObjectBase::SetProperty(), and SetProperty().

Referenced by SetProperty().

◆ SetZoomY()

void PlatformCanvas::SetZoomY ( double  h)
virtual

Definition at line 314 of file sdl/PlatformCanvas.cpp.

315{
316
317 mZoomY = y;
319 SetProperty("Y",mY); //reset X as it matters for images/labels
322
323
324}
pInt mY
Definition PWidget.h:125
pDouble mZoomY
Definition PWidget.h:140

References PWidget::mHeight, PlatformWidget::mTextureHeight, PWidget::mY, PWidget::mZoomY, PEBLObjectBase::SetProperty(), and SetProperty().

Referenced by SetProperty().

◆ ValidateProperty() [1/2]

virtual ObjectValidationError PlatformCanvas::ValidateProperty ( std::string  name) const
inlinevirtual

Reimplemented from PWidget.

Definition at line 48 of file validator/PlatformCanvas.h.

48 {
49 return PCanvas::ValidateProperty(name);
50 }
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PCanvas.cpp:128

References PCanvas::ValidateProperty().

◆ ValidateProperty() [2/2]

virtual ObjectValidationError PlatformCanvas::ValidateProperty ( std::string  name,
Variant  v 
) const
inlinevirtual

Reimplemented from PWidget.

Definition at line 45 of file validator/PlatformCanvas.h.

45 {
46 return PCanvas::ValidateProperty(name, v);
47 }

References PCanvas::ValidateProperty().


The documentation for this class was generated from the following files: