PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PImageBox.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/objects/PImageBox.cpp
4// Purpose: Contains generic specification for a imagebox class.
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
28#include "PImageBox.h"
29#include <iostream>
30
31using std::cout;
32
34 PWidget()
35{
36 InitializeProperty("NAME",Variant("<IMAGEBOX>"));
37 __SetProps__();
38
39}
40
45{
46
47
48 //mx/my is the specified position.
49 mX = x;
50 mY = y;
51 // PWidget::SetPosition(x,y);
52 //mdrawxy is the drawn upper-left corner position.
53 mDrawX = x - GetWidth()/2;
54 mDrawY = y - GetHeight()/2;
55
58
59}
60
61void PImageBox::SetSize(int width, int height)
62{
63
64
65 mWidth = width;
66 mHeight = height;
67
68 PEBLObjectBase::SetProperty("WIDTH",width);
69 PEBLObjectBase::SetProperty("HEIGHT",height);
70 //Reset position so it gets centered correctly.
72}
73
74
75
76
77
78//overloaded generic PEBLObjectBase methods
79bool PImageBox::SetProperty(std::string name, Variant v)
80{
81
82
83 //Width and height are not currently 'settable', in that
84 //they are properties of the object.
85
86 if(name == "X") SetPosition(v,mY);
87 else if (name == "Y") SetPosition(mX,v);
88 else if (name == "HEIGHT") SetSize((int)mWidth,v);
89 else if (name == "WIDTH") SetSize(v,(int)mHeight);
90 else if (name =="ZOOMX") SetZoomX(v);
91 else if (name =="ZOOMY") SetZoomY(v);
92 else if (name == "VISIBLE")
93 {
94 if(v.GetInteger())
95 Show();
96 else
97 Hide();
98 }
99
100
101 else return PWidget::SetProperty(name,v);
102
103 return true;
104}
105
106
107Variant PImageBox::GetProperty(std::string name)const
108{
109
110 //PEBLObjectBase::PrintProperties(cout);
111 return PEBLObjectBase::GetProperty(name);
112}
113
114
116{
117
118 return ValidateProperty(name);
119}
120
122{
123 //All valid properties are also valid Widget properties
125 if(ove == OVE_VALID)
126 {
127 return ove;
128 }
129 else if(name =="WIDTH" ||
130 name == "HEIGHT")
131 return OVE_VALID;
132 else
133
135}
136
137
138
139//This makes sure that the object properties are synced with the class properties.
140void PImageBox::__SetProps__()
141{
142
143 SetProperty("X",mX);
144 SetProperty("Y",mY);
145 SetProperty("VISIBLE",mIsVisible);
146 SetProperty("WIDTH",mWidth);
147 SetProperty("HEIGHT",mHeight);
148 SetProperty("ZOOMX",mZoomX);
149 SetProperty("ZOOMY",mZoomY);
150 SetProperty("ROTATION",mRotation);
151
152}
#define pInt
Definition Defs.h:8
ObjectValidationError
Definition PEBLObject.h:37
@ OVE_INVALID_PROPERTY_NAME
Definition PEBLObject.h:40
@ OVE_VALID
Definition PEBLObject.h:39
virtual bool InitializeProperty(std::string name, Variant v)
virtual bool SetProperty(std::string name, Variant v)
Variant GetProperty(std::string) const
virtual void SetSize(int width, int height)
Definition PImageBox.cpp:61
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
virtual void SetPosition(pInt x, pInt y)
Definition PImageBox.cpp:44
virtual Variant GetProperty(std::string) const
virtual bool SetProperty(std::string, Variant v)
Definition PImageBox.cpp:79
pInt mDrawX
Definition PWidget.h:129
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PWidget.cpp:188
virtual pInt GetWidth() const
Definition PWidget.h:85
virtual void Show()
Definition PWidget.cpp:396
virtual pInt GetHeight() const
Definition PWidget.h:86
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
pDouble mZoomX
Definition PWidget.h:139
virtual bool SetProperty(std::string, Variant v)
Definition PWidget.cpp:142
pInt mWidth
Definition PWidget.h:136
pInt mX
Definition PWidget.h:125
pInt mHeight
Definition PWidget.h:136
virtual void Hide()
Definition PWidget.cpp:402
pInt mY
Definition PWidget.h:125
pDouble mZoomY
Definition PWidget.h:140
pInt mDrawY
Definition PWidget.h:130
bool mIsVisible
Definition PWidget.h:150
pDouble mRotation
Definition PWidget.h:141
pInt GetInteger() const
Definition Variant.cpp:997