annotate window/system.cc @ 67:419761c8d9b9

Add configure option to build scn2kdump.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 23 Feb 2011 01:48:51 +0100
parents 4416cfac86ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
28 #include <SDL.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
29 #include "system.h"
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
30 #include <iostream>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
31 #include <stdio.h>
0
223b71206888 Initial import
thib
parents:
diff changeset
32
223b71206888 Initial import
thib
parents:
diff changeset
33 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 // void SDL_SetEventFilter(SDL_EventFilter filter);
223b71206888 Initial import
thib
parents:
diff changeset
36 // typedef int (*SDL_EventFilter)(const SDL_Event *event);
223b71206888 Initial import
thib
parents:
diff changeset
37 namespace System {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
38 Main* Main::instance = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
39
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
40 int Main::event_filter(const SDL_Event* event) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
41 return 1; /* throw all event */
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
42 }
0
223b71206888 Initial import
thib
parents:
diff changeset
43
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
44 Main::Main(void) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
45 instance = this;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
46 framerate = 20;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
47 cursor = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
48 }
0
223b71206888 Initial import
thib
parents:
diff changeset
49
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
50 Main::~Main() {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
51 if (cursor) delete cursor;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
52 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
53
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
54 void Main::Quit(void) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
55 is_exit = true;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
56 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
57
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
58 void Main::EnableVideo(void) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
59 is_video_update = true;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
60 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
61
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
62 void Main::DisableVideo(void) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
63 is_video_update = false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
64 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
65
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
66 bool Main::is_exit = false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
67 bool Main::is_video_update = true;
0
223b71206888 Initial import
thib
parents:
diff changeset
68
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
69 void Main::Mainloop(void) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
70 SDL_SetEventFilter(&event_filter);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
71 Uint32 old_time = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
72 while(!is_exit) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
73 Uint32 start_time = SDL_GetTicks();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
74 if (! event.Exec(start_time)) break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
75 if (start_time - old_time > 1000/framerate) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
76 if (is_video_update) root.ExecUpdate();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
77 event.Exec(Event::Time::FRAME_UPDATE);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
78 cout.flush();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
79 old_time = start_time;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
80 }
0
223b71206888 Initial import
thib
parents:
diff changeset
81
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
82 // 問題:
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
83 // z 軸と xy 軸の相互干渉;高速化
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
84 // 移動するウィジット描画の高速化
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
85 // キャッシュ
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
86 // 文字列の一部のみ更新の高速化
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
87 // 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
88 /*
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
89 Uint32 end_time = SDL_GetTicks();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
90 Uint32 delay = (end_time-start_time);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
91 if(delay < 1000/framerate) SDL_Delay(1000/framerate - delay);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
92 else SDL_Delay(0);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
93 */
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
94 SDL_Delay(0);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
95 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
96 }
0
223b71206888 Initial import
thib
parents:
diff changeset
97
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
98 void Main::SetCursor(Surface* s, const Rect& r) {
54
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
99 if (instance == NULL) return;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
100 if (instance->cursor) delete instance->cursor;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
101 if (s == NULL) { // カーソル消去
54
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
102 instance->cursor = NULL;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
103 } else if (s == DEFAULT_MOUSECURSOR) {
54
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
104 instance->cursor = NULL;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
105 SDL_ShowCursor(SDL_ENABLE);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
106 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
107 instance->cursor = new WidMouseCursor(instance->event, instance->root.root, s, r.lx, r.ty, r.width(), r.height());
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
108 instance->cursor->show();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
109 SDL_ShowCursor(SDL_DISABLE);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
110 }
0
223b71206888 Initial import
thib
parents:
diff changeset
111 }
223b71206888 Initial import
thib
parents:
diff changeset
112 }