PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PCanvas.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/PCanvas.cpp
4// Purpose: Contains generic canvas.
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2010-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 "PCanvas.h"
29#include "PColor.h"
30#include "../utility/rc_ptrs.h"
31#include "../utility/PEBLUtility.h"
32#include "../base/PComplexData.h"
33
34#include <iostream>
35
36using std::cout;
37using std::endl;
38
40{
41 InitializeProperty("WIDTH",Variant(0));
42 InitializeProperty("HEIGHT",Variant(0));
43 InitializeProperty("NAME",Variant("<CANVAS>"));
44
45 mReset = false;
46}
47
48
49
50PCanvas::PCanvas(int width, int height, Variant pcol):
51 PWidget(0,0,0,0,false)
52{
53 InitializeProperty("WIDTH",Variant(width));
54 InitializeProperty("HEIGHT",Variant(height));
55 InitializeProperty("NAME",Variant("<CANVAS>"));
56 InitializeProperty("BGCOLOR",pcol);
57
58 SetHeight(height);
59 SetWidth(width);
60 mReset = false;
61 mDrawBackground = true;
62}
63
64PCanvas::PCanvas(int width, int height):
65 PWidget(0,0,0,0,false)
66{
67 InitializeProperty("WIDTH",Variant(width));
68 InitializeProperty("HEIGHT",Variant(height));
69 InitializeProperty("NAME",Variant("<CANVAS>"));
70
71 SetHeight(height);
72 SetWidth(width);
73 mReset = false;
74 mDrawBackground = false;
75
76}
77
78
82
83
84bool PCanvas::SetProperty(std::string name, Variant v)
85{
86
87 if(PWidget::SetProperty(name,v))
88 {
89 // If we set it at higher level, don't worry.
90 }
91 else if (name =="WIDTH") SetWidth(v);
92 else if(name == "HEIGHT") SetHeight(v);
93 else if (name == "BGCOLOR") SetColor(v);
94 else return false;
95
96 return true;
97}
98
99
100// Position of canvas is specified as its center
101//
103{
104 mX = x;
105 mY = y;
106 mDrawX = x - GetWidth()/2;
107 mDrawY = y - GetHeight()/2;
110}
111
113{
114
115 PEBLObjectBase::SetProperty("BGCOLOR",col);
117
118 //mBackgroundColor = *dynamic_cast<PColor*>(col.GetComplexData()->GetObject().get());
119 mReset = true;
120}
121
122Variant PCanvas::GetProperty(std::string name)const
123{
124 return PWidget::GetProperty(name);
125}
126
127
129{
130 return ValidateProperty(name);
131}
132
134{
135
136 return PWidget::ValidateProperty(name);
137}
138
139
140
141
142
143//These shadow higher accessors in widget, because
144//they need to set the textchanged flag
146{
147
148
149 mHeight = h;
150 mReset = true;
151}
152
154{
155
156 mWidth = w;
157 mReset = true;
158}
159
160
161
162std::string PCanvas::ObjectName()const
163{
164 return "Canvas";
165}
#define pInt
Definition Defs.h:8
ObjectValidationError
Definition PEBLObject.h:37
virtual ~PCanvas()
Definition PCanvas.cpp:79
virtual void SetWidth(int w)
Definition PCanvas.cpp:153
bool mReset
Definition PCanvas.h:67
virtual void SetColor(Variant col)
Definition PCanvas.cpp:112
virtual bool SetProperty(std::string, Variant v)
Definition PCanvas.cpp:84
virtual void SetHeight(int h)
Definition PCanvas.cpp:145
virtual void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
Definition PCanvas.cpp:102
virtual std::string ObjectName() const
Definition PCanvas.cpp:162
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PCanvas.cpp:128
bool mDrawBackground
Definition PCanvas.h:66
virtual Variant GetProperty(std::string) const
Definition PCanvas.cpp:122
PCanvas()
Definition PCanvas.cpp:39
counted_ptr< PEBLObjectBase > GetObject() const
virtual bool InitializeProperty(std::string name, Variant v)
virtual bool SetProperty(std::string name, Variant v)
pInt mDrawX
Definition PWidget.h:129
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PWidget.cpp:188
virtual Variant GetProperty(std::string) const
Definition PWidget.cpp:181
virtual pInt GetWidth() const
Definition PWidget.h:85
virtual void SetBackgroundColor(const PColor &color)
Definition PWidget.cpp:287
virtual pInt GetHeight() const
Definition PWidget.h:86
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
pInt mY
Definition PWidget.h:125
pInt mDrawY
Definition PWidget.h:130
PComplexData * GetComplexData() const
Definition Variant.cpp:1299
X * get() const
Definition rc_ptrs.h:110