00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00030
00031 #include "stratagus.h"
00032 #include "title.h"
00033 #include "video.h"
00034 #include "movie.h"
00035 #include "font.h"
00036 #include "sound_server.h"
00037
00038
00039 TitleScreen **TitleScreens;
00040 static bool WaitNoEvent;
00041
00042
00046 static void WaitCallbackButtonPressed(unsigned dummy)
00047 {
00048 WaitNoEvent = false;
00049 }
00050
00054 static void WaitCallbackButtonReleased(unsigned dummy)
00055 {
00056 }
00057
00061 static void WaitCallbackKeyPressed(unsigned dummy1, unsigned dummy2)
00062 {
00063 WaitNoEvent = false;
00064 }
00065
00069 static void WaitCallbackKeyReleased(unsigned dummy1, unsigned dummy2)
00070 {
00071 }
00072
00076 static void WaitCallbackKeyRepeated(unsigned dummy1, unsigned dummy2)
00077 {
00078 }
00079
00083 static void WaitCallbackMouse(int x, int y)
00084 {
00085 }
00086
00090 static void WaitCallbackExit(void)
00091 {
00092 }
00093
00097 static void ShowTitleImage(TitleScreen *t)
00098 {
00099 const EventCallback *old_callbacks;
00100 EventCallback callbacks;
00101 CGraphic *g;
00102 int x, y;
00103
00104 WaitNoEvent = true;
00105
00106 callbacks.ButtonPressed = WaitCallbackButtonPressed;
00107 callbacks.ButtonReleased = WaitCallbackButtonReleased;
00108 callbacks.MouseMoved = WaitCallbackMouse;
00109 callbacks.MouseExit = WaitCallbackExit;
00110 callbacks.KeyPressed = WaitCallbackKeyPressed;
00111 callbacks.KeyReleased = WaitCallbackKeyReleased;
00112 callbacks.KeyRepeated = WaitCallbackKeyRepeated;
00113 callbacks.NetworkEvent = NULL;
00114
00115 old_callbacks = GetCallbacks();
00116 SetCallbacks(&callbacks);
00117
00118 g = CGraphic::New(t->File);
00119 g->Load();
00120 if (t->StretchImage) {
00121 x = 0;
00122 y = 0;
00123 g->Resize(Video.Width, Video.Height);
00124 } else {
00125 x = (Video.Width - g->Width) / 2;
00126 y = (Video.Height - g->Height) / 2;
00127 }
00128
00129 int timeout = t->Timeout * CYCLES_PER_SECOND;
00130 if (!timeout) {
00131 timeout = -1;
00132 }
00133
00134 while (timeout-- && WaitNoEvent) {
00135 g->DrawClip((Video.Width - g->Width) / 2, (Video.Height - g->Height) / 2);
00136 TitleScreenLabel **labels = t->Labels;
00137 if (labels && labels[0] && labels[0]->Font &&
00138 labels[0]->Font->IsLoaded()) {
00139 for (int j = 0; labels[j]; ++j) {
00140
00141 int x = labels[j]->Xofs * Video.Width / 640;
00142 int y = labels[j]->Yofs * Video.Width / 640;
00143 if (labels[j]->Flags & TitleFlagCenter) {
00144 x -= labels[j]->Font->Width(labels[j]->Text) / 2;
00145 }
00146 VideoDrawText(x, y, labels[j]->Font, labels[j]->Text);
00147 }
00148 }
00149
00150 Invalidate();
00151 RealizeVideoMemory();
00152 WaitEventsOneFrame();
00153 }
00154
00155 SetCallbacks(old_callbacks);
00156 CGraphic::Free(g);
00157 }
00158
00162 void ShowTitleScreens()
00163 {
00164 if (!TitleScreens) {
00165 return;
00166 }
00167
00168 SetVideoSync();
00169
00170 for (int i = 0; TitleScreens[i]; ++i) {
00171 if (!TitleScreens[i]->Music.empty()) {
00172 if (TitleScreens[i]->Music == "none" ||
00173 PlayMusic(TitleScreens[i]->Music) == -1) {
00174 StopMusic();
00175 }
00176 }
00177
00178 if (PlayMovie(TitleScreens[i]->File)) {
00179 ShowTitleImage(TitleScreens[i]);
00180 }
00181
00182 Video.ClearScreen();
00183 }
00184 Invalidate();
00185 }
00186