From 647916e109fd0d2a95311f78dfb15f33a3a9b8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 7 Dec 2011 20:37:09 +0100 Subject: [PATCH] Graphic module --- library/CMakeLists.txt | 2 ++ library/Core.cpp | 2 ++ library/FakeSDL-windows.cpp | 45 +++++++++++++++++++++++++++++---- library/include/dfhack/Core.h | 4 +++ library/private/ModuleFactory.h | 1 + package/linux/dfhack | 2 +- plugins/CMakeLists.txt | 1 + 7 files changed, 51 insertions(+), 6 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index afa60d1c3..195ffa6e1 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -55,6 +55,7 @@ include/dfhack/modules/Translation.h include/dfhack/modules/Vegetation.h include/dfhack/modules/Vermin.h include/dfhack/modules/World.h +include/dfhack/modules/Graphic.h ) SET(PROJECT_SRCS @@ -89,6 +90,7 @@ modules/Translation.cpp modules/Vegetation.cpp modules/Vermin.cpp modules/World.cpp +modules/Graphic.cpp ) SET(PROJECT_HDRS_LINUX diff --git a/library/Core.cpp b/library/Core.cpp index efc9cf83c..f218f2756 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -45,6 +45,7 @@ using namespace std; #include "ModuleFactory.h" #include "dfhack/modules/Gui.h" #include "dfhack/modules/World.h" +#include "dfhack/modules/Graphic.h" using namespace DFHack; #include "dfhack/SDL_fakes/events.h" @@ -788,3 +789,4 @@ MODULE_GETTER(Buildings); MODULE_GETTER(Constructions); MODULE_GETTER(Vermin); MODULE_GETTER(Notes); +MODULE_GETTER(Graphic); diff --git a/library/FakeSDL-windows.cpp b/library/FakeSDL-windows.cpp index ee569c83c..d388b75d5 100644 --- a/library/FakeSDL-windows.cpp +++ b/library/FakeSDL-windows.cpp @@ -33,6 +33,7 @@ distribution. #include #include "tinythread.h" +#include "dfhack/modules/Graphic.h" /* * Plugin loading functions @@ -284,9 +285,44 @@ DFhackCExport vPtr SDL_SetVideoMode(int width, int height, int bpp, uint32_t fla { return _SDL_SetVideoMode(width, height, bpp, flags); } -static int (*_SDL_UpperBlit)(vPtr src, vPtr srcrect, vPtr dst, vPtr dstrect) = 0; -DFhackCExport int SDL_UpperBlit(vPtr src, vPtr srcrect, vPtr dst, vPtr dstrect) -{ + +static int (*_SDL_UpperBlit)(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) = 0; +DFhackCExport int SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) +{ + if ( dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 ) + { + DFHack::Core & c = DFHack::Core::getInstance(); + DFHack::Graphic* g = c.getGraphic(); + DFHack::DFTileSurface* ov = g->Call(dstrect->x/dstrect->w, dstrect->y/dstrect->h); + + if ( ov != NULL ) + { + if ( ov->paintOver ) + { + _SDL_UpperBlit(src, srcrect, dst, dstrect); + } + + DFHack::DFSDL_Rect* dstrect2 = new DFHack::DFSDL_Rect; + dstrect2->x = dstrect->x; + dstrect2->y = dstrect->y; + dstrect2->w = dstrect->w; + dstrect2->h = dstrect->h; + + if ( ov->dstResize != NULL ) + { + DFHack::DFSDL_Rect* r = (DFHack::DFSDL_Rect*)ov->dstResize; + dstrect2->x += r->x; + dstrect2->y += r->y; + dstrect2->w += r->w; + dstrect2->h += r->h; + } + + int result = _SDL_UpperBlit(ov->surface, ov->rect, dst, dstrect2); + delete dstrect2; + return result; + } + } + return _SDL_UpperBlit(src, srcrect, dst, dstrect); } @@ -745,7 +781,7 @@ bool FirstCall() _SDL_SetVideoMode = (void*(*)(int, int, int, uint32_t))GetProcAddress(realSDLlib,"SDL_SetVideoMode"); _SDL_ShowCursor = (int (*)(int))GetProcAddress(realSDLlib,"SDL_ShowCursor"); _SDL_UnlockSurface = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnlockSurface"); - _SDL_UpperBlit = (int (*)(void*, void*, void*, void*))GetProcAddress(realSDLlib,"SDL_UpperBlit"); + _SDL_UpperBlit = (int (*)(DFHack::DFSDL_Surface*, DFHack::DFSDL_Rect*, DFHack::DFSDL_Surface*, DFHack::DFSDL_Rect*))GetProcAddress(realSDLlib,"SDL_UpperBlit"); _SDL_WM_SetCaption = (void (*)(const char*, const char*))GetProcAddress(realSDLlib,"SDL_WM_SetCaption"); _SDL_WM_SetIcon = (void (*)(void*, uint8_t*))GetProcAddress(realSDLlib,"SDL_WM_SetIcon"); _SDL_mutexP = (int (*)(vPtr))GetProcAddress(realSDLlib,"SDL_mutexP"); @@ -781,4 +817,3 @@ bool FirstCall() inited = true; return 1; } - diff --git a/library/include/dfhack/Core.h b/library/include/dfhack/Core.h index 2d453bc10..2d7941af2 100644 --- a/library/include/dfhack/Core.h +++ b/library/include/dfhack/Core.h @@ -32,6 +32,7 @@ distribution. #include #include #include "dfhack/Console.h" +#include "dfhack/modules/Graphic.h" struct WINDOW; @@ -121,6 +122,8 @@ namespace DFHack Vermin * getVermin(); /// get the notes module Notes * getNotes(); + /// get the graphic module + Graphic * getGraphic(); /// sets the current hotkey command bool setHotkeyCmd( std::string cmd ); /// removes the hotkey command and gives it to the caller thread @@ -171,6 +174,7 @@ namespace DFHack Constructions * pConstructions; Vermin * pVermin; Notes * pNotes; + Graphic * pGraphic; } s_mods; std::vector allModules; DFHack::PluginManager * plug_mgr; diff --git a/library/private/ModuleFactory.h b/library/private/ModuleFactory.h index af34c35af..3677d3554 100644 --- a/library/private/ModuleFactory.h +++ b/library/private/ModuleFactory.h @@ -43,5 +43,6 @@ namespace DFHack Module* createMaps(); Module* createVermin(); Module* createNotes(); + Module* createGraphic(); } #endif diff --git a/package/linux/dfhack b/package/linux/dfhack index 7cbcb4219..d539237ff 100755 --- a/package/linux/dfhack +++ b/package/linux/dfhack @@ -67,7 +67,7 @@ case "$1" in esac # Reset terminal to sane state in case of a crash -reset $DF_RESET_OPTS +# reset $DF_RESET_OPTS if [ -n "$DF_POST_CMD" ]; then eval $DF_POST_CMD diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 3f8859e7c..c08bcd9e1 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -57,6 +57,7 @@ DFHACK_PLUGIN(deramp deramp.cpp) DFHACK_PLUGIN(flows flows.cpp) DFHACK_PLUGIN(filltraffic filltraffic.cpp) DFHACK_PLUGIN(seedwatch seedwatch.cpp) +DFHACK_PLUGIN(versionosd versionosd.cpp) # this is the skeleton plugin. If you want to make your own, make a copy and then change it OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF)