Debian Codegraph @

engine/stratagus/title.cpp

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name title.cpp - The title screen. */
11 //
12 // (c) Copyright 2007 by Jimmy Salmon
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program 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 this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27 //
28
29 //@{
30
31 #include "stratagus.h"
32 #include "title.h"
33 #include "video.h"
34 #include "movie.h"
35 #include "font.h"
36 #include "sound_server.h"
37
38
39 TitleScreen **TitleScreens; /// Title screens to show at startup
40 static bool WaitNoEvent; /// Flag got an event
41
42
43 /**
44 ** Callback for input.
45 */
46 static void WaitCallbackButtonPressed(unsigned dummy)
47 {
48 WaitNoEvent = false;
49 }
50
51 /**
52 ** Callback for input.
53 */
54 static void WaitCallbackButtonReleased(unsigned dummy)
55 {
56 }
57
58 /**
59 ** Callback for input.
60 */
61 static void WaitCallbackKeyPressed(unsigned dummy1, unsigned dummy2)
62 {
63 WaitNoEvent = false;
64 }
65
66 /**
67 ** Callback for input.
68 */
69 static void WaitCallbackKeyReleased(unsigned dummy1, unsigned dummy2)
70 {
71 }
72
73 /**
74 ** Callback for input.
75 */
76 static void WaitCallbackKeyRepeated(unsigned dummy1, unsigned dummy2)
77 {
78 }
79
80 /**
81 ** Callback for input.
82 */
83 static void WaitCallbackMouse(int x, int y)
84 {
85 }
86
87 /**
88 ** Callback for exit.
89 */
90 static void WaitCallbackExit(void)
91 {
92 }
93
94 /**
95 ** Show a title image
96 */
97 static void ShowTitleImage(TitleScreen *t)
98 {
99 const EventCallback *old_callbacks;
100 EventCallback callbacks;
101 CGraphic *g;
102
103 WaitNoEvent = true;
104
105 callbacks.ButtonPressed = WaitCallbackButtonPressed;
106 callbacks.ButtonReleased = WaitCallbackButtonReleased;
107 callbacks.MouseMoved = WaitCallbackMouse;
108 callbacks.MouseExit = WaitCallbackExit;
109 callbacks.KeyPressed = WaitCallbackKeyPressed;
110 callbacks.KeyReleased = WaitCallbackKeyReleased;
111 callbacks.KeyRepeated = WaitCallbackKeyRepeated;
112 callbacks.NetworkEvent = NULL;
113
114 old_callbacks = GetCallbacks();
115 SetCallbacks(&callbacks);
116
117 g = CGraphic::New(t->File);
118 g->Load();
119 if (t->StretchImage) {
120 g->Resize(Video.Width, Video.Height);
121 }
122
123 int timeout = t->Timeout * CYCLES_PER_SECOND;
124 if (!timeout) {
125 timeout = -1;
126 }
127
128 while (timeout-- && WaitNoEvent) {
129 g->DrawClip((Video.Width - g->Width) / 2, (Video.Height - g->Height) / 2);
130 TitleScreenLabel **labels = t->Labels;
131 if (labels && labels[0] && labels[0]->Font &&
132 labels[0]->Font->IsLoaded()) {
133 for (int j = 0; labels[j]; ++j) {
134 // offsets are for 640x480, scale up to actual resolution
135 int x = labels[j]->Xofs * Video.Width / 640;
136 int y = labels[j]->Yofs * Video.Width / 640;
137 if (labels[j]->Flags & TitleFlagCenter) {
138 x -= labels[j]->Font->Width(labels[j]->Text) / 2;
139 }
140 VideoDrawText(x, y, labels[j]->Font, labels[j]->Text);
141 }
142 }
143
144 Invalidate();
145 RealizeVideoMemory();
146 WaitEventsOneFrame();
147 }
148
149 SetCallbacks(old_callbacks);
150 CGraphic::Free(g);
151 }
152
153 /**
154 ** Show the title screens
155 */
156 void ShowTitleScreens()
157 {
158 if (!TitleScreens) {
159 return;
160 }
161
162 SetVideoSync();
163
164 for (int i = 0; TitleScreens[i]; ++i) {
165 if (!TitleScreens[i]->Music.empty()) {
166 if (TitleScreens[i]->Music == "none" ||
167 PlayMusic(TitleScreens[i]->Music) == -1) {
168 StopMusic();
169 }
170 }
171
172 if (PlayMovie(TitleScreens[i]->File)) {
173 ShowTitleImage(TitleScreens[i]);
174 }
175
176 Video.ClearScreen();
177 }
178 Invalidate();
179 }
180
181 //@}