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
00078
00079
00080
00081
00082 #include <stdio.h>
00083 #include <string.h>
00084 #include <stdlib.h>
00085
00086 #include "stratagus.h"
00087
00088 #include <vector>
00089
00090 #include "video.h"
00091 #include "font.h"
00092 #include "ui.h"
00093 #include "cursor.h"
00094 #include "iolib.h"
00095
00096 #include "intern_video.h"
00097
00098 #include "SDL.h"
00099
00100
00101
00102
00103
00107 struct Clip {
00108 int X1;
00109 int Y1;
00110 int X2;
00111 int Y2;
00112 };
00113
00114
00115
00116
00117
00118 extern void InitVideoSdl(void);
00119
00120 extern void SdlLockScreen(void);
00121 extern void SdlUnlockScreen(void);
00122
00123
00124
00125
00126
00127 CVideo Video;
00128
00129 bool UseOpenGL;
00130
00131 char VideoForceFullScreen;
00132
00133 unsigned long NextFrameTicks;
00134 unsigned long FrameCounter;
00135 int SlowFrameCounter;
00136
00137 int ClipX1;
00138 int ClipY1;
00139 int ClipX2;
00140 int ClipY2;
00141
00142 static std::vector<Clip> Clips;
00143
00144 int VideoSyncSpeed = 100;
00145 int SkipFrames;
00146
00147 Uint32 ColorBlack;
00148 Uint32 ColorDarkGreen;
00149 Uint32 ColorBlue;
00150 Uint32 ColorOrange;
00151 Uint32 ColorWhite;
00152 Uint32 ColorGray;
00153 Uint32 ColorRed;
00154 Uint32 ColorGreen;
00155 Uint32 ColorYellow;
00156
00157
00158
00159
00160
00161
00170 void SetClipping(int left, int top, int right, int bottom)
00171 {
00172 Assert(left <= right && top <= bottom && left >= 0 && left < Video.Width &&
00173 top >= 0 && top < Video.Height && right >= 0 &&
00174 right < Video.Width && bottom >= 0 && bottom < Video.Height);
00175
00176 ClipX1 = left;
00177 ClipY1 = top;
00178 ClipX2 = right;
00179 ClipY2 = bottom;
00180 }
00181
00185 void PushClipping(void)
00186 {
00187 Clip clip = {ClipX1, ClipY1, ClipX2, ClipY2};
00188 Clips.push_back(clip);
00189 }
00190
00194 void PopClipping(void)
00195 {
00196 Clip clip = Clips.back();
00197 ClipX1 = clip.X1;
00198 ClipY1 = clip.Y1;
00199 ClipX2 = clip.X2;
00200 ClipY2 = clip.Y2;
00201 Clips.pop_back();
00202 }
00203
00204
00205
00206
00207
00211 void CVideo::LockScreen(void)
00212 {
00213 SdlLockScreen();
00214 }
00215
00219 void CVideo::UnlockScreen(void)
00220 {
00221 SdlUnlockScreen();
00222 }
00223
00227 void CVideo::ClearScreen(void)
00228 {
00229 FillRectangle(ColorBlack, 0, 0, Video.Width, Video.Height);
00230 }
00231
00237 bool CVideo::ResizeScreen(int w, int h)
00238 {
00239 if (VideoValidResolution(w, h)) {
00240 if (UseOpenGL) {
00241 FreeOpenGLGraphics();
00242 FreeOpenGLFonts();
00243 UI.Minimap.FreeOpenGL();
00244 }
00245 Width = w;
00246 Height = h;
00247 TheScreen = SDL_SetVideoMode(w, h, TheScreen->format->BitsPerPixel,
00248 TheScreen->flags);
00249 SetClipping(0, 0, Video.Width - 1, Video.Height - 1);
00250 if (UseOpenGL) {
00251 ReloadOpenGL();
00252 }
00253 return true;
00254 }
00255 return false;
00256 }
00257
00261 unsigned long GetTicks(void)
00262 {
00263 return SDL_GetTicks();
00264 }
00265
00269 void InitVideo(void)
00270 {
00271 InitVideoSdl();
00272 InitLineDraw();
00273 }
00274