summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/ginteractors.cpp
blob: 807537240b6aa756d8b665d5118d08d5532c6c37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * File: gobjects.cpp
 * ------------------
 * This file implements the ginteractors.h interface.
 */

#include <iostream>
#include <sstream>
#include "gevents.h"
#include "ginteractors.h"
#include "gobjects.h"
#include "gtypes.h"
#include "gwindow.h"
#include "platform.h"

static Platform *pp = getPlatform();

/*
 * Implementation notes: GInteractor class
 * ---------------------------------------
 */

GInteractor::GInteractor() {
   actionCommand = "";
}

void GInteractor::setActionCommand(string cmd) {
   actionCommand = cmd;
   pp->setActionCommand(this, cmd);
}

string GInteractor::getActionCommand() {
   return actionCommand;
}

void GInteractor::setSize(const GDimension & size) {
   setSize(size.getWidth(), size.getHeight());
}

void GInteractor::setSize(double width, double height) {
   pp->setSize(this, width, height);
}

void GInteractor::setBounds(const GRectangle & rect) {
   setLocation(rect.getX(), rect.getY());
   setSize(rect.getWidth(), rect.getHeight());
}

void GInteractor::setBounds(double x, double y, double width, double height) {
   setLocation(x, y);
   setSize(width, height);
}

GRectangle GInteractor::getBounds() const {
   GDimension size = pp->getSize((GObject *) this);
   return GRectangle(x, y, size.getWidth(), size.getHeight());
}

/*
 * Implementation notes: GButton class
 * -----------------------------------
 */

GButton::GButton(string label) {
   this->label = label;
   pp->createGButton(this, label);
}

string GButton::getType() const {
   return "GButton";
}

string GButton::toString() const {
   ostringstream oss;
   oss << "GButton(\"" << label << "\")";
   return oss.str();
}

/*
 * Implementation notes: GCheckBox class
 * -------------------------------------
 */

GCheckBox::GCheckBox(string label) {
   this->label = label;
   pp->createGCheckBox(this, label);
}

bool GCheckBox::isSelected() {
   return pp->isSelected(this);
}

void GCheckBox::setSelected(bool state) {
   pp->setSelected(this, state);
}

string GCheckBox::getType() const {
   return "GCheckBox";
}

string GCheckBox::toString() const {
   ostringstream oss;
   oss << "GCheckBox(\"" << label << "\")";
   return oss.str();
}

/*
 * Implementation notes: GSlider class
 * -----------------------------------
 */

GSlider::GSlider() {
   create(0, 100, 50);
}

GSlider::GSlider(int min, int max, int value) {
   create(min, max, value);
}

int GSlider::getValue() {
   return pp->getValue(this);
}

void GSlider::setValue(int value) {
   pp->setValue(this, value);
}

string GSlider::getType() const {
   return "GSlider";
}

string GSlider::toString() const {
   ostringstream oss;
   oss << "GSlider()";
   return oss.str();
}

void GSlider::create(int min, int max, int value) {
   this->min = min;
   this->max = max;
   pp->createGSlider(this, min, max, value);
}

/*
 * Implementation notes: GTextField class
 * --------------------------------------
 */

GTextField::GTextField() {
   pp->createGTextField(this, 10);
}

GTextField::GTextField(int nChars) {
   pp->createGTextField(this, nChars);
}

string GTextField::getText() {
   return pp->getText(this);
}

void GTextField::setText(string str) {
   pp->setText(this, str);
}

string GTextField::getType() const {
   return "GTextField";
}

string GTextField::toString() const {
   ostringstream oss;
   oss << "GTextField()";
   return oss.str();
}

/*
 * Implementation notes: GChooser class
 * ------------------------------------
 */

GChooser::GChooser() {
   pp->createGChooser(this);
}

void GChooser::addItem(string item) {
   pp->addItem(this, item);
}

string GChooser::getSelectedItem() {
   return pp->getSelectedItem(this);
}

void GChooser::setSelectedItem(string item) {
   pp->setSelectedItem(this, item);
}

string GChooser::getType() const {
   return "GChooser";
}

string GChooser::toString() const {
   ostringstream oss;
   oss << "GChooser()";
   return oss.str();
}