PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PTextObject.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/PTextObject.cpp
4// Purpose: Contains generic specs for all objects containing text
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2004-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#include "PWidget.h"
28#include "PTextObject.h"
29#include "PFont.h"
30#include "../utility/PError.h"
31
32#include <string>
33#include <iostream>
34using std::cout;
35using std::endl;
36
38 PWidget(0,0,0,0,false),
39 mChanged(true),
40 mText(""),
41 mDirection(1)
42{
43 InitializeProperty("TEXT","");
44 InitializeProperty("DIRECTION",1);
45 InitializeProperty("LINEHEIGHT",0);
46
47}
48
49
50
51PTextObject::PTextObject(const std::string & text):
52 PWidget(0,0,0,0,false),
53 mChanged(true),
54 mText(std::string(text)),
55 mDirection(1)
56{
57
59 InitializeProperty("DIRECTION",1);
60 InitializeProperty("LINEHEIGHT",0);
61}
62
63
65 PWidget(0,0,0,0,false),
66 mChanged(true),
67 mText(object.GetText()),
68 mDirection(1)
69{
71 InitializeProperty("DIRECTION",1);
72 InitializeProperty("LINEHEIGHT",0);
73}
74
75
76void PTextObject::SetText(const std::string & text)
77{
78 mText = text;
80 mChanged = true;
81}
82
83
85{
86 if(dir ==1 | dir == -1)
87 {
88 PEBLObjectBase::SetProperty("DIRECTION",Variant(dir));
89 mDirection = dir;
90 mChanged = true;
91 } else
92 {
93 PError::SignalFatalError("Improper value for direction");
94 }
95}
96
97bool PTextObject::SetProperty(std::string name, Variant v)
98{
99
100
101 if(PWidget::SetProperty(name,v))
102 {
103 mChanged = true;
104 return true;
105 }
106 else
107 {
108 if (name == "TEXT")
109 {
110 SetText(v);
111 return true;
112 }
113 else if(name == "DIRECTION")
114 {
115 SetDirection(v);
116 }
117 return PWidget::SetProperty(name,v);
118 }
119}
120
121
122Variant PTextObject::GetProperty(std::string name)const
123{
124 return PEBLObjectBase::GetProperty(name);
125}
126
127
129{
130 return ValidateProperty(name);
131}
132
134{
135
137
138 if(ove == OVE_VALID)
139 return ove;
140
141 else if(name == "TEXT" ||
142 name == "WIDTH" ||
143 name == "HEIGHT" ||
144 name == "FONT" ||
145 name == "DIRECTION"||
146 name == "LINEHEIGHT")
147
148 return OVE_VALID;
149 else
151
152}
153
154
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
This class simply represent an abstract text-based object.
Definition PTextObject.h:41
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
virtual bool SetProperty(std::string, Variant v)
std::string mText
Definition PTextObject.h:70
virtual Variant GetProperty(std::string) const
virtual ~PTextObject()
virtual void SetDirection(int i)
virtual void SetText(const std::string &text)
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PWidget.cpp:188
virtual bool SetProperty(std::string, Variant v)
Definition PWidget.cpp:142
void SignalFatalError(const std::string &message)