World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
OSWindowFactory.cpp
См. документацию.
2 
3 #ifdef _WINDOWS
4 #include <Windows.h>
5 #else
6 #include <cstring>
7 #endif
8 #include <stdio.h>
9 
10 #include "Platform/Api.h"
11 #include "Platform/Sdl2Window.h"
12 
13 OSWindow *OSWindowFactory::Create(const char *title, int window_width, int window_height) {
14  return CreateSdl2(title, window_width, window_height);
15 }
16 
17 OSWindow *OSWindowFactory::CreateSdl2(const char *title, int window_width, int window_height) {
18  auto sdlWindow = SDL_CreateWindow(
19  title,
20  SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
21  window_width, window_height,
23 
24  if (sdlWindow) {
25  auto sdlWindowSurface = SDL_GetWindowSurface(sdlWindow);
26  if (sdlWindowSurface) {
27  return new Sdl2Window(sdlWindow, sdlWindowSurface);
28  } else {
29  SDL_DestroyWindow(sdlWindow);
30  }
31  }
32 
33  return nullptr;
34 }
35 
36 int main(int argc, char *argv[]) {
37  extern int MM_Main(const char *);
38  return MM_Main(argv[0]);
39 }
Sdl2Window
Definition: Sdl2Window.h:7
OSWindowFactory::CreateSdl2
OSWindow * CreateSdl2(const char *title, int window_width, int window_height)
Definition: OSWindowFactory.cpp:17
SDL_WINDOW_OPENGL
@ SDL_WINDOW_OPENGL
Definition: SDL_video.h:100
MM_Main
int MM_Main(const char *pCmdLine)
Definition: Game.cpp:83
SDL_GetWindowSurface
DECLSPEC SDL_Surface *SDLCALL SDL_GetWindowSurface(SDL_Window *window)
Get the SDL surface associated with the window.
OSWindow
Definition: OSWindow.h:12
Sdl2Window.h
OSWindowFactory::Create
OSWindow * Create(const char *title, int window_width, int window_height)
Definition: OSWindowFactory.cpp:13
main
int main(int argc, char *argv[])
Definition: OSWindowFactory.cpp:36
SDL_WINDOW_SHOWN
@ SDL_WINDOW_SHOWN
Definition: SDL_video.h:101
SDL_CreateWindow
DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
Create a window with the specified position, dimensions, and flags.
OSWindowFactory.h
SDL_DestroyWindow
DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window *window)
Destroy a window.
Api.h