Skip to content

Commit

Permalink
fix windows / renderer compile (renderer requires sdl for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed May 26, 2018
1 parent 841022c commit 58127f3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 80 deletions.
37 changes: 17 additions & 20 deletions SConscript
Expand Up @@ -242,26 +242,25 @@ def findLibs(env, conf):
if not GetOption('renderer') and not conf.CheckLib('SDLmain'):
FatalError("libSDLmain not found or not installed")

if not GetOption('renderer'):
#Look for SDL
runSdlConfig = platform == "Linux" or compilePlatform == "Linux" or platform == "FreeBSD"
if False and platform == "Darwin" and conf.CheckFramework("SDL"):
runSdlConfig = False
elif not conf.CheckLib("SDL2"):
FatalError("SDL development library not found or not installed")

if runSdlConfig:
try:
env.ParseConfig('sdl2-config --cflags')
if GetOption('static'):
env.ParseConfig('sdl2-config --static-libs')
else:
env.ParseConfig('sdl2-config --libs')
except:
pass
#Look for SDL
runSdlConfig = platform == "Linux" or compilePlatform == "Linux" or platform == "FreeBSD"
if False and platform == "Darwin" and conf.CheckFramework("SDL"):
runSdlConfig = False
elif not conf.CheckLib("SDL2"):
FatalError("SDL development library not found or not installed")

if runSdlConfig:
try:
env.ParseConfig('sdl2-config --cflags')
if GetOption('static'):
env.ParseConfig('sdl2-config --static-libs')
else:
env.ParseConfig('sdl2-config --libs')
except:
pass

#look for SDL.h
if not GetOption('renderer') and not conf.CheckCHeader('SDL2.h'):
if not conf.CheckCHeader('SDL2.h'):
if conf.CheckCHeader('SDL2/SDL.h'):
env.Append(CPPDEFINES=["SDL_INC"])
else:
Expand Down Expand Up @@ -505,8 +504,6 @@ if GetOption('opengl') or GetOption('opengl-renderer'):

if GetOption('renderer'):
env.Append(CPPDEFINES=['RENDERER'])
else:
env.Append(CPPDEFINES=['USE_SDL'])

if GetOption('font'):
env.Append(CPPDEFINES=['FONTEDITOR'])
Expand Down
58 changes: 19 additions & 39 deletions src/PowderToySDL.cpp
@@ -1,11 +1,10 @@
#ifdef USE_SDL
#ifndef RENDERER

#include <map>
#include "common/String.h"
#include <ctime>
#include <climits>
#ifdef WIN
#define _WIN32_WINNT 0x0501 //Necessary for some macros and functions, tells windows.h to include functions only available in Windows XP or later
#include <direct.h>
#endif
#include "SDLCompat.h"
Expand Down Expand Up @@ -54,10 +53,6 @@ using namespace std;

#define INCLUDE_SYSWM
#include "SDLCompat.h"
#if defined(USE_SDL) && defined(LIN) && defined(SDL_VIDEO_DRIVER_X11)
SDL_SysWMinfo sdl_wminfo;
Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING;
#endif

int desktopWidth = 1280, desktopHeight = 1024;

Expand Down Expand Up @@ -134,10 +129,7 @@ void blit(pixel * vid)

int SDLOpen()
{
#if defined(WIN) && defined(WINCONSOLE)
FILE * console = fopen("CON", "w" );
#endif
if (SDL_Init(SDL_INIT_VIDEO)<0)
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
return 1;
Expand All @@ -148,32 +140,6 @@ int SDLOpen()
desktopWidth = SDLDisplayMode.w;
desktopHeight = SDLDisplayMode.h;

#if defined(WIN) && defined(WINCONSOLE)
//On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console
if (console)
{
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
//fclose(console);
}
#endif
#ifdef WIN
SDL_SysWMinfo SysInfo;
SDL_VERSION(&SysInfo.version);
if(SDL_GetWMInfo(&SysInfo) <= 0) {
printf("%s : %p\n", SDL_GetError(), SysInfo.window);
exit(-1);
}
HWND WindowHandle = SysInfo.window;

// Use GetModuleHandle to get the Exe HMODULE/HINSTANCE
HMODULE hModExe = GetModuleHandle(NULL);
HICON hIconSmall = (HICON)LoadImage(hModExe, MAKEINTRESOURCE(101), IMAGE_ICON, 16, 16, LR_SHARED);
HICON hIconBig = (HICON)LoadImage(hModExe, MAKEINTRESOURCE(101), IMAGE_ICON, 32, 32, LR_SHARED);
SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
#endif

sdl_window = SDL_CreateWindow("The Powder Toy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOWW * scale, WINDOWH * scale,
fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0);
Expand All @@ -187,6 +153,23 @@ int SDLOpen()
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
//SDL_SetWindowResizable(sdl_window, SDL_TRUE);

#ifdef WIN
SDL_SysWMinfo SysInfo;
SDL_VERSION(&SysInfo.version);
if(SDL_GetWindowWMInfo(sdl_window, &SysInfo) <= 0)
{
printf("%s : %p\n", SDL_GetError(), SysInfo.info.win.window);
exit(-1);
}
HWND WindowHandle = SysInfo.info.win.window;

// Use GetModuleHandle to get the Exe HMODULE/HINSTANCE
HMODULE hModExe = GetModuleHandle(NULL);
HICON hIconSmall = (HICON)LoadImage(hModExe, MAKEINTRESOURCE(101), IMAGE_ICON, 16, 16, LR_SHARED);
HICON hIconBig = (HICON)LoadImage(hModExe, MAKEINTRESOURCE(101), IMAGE_ICON, 32, 32, LR_SHARED);
SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
#endif
#ifdef LIN
SDL_Surface *icon = SDL_CreateRGBSurfaceFrom((void*)app_icon, 48, 48, 32, 192, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
SDL_SetWindowIcon(sdl_window, icon);
Expand Down Expand Up @@ -412,9 +395,6 @@ void DoubleScreenDialog()
{
Client::Ref().SetPref("Scale", 1);
engine->SetScale(1);
#ifdef WIN
LoadWindowPosition(1);
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/SDLCompat.cpp
@@ -1,4 +1,4 @@
#if defined(USE_SDL) && defined(_MSC_VER) && (_MSC_VER >= 1900)
#if defined(_MSC_VER) && (_MSC_VER >= 1900)

#include <cstdio>

Expand Down
8 changes: 2 additions & 6 deletions src/SDLCompat.h
@@ -1,19 +1,15 @@
#ifdef USE_SDL

#ifdef SDL_INC
#include "SDL2/SDL.h"
#else
#include "SDL.h"
#endif

#ifdef INCLUDE_SYSWM
#if defined(WIN) || defined(LIN)
#if defined(WIN)
#ifdef SDL_INC
#include <SDL2/SDL_syswm.h>
#else
#include <SDL_syswm.h>
#endif
#endif // WIN || LIN
#endif // WIN
#endif // INCLUDE_SYSWM

#endif // USE_SDL
4 changes: 0 additions & 4 deletions src/gui/localbrowser/LocalBrowserView.cpp
Expand Up @@ -114,21 +114,17 @@ void LocalBrowserView::textChanged()
else if (num > pageCount)
pageTextbox->SetText(String::Build(pageCount));
changed = true;
#ifdef USE_SDL
lastChanged = GetTicks()+600;
#endif
}

void LocalBrowserView::OnTick(float dt)
{
c->Update();
#ifdef USE_SDL
if (changed && lastChanged < GetTicks())
{
changed = false;
c->SetPage(std::max(pageTextbox->GetText().ToNumber<int>(true), 0));
}
#endif
}

void LocalBrowserView::NotifyPageChanged(LocalBrowserModel * sender)
Expand Down
6 changes: 0 additions & 6 deletions src/gui/options/OptionsView.cpp
Expand Up @@ -180,13 +180,7 @@ OptionsView::OptionsView():
FullscreenAction(OptionsView * v_){ v = v_; }
virtual void ActionCallback(ui::Checkbox * sender)
{
#ifdef USE_SDL
#if defined(MACOSX) && !SDL_VERSION_ATLEAST(1, 2, 15)
ErrorMessage::Blocking("Information", "Fullscreen doesn't work on OS X");
#else
v->c->SetFullscreen(sender->GetChecked());
#endif
#endif
}
};

Expand Down
4 changes: 0 additions & 4 deletions src/gui/search/SearchView.cpp
Expand Up @@ -291,9 +291,7 @@ void SearchView::textChanged()
else if (num > pageCount)
pageTextbox->SetText(String::Build(pageCount));
changed = true;
#ifdef USE_SDL
lastChanged = GetTicks()+600;
#endif
}

void SearchView::OnTryOkay(OkayMethod method)
Expand Down Expand Up @@ -780,13 +778,11 @@ void SearchView::NotifySelectedChanged(SearchModel * sender)
void SearchView::OnTick(float dt)
{
c->Update();
#ifdef USE_SDL
if (changed && lastChanged < GetTicks())
{
changed = false;
c->SetPage(std::max(pageTextbox->GetText().ToNumber<int>(true), 0));
}
#endif
}

void SearchView::OnMouseWheel(int x, int y, int d)
Expand Down

0 comments on commit 58127f3

Please sign in to comment.