ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/BeOS/about_window_beos.cpp
Revision: 1.4
Committed: 2008-01-01T09:47:38Z (16 years, 4 months ago) by gbeauche
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -2 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * about_window_beos.cpp - "About" window, BeOS implementation
3 *
4 * SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <GLView.h>
22 #include <GL/gl.h>
23 #include <GL/glu.h>
24 #include <stdio.h>
25
26 #include "about_window.h"
27 #include "video.h"
28 #include "version.h"
29 #include "user_strings.h"
30
31
32 // About window dimensions
33 static const BRect about_frame = BRect(0, 0, 383, 99);
34
35 // Special colors
36 const rgb_color fill_color = {216, 216, 216, 0};
37
38 // SheepShaver icon
39 static const uint8 sheep_icon[] = {
40 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff,
42 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xda, 0x15, 0x00,
44 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
45 0xff, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xff, 0x00, 0x00, 0x00, 0x16, 0xda, 0x00,
46 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x16,
47 0x00, 0x1d, 0xda, 0x1e, 0x1e, 0x1e, 0xda, 0x16, 0x00, 0x00, 0x16, 0xda, 0x16, 0xda, 0x08, 0xff,
48 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x16, 0x00, 0x00, 0x00, 0x0b, 0xff, 0xff, 0x11, 0x00, 0xda,
49 0x1d, 0xda, 0x1e, 0xda, 0x1e, 0xda, 0x1e, 0xda, 0x1e, 0x16, 0x00, 0x00, 0x0c, 0xff, 0xff, 0xff,
50 0xff, 0x0b, 0x00, 0x00, 0x16, 0x16, 0x00, 0x12, 0xfd, 0x1d, 0x0b, 0x00, 0x00, 0x1d, 0xfd, 0x1d,
51 0xfd, 0x1e, 0xda, 0x1e, 0xda, 0x1e, 0xda, 0x3f, 0xda, 0x3f, 0xda, 0x15, 0x00, 0xff, 0xff, 0xff,
52 0x16, 0x00, 0x17, 0x16, 0x00, 0x00, 0x1d, 0xfd, 0x1d, 0xfd, 0x1d, 0xfd, 0x16, 0x0f, 0x0b, 0x1d,
53 0x1e, 0xfd, 0x1e, 0xda, 0x1e, 0xda, 0x3f, 0xda, 0x3f, 0xda, 0x1d, 0x5a, 0x15, 0xff, 0xff, 0xff,
54 0x05, 0x17, 0x16, 0x00, 0x12, 0x1d, 0x00, 0x1d, 0xfd, 0x00, 0xfd, 0x00, 0x00, 0x16, 0x0b, 0x00,
55 0x00, 0x0e, 0x1d, 0x3f, 0x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10, 0x00, 0x1b, 0xfd, 0x1b, 0xfd, 0x1b, 0xfd, 0x18,
67 0xfd, 0x15, 0xfa, 0x15, 0xf9, 0x18, 0x15, 0x00, 0x12, 0x9b, 0x00, 0x1b, 0x9b, 0x00, 0x15, 0x15,
68 0xff, 0xff, 0x00, 0xfd, 0x1d, 0xfd, 0x1d, 0x00, 0x16, 0x00, 0x1b, 0xfd, 0x1b, 0xfd, 0x15, 0xfd,
69 0x15, 0xfa, 0x15, 0xf9, 0x15, 0x16, 0x00, 0x0f, 0x9b, 0x12, 0x00, 0x9b, 0x1b, 0x00, 0x15, 0x15,
70 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x1d, 0x00, 0xfa, 0x1e, 0x00, 0x1e, 0xfa, 0x15,
71 0xfa, 0x15, 0x16, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x9b, 0x00, 0x00, 0x00, 0x12, 0x15, 0x15,
72 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1d, 0xf9, 0x00, 0x3f, 0xfa, 0x00, 0xfa, 0x1b, 0x00,
73 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x00, 0x00, 0x12, 0x15, 0x15, 0x15, 0x15,
74 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf9, 0x1d, 0x00, 0xf9, 0x1b, 0x00, 0x1b, 0xf9, 0x00,
75 0xff, 0xff, 0xff, 0xff, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0xff,
76 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1d, 0xf9, 0x00, 0x3f, 0xf9, 0x00, 0xf9, 0x1b, 0x00,
77 0xff, 0xff, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0xff, 0xff, 0xff, 0xff,
78 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x16, 0x1d, 0x00, 0xf9, 0x1b, 0x00, 0x1b, 0xf9, 0x00,
79 0xff, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
80 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x16, 0x00, 0x00, 0x00, 0x16, 0xf9, 0x00, 0x1b, 0x16, 0x00,
81 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x00, 0x00, 0x12, 0xff, 0xff, 0xff, 0xff, 0xff,
82 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x16, 0x00, 0x00, 0x16, 0x00, 0x16, 0x00, 0x16,
83 0x15, 0x15, 0x15, 0x15, 0x00, 0x00, 0x15, 0x00, 0x0a, 0x19, 0x0a, 0x00, 0xff, 0xff, 0xff, 0xff,
84 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x12, 0x00, 0x00, 0x00, 0x16, 0xff,
85 0xff, 0xff, 0xff, 0xff, 0x00, 0x0a, 0x00, 0x15, 0x00, 0x19, 0x1c, 0x18, 0x00, 0xff, 0xff, 0xff,
86 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,
87 0x0f, 0xff, 0xff, 0xff, 0x00, 0x18, 0x11, 0x00, 0x15, 0x00, 0x1c, 0x18, 0x00, 0xff, 0xff, 0xff,
88 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, 0x00, 0x00, 0x00, 0x0b, 0x0b,
89 0x00, 0x00, 0x0f, 0xff, 0x12, 0x00, 0x18, 0x19, 0x00, 0x15, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
90 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, 0x00, 0x00, 0x14, 0x1e, 0xfd, 0x01, 0xfd, 0x14,
91 0xfa, 0xf9, 0x00, 0xff, 0xff, 0x00, 0x0a, 0x19, 0x1c, 0x00, 0x18, 0x1c, 0x00, 0x00, 0xff, 0xff,
92 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x14, 0xfd, 0x1e, 0xf9, 0x1e, 0xfa, 0x1e, 0xf9,
93 0x14, 0xfa, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x1c, 0x00, 0x18, 0x00, 0xff,
94 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x14, 0x1e, 0xf9, 0x14, 0xfa, 0x1e, 0xf9, 0x1e,
95 0xfd, 0x1e, 0x00, 0x15, 0xff, 0xff, 0xff, 0x15, 0x15, 0x15, 0x00, 0x00, 0x18, 0x00, 0x1c, 0x00,
96 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, 0x00, 0xfd, 0x1e, 0xfd, 0x14, 0xfd, 0x1e, 0xfd,
97 0x1e, 0x01, 0x00, 0x15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x00, 0x00, 0x1c, 0x00, 0x15,
98 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x14, 0xfa, 0x01, 0xf9, 0x1e, 0xf9, 0x14,
99 0x14, 0x00, 0x0f, 0x15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x00, 0x00, 0x15, 0x15,
100 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x0f, 0x15, 0x15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x15, 0x15, 0xff,
102 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
103 0x15, 0x15, 0x15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
104 };
105
106
107 // View class
108 class AboutViewT : public BView {
109 public:
110 AboutViewT(BRect r) : BView(r, "", B_FOLLOW_NONE, B_WILL_DRAW) {}
111
112 virtual void Draw(BRect update)
113 {
114 char str[256];
115 sprintf(str, GetString(STR_ABOUT_TEXT1), VERSION_MAJOR, VERSION_MINOR);
116
117 SetFont(be_bold_font);
118 SetDrawingMode(B_OP_OVER);
119 MovePenTo(20, 20);
120 DrawString(str);
121 SetFont(be_plain_font);
122 MovePenTo(20, 40);
123 DrawString(GetString(STR_ABOUT_TEXT2));
124 MovePenTo(20, 60);
125 DrawString(B_UTF8_COPYRIGHT "1997-2008 Christian Bauer and Marc Hellwig");
126 }
127
128 virtual void MouseDown(BPoint point)
129 {
130 Window()->PostMessage(B_QUIT_REQUESTED);
131 }
132 };
133
134
135 // 3D view class
136 class AboutView3D : public BGLView {
137 public:
138 AboutView3D(BRect r) : BGLView(r, "", B_FOLLOW_NONE, 0, BGL_RGB | BGL_DOUBLE)
139 {
140 rot_x = rot_y = 0;
141
142 if (!VideoSnapshot(64, 64, texture)) {
143 uint8 *p = texture;
144 const uint8 *q = sheep_icon;
145 const color_map *cm = system_colors();
146 for (int i=0; i<32*32; i++) {
147 uint8 red = cm->color_list[*q].red;
148 uint8 green = cm->color_list[*q].green;
149 uint8 blue = cm->color_list[*q++].blue;
150 p[0] = p[3] = p[64*3] = p[65*3] = red;
151 p[1] = p[4] = p[64*3+1] = p[65*3+1] = green;
152 p[2] = p[5] = p[64*3+2] = p[65*3+2] = blue;
153 p += 6;
154 if ((i & 31) == 31)
155 p += 64*3;
156 }
157 }
158 }
159
160 virtual void AttachedToWindow(void)
161 {
162 BGLView::AttachedToWindow();
163 LockGL();
164
165 glDisable(GL_DEPTH_TEST);
166 glDepthMask(GL_FALSE);
167
168 glShadeModel(GL_SMOOTH);
169
170 glMatrixMode(GL_PROJECTION);
171 glLoadIdentity();
172 gluPerspective(30, 1, 0.5, 20);
173
174 glMatrixMode(GL_MODELVIEW);
175 glLoadIdentity();
176
177 GLfloat light_color[4] = {1, 1, 1, 1};
178 GLfloat light_dir[4] = {1, 2, 1.5, 1};
179 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color);
180 glLightfv(GL_LIGHT0, GL_POSITION, light_dir);
181 glEnable(GL_LIGHT0);
182 glEnable(GL_LIGHTING);
183
184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
188 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
189 glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
190 glEnable(GL_TEXTURE_2D);
191
192 UnlockGL();
193
194 tick_thread_active = true;
195 tick_thread = spawn_thread(tick_func, "OpenGL Animation", B_NORMAL_PRIORITY, this);
196 resume_thread(tick_thread);
197 }
198
199 virtual void DetachedFromWindow(void)
200 {
201 status_t l;
202 tick_thread_active = false;
203 wait_for_thread(tick_thread, &l);
204
205 BGLView::DetachedFromWindow();
206 }
207
208 virtual void Draw(BRect update)
209 {
210 LockGL();
211 glClear(GL_COLOR_BUFFER_BIT);
212 glBegin(GL_QUADS);
213 glNormal3d(0, 0, 1);
214 glTexCoord2f(0, 0);
215 glVertex3d(-1, 1, 0);
216 glTexCoord2f(1, 0);
217 glVertex3d(1, 1, 0);
218 glTexCoord2f(1, 1);
219 glVertex3d(1, -1, 0);
220 glTexCoord2f(0, 1);
221 glVertex3d(-1, -1, 0);
222 glEnd();
223 SwapBuffers();
224 UnlockGL();
225 }
226
227 static status_t tick_func(void *arg)
228 {
229 AboutView3D *obj = (AboutView3D *)arg;
230 while (obj->tick_thread_active) {
231 obj->rot_x += 2;
232 obj->rot_y += 2;
233 obj->LockGL();
234 glMatrixMode(GL_MODELVIEW);
235 glLoadIdentity();
236 glTranslatef(0, 0, -5);
237 glRotatef(obj->rot_x, 1, 0, 0);
238 glRotatef(obj->rot_y, 0, 1, 0);
239 obj->UnlockGL();
240 if (obj->LockLooperWithTimeout(20000) == B_OK) {
241 obj->Draw(obj->Bounds());
242 obj->UnlockLooper();
243 }
244 snooze(16667);
245 }
246 return 0;
247 }
248
249 private:
250 thread_id tick_thread;
251 bool tick_thread_active;
252
253 float rot_x, rot_y;
254 uint8 texture[64*64*3];
255 };
256
257
258 // Window class
259 class AboutWindowT : public BWindow {
260 public:
261 AboutWindowT() : BWindow(about_frame, NULL, B_MODAL_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK)
262 {
263 Lock();
264 MoveTo(100, 100);
265 BRect r = Bounds();
266 r.right = 100;
267 AboutView3D *view_3d = new AboutView3D(r);
268 AddChild(view_3d);
269 r = Bounds();
270 r.left = 100;
271 AboutViewT *view = new AboutViewT(r);
272 AddChild(view);
273 view->SetHighColor(0, 0, 0);
274 view->SetViewColor(fill_color);
275 view->MakeFocus();
276 Unlock();
277 Show();
278 }
279 };
280
281
282 /*
283 * Open "About" window
284 */
285
286 void OpenAboutWindow(void)
287 {
288 new AboutWindowT;
289 }