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

#include <PWidget.h>

Inheritance diagram for PWidget:
PEBLObjectBase PCanvas PDrawObject PImageBox PMovie PTextObject PWindow PlatformWidget PlatformWidget

Public Member Functions

 PWidget ()
 
 PWidget (const PWidget &pw)
 
 PWidget (pInt x, pInt y, pInt width, pInt height, bool visible)
 
virtual ~PWidget ()
 
virtual bool SetProperty (std::string, Variant v)
 
virtual Variant GetProperty (std::string) const
 
virtual ObjectValidationError ValidateProperty (std::string, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string) const
 
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)
 
virtual void SetParent (PWidget *widget)
 This unconditionally sets the parent widget.
 
virtual PWidgetGetParent ()
 
virtual bool IsParent (PWidget *parent)
 
virtual bool Draw ()
 
virtual void SetPosition (pInt x, pInt y)
 This sets the widget's position on its parent widget.
 
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 void SetWidth (pInt w)
 
virtual void SetHeight (pInt h)
 
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 RemoveSubWidgets ()
 
virtual bool RemoveLastSubWidget ()
 This is probably pretty useless.
 
virtual void Show ()
 
virtual void Hide ()
 
virtual bool IsVisible () const
 
virtual std::string ObjectName () 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 ()
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 An inheritable printing class used by PEBLObjectBase::operator<<.
 

Protected Attributes

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
 

Detailed Description

This class is the main visual gui base class. It is an abstract class, containing methods that need to be overriden by an inherited class (i.e., Platform*) to be used.

Definition at line 42 of file PWidget.h.

Constructor & Destructor Documentation

◆ PWidget() [1/3]

PWidget::PWidget ( )

Definition at line 37 of file PWidget.cpp.

37 :
38 mX(0),
39 mY(0),
40 mDrawX(0),
41 mDrawY(0),
42 mWidth(0),
43 mHeight(0),
44 mZoomX(1),
45 mZoomY(1),
46 mRotation(0),
47 mBackgroundColor(PColor(0,0,0,0)),
48 mIsVisible(true),
50{
51 // InitializeProperty("NAME",Variant(""));
60 InitializeProperty("PARENT",Variant(0));
61
62}
#define NULL
Definition BinReloc.cpp:317
virtual bool InitializeProperty(std::string name, Variant v)
pInt mDrawX
Definition PWidget.h:129
pDouble mZoomX
Definition PWidget.h:139
pInt mWidth
Definition PWidget.h:136
PColor mBackgroundColor
The background color of the widget. if alpha = 0, will not be painted.
Definition PWidget.h:144
pInt mX
Definition PWidget.h:125
pInt mHeight
Definition PWidget.h:136
pInt mY
Definition PWidget.h:125
pDouble mZoomY
Definition PWidget.h:140
PWidget * mParent
Definition PWidget.h:154
pInt mDrawY
Definition PWidget.h:130
bool mIsVisible
Definition PWidget.h:150
pDouble mRotation
Definition PWidget.h:141

References PEBLObjectBase::InitializeProperty(), mHeight, mIsVisible, mRotation, mWidth, mX, mY, mZoomX, and mZoomY.

◆ PWidget() [2/3]

PWidget::PWidget ( const PWidget pw)

Definition at line 91 of file PWidget.cpp.

91 :
92 PWidget(pw.GetX(),
93 pw.GetY(),
94 pw.GetWidth(),
95 pw.GetHeight(),
96 pw.IsVisible())
97{
98 // InitializeProperty("NAME",Variant(""));
107 InitializeProperty("PARENT",Variant(0));
108
109}
virtual pInt GetX() const
Definition PWidget.h:82
PWidget()
Definition PWidget.cpp:37
virtual pInt GetWidth() const
Definition PWidget.h:85
virtual pInt GetHeight() const
Definition PWidget.h:86
virtual pInt GetY() const
Definition PWidget.h:83
virtual bool IsVisible() const
Definition PWidget.h:113

References PEBLObjectBase::InitializeProperty(), mHeight, mIsVisible, mRotation, mWidth, mX, mY, mZoomX, and mZoomY.

◆ PWidget() [3/3]

PWidget::PWidget ( pInt  x,
pInt  y,
pInt  width,
pInt  height,
bool  visible 
)

Definition at line 64 of file PWidget.cpp.

64 :
65 mX(x),
66 mY(y),
67 mDrawX(x),
68 mDrawY(y),
69 mWidth(width),
70 mHeight(height),
71 mZoomX(1.0),
72 mZoomY(1.0),
73 mRotation(0),
74 mBackgroundColor(PColor(0,0,0,0)),
75 mIsVisible(visible),
77{
78 // InitializeProperty("NAME",Variant(""));
87 InitializeProperty("PARENT",Variant(0));
88
89}

References PEBLObjectBase::InitializeProperty(), mHeight, mIsVisible, mRotation, mWidth, mX, mY, mZoomX, and mZoomY.

◆ ~PWidget()

PWidget::~PWidget ( )
virtual

Definition at line 111 of file PWidget.cpp.

112{
113
114
115
116}

Member Function Documentation

◆ AddSubWidget()

bool PWidget::AddSubWidget ( PWidget widget)
virtual

AddSubWidget takes care of adding a widget to a current parent widget, and setting the parent field of the child widget to the parent widget.

Definition at line 330 of file PWidget.cpp.

331{
332
333
334 //remove the subwidget from wherever it was:
335 PWidget* p = widget->GetParent();
336 if(p)
337 {
338
339 p->RemoveSubWidget(widget);
340 }
341
342 widget->SetParent(NULL);
343
344
345
346 //now, add it back on:
347 mSubWidgets.push_front(widget);
348 widget->SetParent(this);
349
350 return true;
351}
std::list< PWidget * > mSubWidgets
Definition PWidget.h:147
virtual PWidget * GetParent()
Definition PWidget.h:63
virtual bool RemoveSubWidget(PWidget *widget)
Definition PWidget.cpp:375
virtual void SetParent(PWidget *widget)
This unconditionally sets the parent widget.
Definition PWidget.cpp:315

References GetParent(), mSubWidgets, NULL, RemoveSubWidget(), and SetParent().

Referenced by PlatformWidget::AddSubWidget().

◆ Draw()

◆ GetBackgroundColor()

virtual PColor PWidget::GetBackgroundColor ( )
inlinevirtual

Definition at line 92 of file PWidget.h.

92{return mBackgroundColor;};

References mBackgroundColor.

Referenced by PlatformTextBox::Draw(), and PlatformTextBox::SetFont().

◆ GetHeight()

◆ GetParent()

virtual PWidget * PWidget::GetParent ( )
inlinevirtual

Definition at line 63 of file PWidget.h.

63{return mParent;}

References mParent.

Referenced by AddSubWidget(), PEBLObjects::GetParent(), and IsParent().

◆ GetPixel()

PColor PWidget::GetPixel ( pInt  x,
pInt  y 
)
virtual

Reimplemented in PlatformWidget.

Definition at line 133 of file PWidget.cpp.

134{
135 //This should go straight to PlatforwWidget::GetPixel
136
137 return false;
138}

◆ GetProperty()

Variant PWidget::GetProperty ( std::string  name) const
virtual

Reimplemented in PlatformTextBox, PCanvas, PDrawObject, PLine, PThickLine, PRectangle, PSquare, PEllipse, PCircle, PPolygon, PBezier, PImageBox, PLabel, PMovie, PTextBox, PTextObject, and PWindow.

Definition at line 181 of file PWidget.cpp.

182{
183 return PEBLObjectBase::GetProperty(name);
184}
Variant GetProperty(std::string) const

References PEBLObjectBase::GetProperty().

Referenced by PCanvas::GetProperty().

◆ GetWidth()

◆ GetX()

virtual pInt PWidget::GetX ( ) const
inlinevirtual

Definition at line 82 of file PWidget.h.

82{return mX;};

References mX.

Referenced by SDLUtility::DrawPixel().

◆ GetY()

virtual pInt PWidget::GetY ( ) const
inlinevirtual

Definition at line 83 of file PWidget.h.

83{return mY;};

References mY.

Referenced by SDLUtility::DrawPixel().

◆ Hide()

void PWidget::Hide ( )
virtual

Definition at line 402 of file PWidget.cpp.

403{
404 mIsVisible = false;
406}
virtual bool SetProperty(std::string name, Variant v)

References mIsVisible, and PEBLObjectBase::SetProperty().

Referenced by PEBLObjects::Hide(), PImageBox::SetProperty(), PMovie::SetProperty(), and SetProperty().

◆ IsParent()

bool PWidget::IsParent ( PWidget parent)
virtual

Definition at line 323 of file PWidget.cpp.

324{
325
326 return testparent == GetParent();
327}

References GetParent().

Referenced by PEBLObjects::RemoveObject().

◆ IsVisible()

virtual bool PWidget::IsVisible ( ) const
inlinevirtual

Definition at line 113 of file PWidget.h.

113{return mIsVisible;}

References mIsVisible.

Referenced by PlatformWidget::Draw().

◆ ObjectName()

◆ RemoveLastSubWidget()

bool PWidget::RemoveLastSubWidget ( )
virtual

This is probably pretty useless.

Definition at line 388 of file PWidget.cpp.

389{
390
391 mSubWidgets.pop_front();
392 return true;
393}

References mSubWidgets.

◆ RemoveSubWidget()

bool PWidget::RemoveSubWidget ( PWidget widget)
virtual

This method iterates through the subwidgets and sees if any are equal to the argument. If so, it removes it. It does not delete it.

Definition at line 375 of file PWidget.cpp.

376{
377
378
379
380
381 mSubWidgets.remove(widget);
382 mSubWidgets.remove(dynamic_cast<PlatformWidget*>(widget));
383 widget->SetParent(NULL);
384
385 return true;
386}

References mSubWidgets, NULL, and SetParent().

Referenced by AddSubWidget(), PlatformWidget::RemoveSubWidget(), and PlatformWidget::~PlatformWidget().

◆ RemoveSubWidgets()

bool PWidget::RemoveSubWidgets ( )
virtual

Reimplemented in PlatformWidget.

Definition at line 353 of file PWidget.cpp.

355{
356
357 if(mSubWidgets.size()>0)
358 {
359
360 std::list<PWidget*>::iterator i = mSubWidgets.begin();
361 while(i != mSubWidgets.end())
362 {
363
364 (*i)->SetParent(NULL);
365 mSubWidgets.pop_front();
366 i=mSubWidgets.begin(); //readjust so it points to the start of the list.
367 }
368
369 mSubWidgets.clear();
370 }
371 return true;
372}

References mSubWidgets, and NULL.

◆ RotoZoom()

bool PWidget::RotoZoom ( pDouble  angle,
pDouble  zoomx,
pDouble  zoomy,
pInt  smooth 
)
virtual

Reimplemented in PlatformWidget.

Definition at line 118 of file PWidget.cpp.

119{
120
121 return false;
122}

◆ SendToStream()

◆ SetBackgroundColor()

void PWidget::SetBackgroundColor ( const PColor color)
virtual

Reimplemented in PlatformWindow.

Definition at line 287 of file PWidget.cpp.

288{
289
290 PColor * pc = new PColor(color);
292 PComplexData * pcd = new PComplexData(pob);
293 Variant col = Variant(pcd);
294
295
296 PEBLObjectBase::SetProperty("BGCOLOR",col);
297
298 PColor pc2 = PColor(color.GetRed(),color.GetGreen(),color.GetBlue(),color.GetAlpha());
299 //PColor(col);
300
305
306
307 // InitializeProperty("BGCOLOR", col);
308
309}
void SetRed(int color)
Definition PColor.cpp:197
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
void SetGreen(int color)
Definition PColor.cpp:204
void SetBlue(int color)
Definition PColor.cpp:211
void SetAlpha(int color)
Definition PColor.cpp:218

References PColor::GetAlpha(), PColor::GetBlue(), PColor::GetGreen(), PColor::GetRed(), mBackgroundColor, PColor::SetAlpha(), PColor::SetBlue(), PColor::SetGreen(), PEBLObjectBase::SetProperty(), and PColor::SetRed().

Referenced by PlatformTextBox::Draw(), PlatformWindow::PlatformWindow(), PlatformWindow::SetBackgroundColor(), PCanvas::SetColor(), PlatformTextBox::SetFont(), and SetProperty().

◆ SetHeight()

void PWidget::SetHeight ( pInt  h)
virtual

Reimplemented in PlatformCanvas.

Definition at line 258 of file PWidget.cpp.

259{
260 mHeight = h;
262
263}

References mHeight, and PEBLObjectBase::SetProperty().

Referenced by SetProperty().

◆ SetParent()

void PWidget::SetParent ( PWidget widget)
virtual

This unconditionally sets the parent widget.

Definition at line 315 of file PWidget.cpp.

316{
317
318 PEBLObjectBase::SetProperty("PARENT",widget);
319 mParent = widget;
320}

References mParent, and PEBLObjectBase::SetProperty().

Referenced by AddSubWidget(), RemoveSubWidget(), and PlatformWidget::SetParent().

◆ SetPoint()

bool PWidget::SetPoint ( pInt  x,
pInt  y,
PColor  col 
)
virtual

Reimplemented in PlatformWidget.

Definition at line 125 of file PWidget.cpp.

126{
127 //This should go straight to PlatforwWidget::SetPoint
128
129 return false;
130}

◆ SetPosition()

◆ SetProperty()

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

Reimplemented from PEBLObjectBase.

Reimplemented in PlatformCanvas, PlatformLine, PlatformThickLine, PlatformRectangle, PlatformSquare, PlatformEllipse, PlatformCircle, PlatformPolygon, PlatformBezier, PlatformImageBox, PlatformLabel, PlatformTextBox, PlatformWindow, PCanvas, PDrawObject, PLine, PThickLine, PRectangle, PSquare, PEllipse, PCircle, PPolygon, PBezier, PImageBox, PLabel, PMovie, PTextBox, PTextObject, PWindow, PlatformCanvas, PlatformLabel, and PlatformTextBox.

Definition at line 142 of file PWidget.cpp.

143{
145 if(err == OVE_SUCCESS)
146 {
147 if (name == "X") SetPosition(v,mY);
148 else if (name == "Y") SetPosition(mX,v);
149 else if (name == "ZOOMX") SetZoomX(( pDouble)v);
150 else if (name == "ZOOMY") SetZoomY(( pDouble)v);
151 else if (name == "ROTATION") SetRotation(( pDouble)v);
152 else if (name == "WIDTH") SetWidth((pInt)v);
153 else if (name == "HEIGHT") SetHeight((pInt)v);
154 else if (name == "BGCOLOR")
155 {
156 PColor bgcolor = *((PColor*)(v.GetComplexData()->GetObject().get()));
157 SetBackgroundColor(bgcolor);
158 }
159 else if (name == "VISIBLE")
160 {
161 if(v.GetInteger())
162 Show();
163 else
164 Hide();
165 }else if (name=="PARENT")
166 {
167
168 PEBLObjectBase::SetProperty("PARENT",v);
169 }
170 else return false;
171 }
172 else
173 {
174 PError::SignalFatalError("Failing to set invalid property: ["+ name +"]" );
175 return false;
176 }
177 return false;
178}
#define pInt
Definition Defs.h:8
#define pDouble
Definition Defs.h:7
ObjectValidationError
Definition PEBLObject.h:37
@ OVE_SUCCESS
Definition PEBLObject.h:38
counted_ptr< PEBLObjectBase > GetObject() const
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PWidget.cpp:188
virtual void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
Definition PWidget.cpp:220
virtual void Show()
Definition PWidget.cpp:396
virtual void SetBackgroundColor(const PColor &color)
Definition PWidget.cpp:287
virtual void SetWidth(pInt w)
Definition PWidget.cpp:265
virtual void SetZoomX(pDouble x)
This sets the widget's position on its parent widget.
Definition PWidget.cpp:236
virtual void SetZoomY(pDouble x)
This sets the widget's position on its parent widget.
Definition PWidget.cpp:247
virtual void SetHeight(pInt h)
Definition PWidget.cpp:258
virtual void Hide()
Definition PWidget.cpp:402
virtual void SetRotation(pDouble x)
This sets the widget's position on its parent widget.
Definition PWidget.cpp:273
pInt GetInteger() const
Definition Variant.cpp:997
PComplexData * GetComplexData() const
Definition Variant.cpp:1299
X * get() const
Definition rc_ptrs.h:110
void SignalFatalError(const std::string &message)

References Hide(), mX, mY, OVE_SUCCESS, pDouble, pInt, SetBackgroundColor(), SetHeight(), SetPosition(), PEBLObjectBase::SetProperty(), SetRotation(), SetWidth(), SetZoomX(), SetZoomY(), Show(), PError::SignalFatalError(), and ValidateProperty().

Referenced by PEBLObjects::AddObject(), PlatformWidget::Draw(), PlatformWindow::Initialize(), PlatformImageBox::LoadImage(), PlatformWidget::RotoZoom(), PCanvas::SetProperty(), PDrawObject::SetProperty(), PImageBox::SetProperty(), PMovie::SetProperty(), PTextObject::SetProperty(), PWindow::SetProperty(), SetZoomX(), and SetZoomY().

◆ SetRotation()

void PWidget::SetRotation ( pDouble  x)
virtual

This sets the widget's position on its parent widget.

Definition at line 273 of file PWidget.cpp.

274{
275 mRotation = x;
276 PEBLObjectBase::SetProperty("ROTATION",x);
277}

References mRotation, and PEBLObjectBase::SetProperty().

Referenced by SetProperty().

◆ SetWidth()

void PWidget::SetWidth ( pInt  w)
virtual

Reimplemented in PlatformCanvas.

Definition at line 265 of file PWidget.cpp.

266{
267 mWidth = w;
269
270}

References mWidth, and PEBLObjectBase::SetProperty().

Referenced by SetProperty().

◆ SetZoomX()

void PWidget::SetZoomX ( pDouble  x)
virtual

This sets the widget's position on its parent widget.

Reimplemented in PlatformImageBox.

Definition at line 236 of file PWidget.cpp.

237{
238
239 mZoomX = x;
241 SetProperty("X",mX); //reset X as it matters for images/labels
242 //SetProperty("WIDTH",(int)(mWidth*mZoomX));
243}
virtual bool SetProperty(std::string, Variant v)
Definition PWidget.cpp:142

References mX, mZoomX, PEBLObjectBase::SetProperty(), and SetProperty().

Referenced by PImageBox::SetProperty(), and SetProperty().

◆ SetZoomY()

void PWidget::SetZoomY ( pDouble  x)
virtual

This sets the widget's position on its parent widget.

Reimplemented in PlatformImageBox.

Definition at line 247 of file PWidget.cpp.

248{
249
250 mZoomY = y;
252 SetProperty("Y",mY);//reset y as it matters for images/labels
253 //SetProperty("HEIGHT",(int)(mHeight*mZoomY));
254}

References mY, mZoomY, PEBLObjectBase::SetProperty(), and SetProperty().

Referenced by PImageBox::SetProperty(), and SetProperty().

◆ Show()

void PWidget::Show ( )
virtual

These change the visibility state. If invisible, the widget gets skipped over when drawn.

Definition at line 396 of file PWidget.cpp.

397{
398 mIsVisible = true;
400
401}

References mIsVisible, and PEBLObjectBase::SetProperty().

Referenced by PImageBox::SetProperty(), PMovie::SetProperty(), SetProperty(), and PEBLObjects::Show().

◆ ValidateProperty() [1/2]

ObjectValidationError PWidget::ValidateProperty ( std::string  name) const
virtual

Reimplemented from PEBLObjectBase.

Reimplemented in PlatformCanvas, PlatformLine, PlatformThickLine, PlatformRectangle, PlatformSquare, PlatformEllipse, PlatformCircle, PlatformPolygon, PlatformBezier, PlatformImageBox, PlatformLabel, PlatformTextBox, PlatformWindow, PCanvas, PDrawObject, PLine, PThickLine, PRectangle, PSquare, PEllipse, PCircle, PPolygon, PBezier, PImageBox, PLabel, PMovie, PTextBox, PTextObject, and PWindow.

Definition at line 194 of file PWidget.cpp.

195{
196
197
198 //This only returns valid for properties that are valid to widgets
199 //in general--subclasses need to check on their own.
200 if(name == "X" ||
201 name == "Y" ||
202 name == "VISIBLE" ||
203 name == "WIDTH" ||
204 name == "HEIGHT" ||
205 name == "ZOOMX" ||
206 name == "ZOOMY" ||
207 name == "BGCOLOR" ||
208 name == "ROTATION" ||
209 name == "NAME"||
210 name=="PARENT"
211 )
212 return OVE_VALID;
213 else
215}
@ OVE_INVALID_PROPERTY_NAME
Definition PEBLObject.h:40
@ OVE_VALID
Definition PEBLObject.h:39

References OVE_INVALID_PROPERTY_NAME, and OVE_VALID.

◆ ValidateProperty() [2/2]

Member Data Documentation

◆ mBackgroundColor

PColor PWidget::mBackgroundColor
protected

The background color of the widget. if alpha = 0, will not be painted.

Definition at line 144 of file PWidget.h.

Referenced by PlatformWindow::Draw(), GetBackgroundColor(), PlatformCanvas::Reset(), and SetBackgroundColor().

◆ mDrawX

◆ mDrawY

◆ mHeight

◆ mIsVisible

◆ mParent

◆ mRotation

pDouble PWidget::mRotation
protected

◆ mSubWidgets

◆ mWidth

◆ mX

◆ mY

◆ mZoomX

◆ mZoomY


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