26a9d5dd5e
* SDL Input Refactor (Initial Edit) * SDL Input Refactor - IMGUI Text Input Fix * SDL Input Refactor - wiGUI Text Input Fix * SDL Input Refactor - Pruning Includes * SDL Input Refactor - Fix Includes * SDL Input Refactor - Fix Compiler Error (Windows) * SDL Input Refactor - Fix Compile Error (2) * SDL Input Refactor - SDL Version Checking For LED * Trying out Sniper SDK build system * SDL Input Refactor - Processing Design Changes * SDL Input Refactor - Separate Steam Deck Build * SDL Input Refactor - Separate Steam Deck (2) * Steam SDK CI Build - Change Package Name & Reduct * Steam SDK CI - Straight up building, no apt update
161 lines
5.7 KiB
C++
161 lines
5.7 KiB
C++
#include "stdafx.h"
|
|
#include "Editor.h"
|
|
|
|
#include "sdl2.h"
|
|
#include <fstream>
|
|
|
|
#include "Assets/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_QUIT:
|
|
quit = true;
|
|
break;
|
|
case SDL_WINDOWEVENT:
|
|
switch (event.window.event) {
|
|
case SDL_WINDOWEVENT_CLOSE: // exit editor
|
|
quit = true;
|
|
break;
|
|
case SDL_WINDOWEVENT_RESIZED:
|
|
// Tells the engine to reload window configuration (size and dpi)
|
|
editor.SetWindow(editor.window);
|
|
break;
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
editor.is_window_active = false;
|
|
break;
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
editor.is_window_active = true;
|
|
if (wi::shadercompiler::GetRegisteredShaderCount() > 0)
|
|
{
|
|
std::thread([] {
|
|
wi::backlog::post("[Shader check] Started checking " + std::to_string(wi::shadercompiler::GetRegisteredShaderCount()) + " registered shaders for changes...");
|
|
if (wi::shadercompiler::CheckRegisteredShadersOutdated())
|
|
{
|
|
wi::backlog::post("[Shader check] Changes detected, initiating reload...");
|
|
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [](uint64_t userdata) {
|
|
wi::renderer::ReloadShaders();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
wi::backlog::post("[Shader check] All up to date");
|
|
}
|
|
}).detach();
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
case SDL_KEYDOWN:
|
|
if(event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE
|
|
|| event.key.keysym.scancode == SDL_SCANCODE_DELETE
|
|
|| event.key.keysym.scancode == SDL_SCANCODE_KP_BACKSPACE){
|
|
if (wi::backlog::isActive())
|
|
wi::backlog::deletefromInput();
|
|
wi::gui::TextInputField::DeleteFromInput();
|
|
textinput_action_delete = true;
|
|
}
|
|
break;
|
|
case SDL_TEXTINPUT:
|
|
if(!textinput_action_delete){
|
|
if(event.text.text[0] >= 21){
|
|
if (wi::backlog::isActive())
|
|
wi::backlog::input(event.text.text[0]);
|
|
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
|
|
SDL_Surface* icon = SDL_CreateRGBSurfaceFrom((void*)gimp_image.pixel_data, gimp_image.width,
|
|
gimp_image.height, gimp_image.bytes_per_pixel*8, gimp_image.bytes_per_pixel*gimp_image.width,
|
|
rmask, gmask, bmask, amask);
|
|
|
|
SDL_SetWindowIcon(window, icon);
|
|
|
|
SDL_FreeSurface(icon);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
Editor editor;
|
|
|
|
wi::arguments::Parse(argc, argv);
|
|
|
|
sdl2::sdlsystem_ptr_t system = sdl2::make_sdlsystem(SDL_INIT_EVERYTHING | SDL_INIT_EVENTS);
|
|
if (!system) {
|
|
throw sdl2::SDLError("Error creating SDL2 system");
|
|
}
|
|
|
|
int x = 0, y = 0, w = 1920, h = 1080;
|
|
bool fullscreen = false;
|
|
bool borderless = false;
|
|
string voidStr = "";
|
|
|
|
ifstream file("config.ini");
|
|
if (file.is_open())
|
|
{
|
|
int enabled;
|
|
file >> voidStr >> enabled;
|
|
if (enabled != 0)
|
|
{
|
|
file >> voidStr >> x >> voidStr >> y >> voidStr >> w >> voidStr >> h >> voidStr >> fullscreen >> voidStr >> borderless;
|
|
}
|
|
}
|
|
file.close();
|
|
|
|
sdl2::window_ptr_t window = sdl2::make_window(
|
|
"Wicked Engine Editor",
|
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
w, h,
|
|
SDL_WINDOW_SHOWN | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
|
if (!window) {
|
|
throw sdl2::SDLError("Error creating window");
|
|
}
|
|
|
|
set_window_icon( window.get());
|
|
|
|
if(fullscreen) SDL_SetWindowFullscreen(window.get(), SDL_TRUE);
|
|
|
|
editor.SetWindow(window.get());
|
|
|
|
int ret = sdl_loop(editor);
|
|
|
|
SDL_Quit();
|
|
return ret;
|
|
}
|