-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenWindow.cpp
More file actions
196 lines (164 loc) · 5.87 KB
/
openWindow.cpp
File metadata and controls
196 lines (164 loc) · 5.87 KB
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
/*
CS 349 Code Examples: X Windows and XLib
openwindow Opens a single blank window
- - - - - - - - - - - - - - - - - - - - - -
See associated makefile for compiling instructions
*/
#include <cstdlib>
#include <iostream>
#include <list>
#include <vector>
#include <unistd.h>
/*
* Header files for X functions
*/
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "openWindow.h"
#include "getColor.h"
using namespace std;
/*
* Information to draw on the window.
*/
/*
* Function to put out a message on error exits.
*/
void error( string str ) {
cerr << str << endl;
exit(0);
}
BrickPoint CreateBrick(int x, int y, int isHit) {
BrickPoint a;
a.X = x;
a.Y = y;
a.isHit = isHit;
return a;
}
/*
* Create a window
*/
void initSplash (int argc, char* argv[], XInfo& xinfo) {
XSizeHints hints;
hints.x = 450;
hints.y = 250;
hints.width = 400;
hints.height = 300;
hints.min_width=400;
hints.max_width=400;
hints.min_height=300;
hints.max_height=300;
hints.flags = PPosition | PSize | PMinSize | PMaxSize;
/*
* Display opening uses the DISPLAY environment variable.
* It can go wrong if DISPLAY isn't set, or you don't have permission.
*/
xinfo.display = XOpenDisplay( "" );
if ( !xinfo.display ) {
error( "Can't open display." );
}
/*
* Find out some things about the display you're using.
*/
// DefaultScreen is as macro to get default screen index
xinfo.screen = DefaultScreen( xinfo.display );
unsigned long white, black;
white = XWhitePixel( xinfo.display, xinfo.screen );
black = XBlackPixel( xinfo.display, xinfo.screen );
xinfo.window = XCreateSimpleWindow(
xinfo.display, // display where window appears
DefaultRootWindow( xinfo.display ), // window's parent in window tree
hints.x, hints.y, // upper left corner location
hints.width, hints.height, // size of the window
10, // width of window's border
black, // window border colour
white ); // window background colour
Atom type = XInternAtom(xinfo.display,"_NET_WM_WINDOW_TYPE", False);
Atom value = XInternAtom(xinfo.display,"_NET_WM_WINDOW_TYPE_SPLASH", False);
XChangeProperty(xinfo.display, xinfo.window, type, XA_ATOM, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&value), 1);
/* register interest in the delete window message */
Atom wmDeleteMessage = XInternAtom(xinfo.display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(xinfo.display, xinfo.window, &wmDeleteMessage, 1);
//extra window properties like a window title
XSetStandardProperties(
xinfo.display, // display containing the window
xinfo.window, // window whose properties are set
"x1_openWindow", // window's title
"OW", // icon's title
None, // pixmap for the icon
argv, argc, // applications command line args
&hints); // size hints for the window
XSetWMNormalHints(xinfo.display,xinfo.window,&hints);
/*
* Put the window on the screen.
*/
XSelectInput(xinfo.display, xinfo.window, ButtonPressMask | KeyPressMask);
XMapRaised( xinfo.display, xinfo.window );
XFlush(xinfo.display);
}
vector<vector<BrickPoint> > resetBricks() {
vector<vector<BrickPoint> > newReset(5, vector<BrickPoint> (15, CreateBrick(0,0,0)));
cout<<"enter resetBricks"<<endl;
//fill blocks
for (int i=0; i<5; ++i) {
// XSetForeground(xinfo.display, gc, xcolour.pixel);
for (int y=0; y<15;++y) {
newReset[i][y] = CreateBrick(y*75 + 56, i*45+50, 0);
//cout<<"brick created at: "<< vecBrick[i][y].X<<", "<<vecBrick[i][y].Y<<endl;
}
}
cout<<"exit resetBricks"<<endl;
return newReset;
}
void initX(int argc, char* argv[], XInfo& xinfo) {
XSizeHints hints;
hints.x = 0;
hints.y = 0;
hints.width = 1280;
hints.height = 800;
hints.min_width=1280;
hints.max_width=1280;
hints.min_height=800;
hints.max_height=800;
hints.flags = PPosition | PSize | PMinSize | PMaxSize;
/*
* Display opening uses the DISPLAY environment variable.
* It can go wrong if DISPLAY isn't set, or you don't have permission.
*/
xinfo.display = XOpenDisplay( "" );
if ( !xinfo.display ) {
error( "Can't open display." );
}
/*
* Find out some things about the display you're using.
*/
// DefaultScreen is as macro to get default screen index
xinfo.screen = DefaultScreen( xinfo.display );
unsigned long black;
Colormap cmap= XDefaultColormap(xinfo.display,DefaultScreen(xinfo.display));
XColor xred = getColor(cmap, 50000,65000,55000, xinfo.display);
black = XBlackPixel( xinfo.display, xinfo.screen );
xinfo.window = XCreateSimpleWindow(
xinfo.display, // display where window appears
DefaultRootWindow( xinfo.display ), // window's parent in window tree
hints.x, hints.y, // upper left corner location
hints.width, hints.height, // size of the window
10, // width of window's border
black, // window border colour
xred.pixel ); // window background colour
XSetWMNormalHints(xinfo.display,xinfo.window,&hints);
/*
* Put the window on the screen.
*/
XSelectInput(xinfo.display, xinfo.window, ButtonPressMask | KeyPressMask);
XMapRaised( xinfo.display, xinfo.window );
XFlush(xinfo.display);
}
// int main ( int argc, char* argv[] ) {
// XInfo xinfo;
// initX(argc, argv, xinfo);
// // wait for user input to quit (a concole event for now)
// cout << "press ENTER to exit";
// cin.get();
// XCloseDisplay(xinfo.display);
// }