PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
WindowTest.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: WindowTest.cpp
4// Purpose: Tests the basic Window widget class hierarchy
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003 Shane T. Mueller <smueller@umich.edu>
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
29#include "../base/Variant.h"
30#include "../objects/PObject.h"
31#include "../objects/PWidget.h"
32
33#include "../objects/PEnvironment.h"
34#include "../objects/PWindow.h"
35#include "../devices/PKeyboard.h"
36#include "../objects/PImageBox.h"
37
38#include "../platforms/sdl/PlatformEnvironment.h"
39#include "../platforms/sdl/PlatformWindow.h"
40#include "../platforms/sdl/PlatformKeyboard.h"
41#include "../platforms/sdl/PlatformImageBox.h"
42#include "../platforms/sdl/PlatformFont.h"
43#include "../platforms/sdl/PlatformWord.h"
44
45#include <iostream>
46
47
48//The following is the entry point for the command-line version
49int main(int argc, char **argv)
50{
51
52 //This sets the video driver
53 setenv("SDL_VIDEODRIVER", "dga",1);
54 setenv("SDL_VIDEODRIVER", "x11",1);
55
56
57
58 //Make a few new colors.
59 cout << "Creating new colors\n";
60 PColor red = PColor("red");
61 PColor grey = PColor("grey");
62 grey.SetAlpha(150);
63
66
67 PlatformWindow * myWindow = new PlatformWindow();
68 myWindow->Initialize();
69 myWindow->SetBackgroundColor(grey);
70
71 PKeyboard * myKeyboard = new PlatformKeyboard();
72
73
74 //Add window to environment.
75 myEnv->AddWindow(myWindow);
76
77
78 //Now make an Image Widget.
79 PlatformImageBox * myImage1 = new PlatformImageBox;
80 if(!myImage1->LoadImage("media/images/pebl.bmp"))
81 cout << "Loading image1 failed\n" ;
82
83
84 //Make another image, just for kicks.
85 PlatformImageBox * myImage2 = new PlatformImageBox;
86 if(!myImage2->LoadImage("media/images/pebl.png"))
87 cout << "Loading image2 failed\n" ;
88
89 //Make a font.
90 cout << "Creating a font\n";
91 PlatformFont * myFont1 = new PlatformFont("media/fonts/VeraSe.ttf", PFS_Normal, 22, red, grey, true );
92 PlatformFont * myFont2 = new PlatformFont("media/fonts/VeraSe.ttf", PFS_Normal, 22, red, grey, false );
93
94
95 cout << "Creating PlatformWord object\n";
96 //Now, make a 'word object.
97 PlatformWord * myWord1 = new PlatformWord("Hello World: anti-aliased", myFont1);
98 myWord1->SetPosition(30,30);
99
100 PlatformWord * myWord2 = new PlatformWord("Hello World:aliased", myFont2);
101 myWord2->SetPosition(30,50);
102
103
104
105
106 myWindow->AddSubWidget(myImage1);
107 myWindow->AddSubWidget(myImage2);
108 myWindow->AddSubWidget(myWord1);
109 myWindow->AddSubWidget(myWord2);
110
111
112 myEnv->Draw();
113 myKeyboard->WaitForAnyKeyDown();
114 myKeyboard->WaitForAllKeysUp();
115
116
117 myImage1->SetPosition(10,10);
118 myImage2->SetPosition(10,200);
119 myEnv->Draw();
120 myKeyboard->WaitForAnyKeyDown();
121 myKeyboard->WaitForAllKeysUp();
122
123
124
125 myImage1->SetPosition(100,20);
126 myImage2->SetPosition(100,300);
127 myEnv->Draw();
128 myKeyboard->WaitForAllKeysUp();
129 myKeyboard->WaitForAnyKeyDown();
130
131
132
133 myImage1->SetPosition(200,200);
134 myImage2->SetPosition(200,400);
135 myEnv->Draw();
136 myKeyboard->WaitForAllKeysUp();
137
138 myKeyboard->WaitForAnyKeyDown();
139
140
141 for(int i= 0; i<500;i+=10){
142 myImage1->SetPosition(i,400);
143 myEnv->Draw();
144 }
145
146
147 myKeyboard->WaitForAllKeysUp();
148 myKeyboard->WaitForAnyKeyDown();
149 cout << "Done\n";
150
151
152 delete myImage1, myImage2;
153 delete myWindow;
154 delete myEnv;
155
156 return 0;
157}
PlatformEnvironment * myEnv
Definition PEBL.cpp:189
@ PFS_Normal
Definition PFont.h:45
int main(int argc, char **argv)
void SetAlpha(int color)
Definition PColor.cpp:218
virtual bool AddWindow(PWindow *window)
virtual void SetPosition(pInt x, pInt y)
Definition PImageBox.cpp:44
void Initialize()
This method initiates everything needed to display the main window.
Validator platform image box - no image loading, used only for compilation.
virtual bool LoadImage(const std::string &imagefilename)
virtual bool AddSubWidget(PlatformWidget *widget)
bool Initialize(PEBLVideoMode mode, PEBLVideoDepth vdepth, bool windowed, bool resizeable, unsigned int width, unsigned int height)
This method initiates everything needed to display the main window.
virtual void SetBackgroundColor(const PColor &color)