-
-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathmain_SDL3.cpp
More file actions
146 lines (125 loc) · 4.43 KB
/
main_SDL3.cpp
File metadata and controls
146 lines (125 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "stdafx.h"
#include "Editor.h"
#include "sdl3.h"
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_video.h>
#include <fstream>
#include "icon.c"
using namespace std;
int sdl_loop(Editor &editor)
{
bool quit = false;
while (!quit)
{
editor.Run();
SDL_Event event;
while(SDL_PollEvent(&event)){
bool textinput_action_delete = false;
switch(event.type){
case SDL_EVENT_QUIT:
quit = true;
break;
case SDL_EVENT_WINDOW_CLOSE_REQUESTED: // exit editor
quit = true;
break;
case SDL_EVENT_WINDOW_RESIZED:
// Tells the engine to reload window configuration (size and dpi)
editor.SetWindow(editor.window);
break;
case SDL_EVENT_WINDOW_FOCUS_LOST:
editor.is_window_active = false;
break;
case SDL_EVENT_WINDOW_FOCUS_GAINED:
editor.is_window_active = true;
editor.HotReload();
break;
case SDL_EVENT_KEY_DOWN:
if(event.key.scancode == SDL_SCANCODE_BACKSPACE
|| event.key.scancode == SDL_SCANCODE_DELETE
|| event.key.scancode == SDL_SCANCODE_KP_BACKSPACE){
wi::gui::TextInputField::DeleteFromInput();
textinput_action_delete = true;
}
break;
case SDL_EVENT_TEXT_INPUT:
if(!textinput_action_delete){
if(event.text.text[0] >= 21){
wi::gui::TextInputField::AddInput(event.text.text[0]);
}
}
break;
default:
break;
}
wi::input::sdlinput::ProcessEvent(event);
}
}
return 0;
}
void set_window_icon(SDL_Window *window) {
// these masks are needed to tell SDL_CreateRGBSurface(From)
// to assume the data it gets is byte-wise RGB(A) data
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int shift = (gimp_image.bytes_per_pixel == 3) ? 8 : 0;
rmask = 0xff000000 >> shift;
gmask = 0x00ff0000 >> shift;
bmask = 0x0000ff00 >> shift;
amask = 0x000000ff >> shift;
#else // little endian, like x86
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = (gimp_image.bytes_per_pixel == 3) ? 0 : 0xff000000;
#endif
const int depth = gimp_image.bytes_per_pixel*8;
const int pitch = gimp_image.bytes_per_pixel*gimp_image.width;
SDL_Surface* icon = SDL_CreateSurfaceFrom(gimp_image.width, gimp_image.height,
SDL_GetPixelFormatForMasks(depth, rmask, gmask, bmask, amask),
(void*)gimp_image.pixel_data, pitch);
SDL_SetWindowIcon(window, icon);
SDL_DestroySurface(icon);
}
int main(int argc, char *argv[])
{
Editor editor;
wi::arguments::Parse(argc, argv);
sdl3::sdlsystem_ptr_t system = sdl3::make_sdlsystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD);
if (!system) {
throw sdl3::SDLError("Error creating SDL3 system");
}
int width = 1920;
int height = 1080;
bool fullscreen = false;
wi::Timer timer;
if (editor.config.Open("config.ini"))
{
if (editor.config.Has("width"))
{
width = editor.config.GetInt("width");
height = editor.config.GetInt("height");
}
fullscreen = editor.config.GetBool("fullscreen");
editor.allow_hdr = editor.config.GetBool("allow_hdr");
wi::backlog::post("config.ini loaded in " + std::to_string(timer.elapsed_milliseconds()) + " milliseconds\n");
}
width = std::max(100, width);
height = std::max(100, height);
sdl3::window_ptr_t window = sdl3::make_window(
"Wicked Engine Editor",
width, height,
SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
if (!window) {
throw sdl3::SDLError("Error creating window");
}
set_window_icon(window.get());
if (fullscreen)
{
// SDL_SetWindowFullscreenMode(window.get(), TODO);
SDL_SetWindowFullscreen(window.get(), true);
}
editor.SetWindow(window.get());
int ret = sdl_loop(editor);
return ret;
}