PEBL
2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PLabel.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/PLabel.cpp
4
// Purpose: Contains methods primary visual 'word' structure
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 "
PLabel.h
"
28
#include "
PFont.h
"
29
30
#include <string>
31
#include <iostream>
32
33
using
std::cout;
34
using
std::endl;
35
36
PLabel::PLabel
():
37
PTextObject
(
""
)
38
{
39
InitializeProperty
(
"NAME"
,
Variant
(
"<LABEL>"
));
40
InitializeProperty
(
"FORMATTED"
,
Variant
(0));
41
mCDT
=
CDT_LABEL
;
42
}
43
44
45
46
PLabel::PLabel
(
const
std::string & text):
47
PTextObject
(text)
48
{
49
InitializeProperty
(
"NAME"
,
Variant
(
"<LABEL>"
));
50
InitializeProperty
(
"FORMATTED"
,
Variant
(0));
51
mCDT
=
CDT_LABEL
;
52
}
53
54
55
56
PLabel::PLabel
(
const
PLabel
& label):
57
PTextObject
(label.GetText())
58
{
59
InitializeProperty
(
"NAME"
,
Variant
(
"<LABEL>"
));
60
InitializeProperty
(
"FORMATTED"
,
Variant
(0));
61
mCDT
=
CDT_LABEL
;
62
}
63
64
PLabel::~PLabel
()
65
{
66
}
67
68
69
bool
PLabel::SetProperty
(std::string name,
Variant
v)
70
{
71
if
(name ==
"FORMATTED"
) {
72
// FORMATTED property: 0 or 1
73
PEBLObjectBase::SetProperty
(name, v);
74
return
true
;
75
}
76
else
if
(
PTextObject::SetProperty
(name,v))
77
return
true
;
78
else
return
false
;
79
80
}
81
82
83
Variant
PLabel::GetProperty
(std::string name)
const
84
{
85
return
PTextObject::GetProperty
(name);
86
}
87
88
89
ObjectValidationError
PLabel::ValidateProperty
(std::string name,
Variant
v)
const
90
{
91
return
ValidateProperty
(name);
92
}
93
94
ObjectValidationError
PLabel::ValidateProperty
(std::string name)
const
95
{
96
// Check for Label-specific properties first
97
if
(name ==
"FORMATTED"
) {
98
return
OVE_VALID
;
99
}
100
101
// Then check parent class properties
102
ObjectValidationError
ove =
PTextObject::ValidateProperty
(name);
103
104
if
(ove ==
OVE_VALID
)
105
return
ove;
106
else
107
return
OVE_INVALID_PROPERTY_NAME
;
108
}
109
110
void
PLabel::SetPosition
(
pInt
x,
pInt
y)
111
{
112
//Why does this get called 4x with an EasyLabel?
113
114
mX
= x;
115
mY
= y;
116
mDrawX
= x -
GetWidth
()/2;
117
mDrawY
= y -
GetHeight
()/2;
118
// cout << "Setting label position\n" << x << ","<<y<<"|" << mDrawX << "," << mDrawY<<endl;
119
PEBLObjectBase::SetProperty
(
"X"
,
Variant
(
mX
));
120
PEBLObjectBase::SetProperty
(
"Y"
,
Variant
(
mY
));
121
}
122
123
124
std::string
PLabel::ObjectName
()
const
125
{
126
return
"Text Label"
;
127
}
pInt
#define pInt
Definition
Defs.h:8
ObjectValidationError
ObjectValidationError
Definition
PEBLObject.h:37
OVE_INVALID_PROPERTY_NAME
@ OVE_INVALID_PROPERTY_NAME
Definition
PEBLObject.h:40
OVE_VALID
@ OVE_VALID
Definition
PEBLObject.h:39
CDT_LABEL
@ CDT_LABEL
Definition
PEBLObject.h:59
PFont.h
PLabel.h
PEBLObjectBase::InitializeProperty
virtual bool InitializeProperty(std::string name, Variant v)
Definition
PEBLObject.cpp:88
PEBLObjectBase::SetProperty
virtual bool SetProperty(std::string name, Variant v)
Definition
PEBLObject.cpp:67
PEBLObjectBase::mCDT
ComplexDataType mCDT
Definition
PEBLObject.h:109
PLabel
Definition
PLabel.h:45
PLabel::ValidateProperty
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition
PLabel.cpp:89
PLabel::~PLabel
virtual ~PLabel()
Definition
PLabel.cpp:64
PLabel::GetProperty
virtual Variant GetProperty(std::string) const
Definition
PLabel.cpp:83
PLabel::SetProperty
virtual bool SetProperty(std::string, Variant v)
Definition
PLabel.cpp:69
PLabel::PLabel
PLabel()
Definition
PLabel.cpp:36
PLabel::SetPosition
void SetPosition(pInt x, pInt y)
This sets the widget's position on its parent widget.
Definition
PLabel.cpp:110
PLabel::ObjectName
virtual std::string ObjectName() const
Definition
PLabel.cpp:124
PTextObject
This class simply represent an abstract text-based object.
Definition
PTextObject.h:41
PTextObject::ValidateProperty
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition
PTextObject.cpp:128
PTextObject::SetProperty
virtual bool SetProperty(std::string, Variant v)
Definition
PTextObject.cpp:97
PTextObject::GetProperty
virtual Variant GetProperty(std::string) const
Definition
PTextObject.cpp:122
PWidget::mDrawX
pInt mDrawX
Definition
PWidget.h:129
PWidget::GetWidth
virtual pInt GetWidth() const
Definition
PWidget.h:85
PWidget::GetHeight
virtual pInt GetHeight() const
Definition
PWidget.h:86
PWidget::mX
pInt mX
Definition
PWidget.h:125
PWidget::mY
pInt mY
Definition
PWidget.h:125
PWidget::mDrawY
pInt mDrawY
Definition
PWidget.h:130
Variant
Definition
Variant.h:67
src
objects
PLabel.cpp
Generated by
1.9.8