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

Validator platform image box - no image loading, used only for compilation. More...

#include <PlatformImageBox.h>

Inheritance diagram for PlatformImageBox:
PImageBox PlatformWidget PlatformWidget PImageBox PWidget PWidget PWidget PWidget PWidget PWidget PEBLObjectBase PEBLObjectBase PEBLObjectBase PEBLObjectBase PEBLObjectBase PEBLObjectBase

Public Member Functions

 PlatformImageBox ()
 Standard Constructor.
 
virtual ~PlatformImageBox ()
 Standard Destructor.
 
virtual bool LoadImage (const std::string &imagefilename)
 
virtual bool Draw ()
 
virtual std::string ObjectName () const
 
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.
 
 PlatformImageBox ()
 
 PlatformImageBox (const std::string &filename)
 
virtual ~PlatformImageBox ()
 
virtual bool LoadImage (const std::string &imagefilename)
 
virtual bool Draw ()
 
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 PImageBox
 PImageBox ()
 
virtual ~PImageBox ()
 
virtual Variant GetProperty (std::string) const
 
virtual void SetPosition (pInt x, pInt y)
 
virtual void SetSize (int width, int height)
 
- 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 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 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 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)
 

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.
 

Protected Attributes

bool mTextureCreated
 
- 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 PlatformWidget
pInt mTextureWidth
 
pInt mTextureHeight
 
bool mNeedsTexture
 
SDL_Texture * mTexture
 
SDL_Surface * mSurface
 
SDL_Renderer * mRenderer
 

Detailed Description

Validator platform image box - no image loading, used only for compilation.

Definition at line 50 of file sdl/PlatformImageBox.h.

Constructor & Destructor Documentation

◆ PlatformImageBox() [1/3]

PlatformImageBox::PlatformImageBox ( )

Standard Constructor.

Definition at line 61 of file sdl/PlatformImageBox.cpp.

61 :
62 PImageBox()
63
64{
66 mTexture = NULL;
67 mSurface = NULL;
69 mTextureCreated = false;
70 mNeedsTexture = true;
71}
#define NULL
Definition BinReloc.cpp:317
@ CDT_IMAGEBOX
Definition PEBLObject.h:53
ComplexDataType mCDT
Definition PEBLObject.h:109
SDL_Surface * mSurface
SDL_Texture * mTexture
SDL_Renderer * mRenderer

References CDT_IMAGEBOX, PEBLObjectBase::mCDT, PlatformWidget::mNeedsTexture, PlatformWidget::mRenderer, PlatformWidget::mSurface, PlatformWidget::mTexture, mTextureCreated, and NULL.

◆ ~PlatformImageBox() [1/2]

PlatformImageBox::~PlatformImageBox ( )
virtual

Standard Destructor.

Definition at line 76 of file sdl/PlatformImageBox.cpp.

77{
78
79}

◆ PlatformImageBox() [2/3]

PlatformImageBox::PlatformImageBox ( )

◆ PlatformImageBox() [3/3]

PlatformImageBox::PlatformImageBox ( const std::string &  filename)

Definition at line 33 of file validator/PlatformImageBox.cpp.

33 : PImageBox() {
34 LoadImage(filename);
35}
virtual bool LoadImage(const std::string &imagefilename)

References LoadImage().

◆ ~PlatformImageBox() [2/2]

virtual PlatformImageBox::~PlatformImageBox ( )
virtual

Member Function Documentation

◆ Draw() [1/2]

bool PlatformImageBox::Draw ( )
virtual

This draws the subwidgets. It doesn't need a 'parent' argument, because 'this' is it.

Reimplemented from PWidget.

Definition at line 161 of file sdl/PlatformImageBox.cpp.

162{
163
164 if(mRenderer)
165 {
166
167 if(!mTexture)
168 {
169
170 mTexture = SDL_CreateTextureFromSurface(mRenderer, mSurface);
171 mTextureCreated = true;
172
173 }
174 else
175 {
176 //In this case, a texture already exists...
177
178 }
179 } else {
180
181 }
182 int out = PlatformWidget::Draw();
183 return out==0;
184}
virtual bool Draw()
This method initiates everything needed to display the main window

References PlatformWidget::Draw(), PlatformWidget::mRenderer, PlatformWidget::mSurface, PlatformWidget::mTexture, and mTextureCreated.

◆ Draw() [2/2]

virtual bool PlatformImageBox::Draw ( )
virtual

This draws the subwidgets. It doesn't need a 'parent' argument, because 'this' is it.

Reimplemented from PWidget.

◆ LoadImage() [1/2]

bool PlatformImageBox::LoadImage ( const std::string &  imagefilename)
virtual

This will load a file into the class data, given a file name. height and width are set automatically.

Implements PImageBox.

Definition at line 97 of file sdl/PlatformImageBox.cpp.

98{
99
100
101 //Check to see if we can find the image; if not, call everything off.
102 string filename = Evaluator::gPath.FindFile(imagefilename);
103
104 if(filename == "")
105 PError::SignalFatalError(string("Unable to find image file [") +
106 imagefilename + string("]."));
107
108
109
110 //This uses the SDL_image library to load a variety of
111 //image types.
112
113 //If the SDL_image library is being used, we can handle many different types
114 //of images. If it isn't, use SDL's built-in bmp loader.
115#ifdef PEBL_EMSCRIPTENX
116
117 mSurface = SDL_LoadBMP(filename.c_str());
118#else
119
120#ifdef SDL_IMAGE
121 mSurface = IMG_Load(filename.c_str());
122#else
123 mSurface = SDL_LoadBMP(filename.c_str());
124#endif
125
126#endif
127
128 //Now, set the height and width to be the same as the
129 //initial image.
130
131 if(mSurface)
132 {
133
134 mWidth = mSurface->w;
135 mHeight = mSurface->h;
138
139 //These need to be set at the PWidget level because
140 //they are not mutable at the imagebox level.
143 return true;
144 }
145 else
146 {
147
148 PWidget::SetProperty("WIDTH", 0);
149 PWidget::SetProperty("HEIGHT", 0);
150
151
152 PError::SignalFatalError(string("Image not created.[") +
153 imagefilename + string("].") +
154 string(IMG_GetError()));
155 return false;
156 }
157}
static PEBLPath gPath
std::string FindFile(const string &filename)
Definition PEBLPath.cpp:368
virtual bool SetProperty(std::string, Variant v)
Definition PImageBox.cpp:79
virtual bool SetProperty(std::string, Variant v)
Definition PWidget.cpp:142
pInt mWidth
Definition PWidget.h:136
pInt mHeight
Definition PWidget.h:136
void SignalFatalError(const std::string &message)

References PEBLPath::FindFile(), Evaluator::gPath, PWidget::mHeight, PlatformWidget::mSurface, PlatformWidget::mTextureHeight, PlatformWidget::mTextureWidth, PWidget::mWidth, PImageBox::SetProperty(), PWidget::SetProperty(), and PError::SignalFatalError().

Referenced by main(), PEBLObjects::MakeImage(), and PlatformImageBox().

◆ LoadImage() [2/2]

virtual bool PlatformImageBox::LoadImage ( const std::string &  imagefilename)
virtual

This will load a file into the class data, given a file name. height and width are set automatically.

Implements PImageBox.

◆ ObjectName() [1/2]

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

Reimplemented from PImageBox.

Definition at line 61 of file sdl/PlatformImageBox.h.

61{return "PlatformImageBox\n";};

◆ ObjectName() [2/2]

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

Reimplemented from PImageBox.

Definition at line 40 of file validator/PlatformImageBox.h.

40{ return "PlatformImageBox (validator)"; }

◆ SendToStream() [1/2]

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

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

Reimplemented from PImageBox.

Definition at line 53 of file validator/PlatformImageBox.cpp.

53 {
54 out << "PlatformImageBox (validator)";
55 return out;
56}

◆ SendToStream() [2/2]

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

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

Reimplemented from PImageBox.

◆ SetProperty()

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

Reimplemented from PImageBox.

Definition at line 43 of file validator/PlatformImageBox.h.

43 {
44 return PImageBox::SetProperty(name, v);
45 }

References PImageBox::SetProperty().

Referenced by SetZoomX(), and SetZoomY().

◆ SetZoomX()

void PlatformImageBox::SetZoomX ( pDouble  x)
virtual

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

Reimplemented from PWidget.

Definition at line 188 of file sdl/PlatformImageBox.cpp.

189{
190
191 mZoomX = x;
193 SetProperty("X",mX); //reset X as it matters for images/labels
194 SetProperty("WIDTH",(int)(mTextureWidth*mZoomX));
195}
virtual bool SetProperty(std::string name, Variant v)
pDouble mZoomX
Definition PWidget.h:139
pInt mX
Definition PWidget.h:125
virtual bool SetProperty(std::string name, Variant v)

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

◆ SetZoomY()

void PlatformImageBox::SetZoomY ( pDouble  x)
virtual

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

Reimplemented from PWidget.

Definition at line 198 of file sdl/PlatformImageBox.cpp.

199{
200
201 mZoomY = y;
203 SetProperty("Y",mY);//reset y as it matters for images/labels
204 SetProperty("HEIGHT",(int)(mTextureHeight*mZoomY));
205}
pInt mY
Definition PWidget.h:125
pDouble mZoomY
Definition PWidget.h:140

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

◆ ValidateProperty() [1/2]

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

Reimplemented from PImageBox.

Definition at line 49 of file validator/PlatformImageBox.h.

49 {
50 return PImageBox::ValidateProperty(name);
51 }
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const

References PImageBox::ValidateProperty().

◆ ValidateProperty() [2/2]

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

Reimplemented from PImageBox.

Definition at line 46 of file validator/PlatformImageBox.h.

46 {
47 return PImageBox::ValidateProperty(name, v);
48 }

References PImageBox::ValidateProperty().

Member Data Documentation

◆ mTextureCreated

bool PlatformImageBox::mTextureCreated
protected

Definition at line 66 of file sdl/PlatformImageBox.h.

Referenced by Draw(), and PlatformImageBox().


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