Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement resizable GUI #64

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b8094ab
Try to handle resize event.
Quipyowert2 Feb 27, 2021
b94f466
Write class to listen for events in main thread.
Quipyowert2 Nov 12, 2022
aff7fe6
Change globalContainer to handle both event and logic threads.
Quipyowert2 Nov 13, 2022
0e786bd
Replace SDL_PollEvent with EventListener::poll.
Quipyowert2 Nov 13, 2022
1730c9e
Handle resize on title screen.
Quipyowert2 Nov 17, 2022
9d4e8fe
Change EventListener booleans to be atomic.
Quipyowert2 Nov 23, 2022
7ceb58e
Fix graphics glitches in OpenGL mode.
Quipyowert2 Nov 23, 2022
6c4c7ad
Handle resizing during a game.
Quipyowert2 Nov 23, 2022
5dacb46
Fix position of minimap when resizing game window.
Quipyowert2 Nov 23, 2022
6837dcf
Keep map editor widgets in the right panel.
Quipyowert2 Nov 23, 2022
0ca173d
Join thread, fix server, and move globals into GlobalContainer.
Quipyowert2 Nov 24, 2022
4cb6f6c
Use condition variables rather than busy looping.
Quipyowert2 Nov 24, 2022
dbba9bc
Fix deadlock when exiting the game.
Quipyowert2 Nov 25, 2022
bcb6fd3
Add copyright header.
Quipyowert2 Nov 26, 2022
abd01a0
Disallow resizing to smaller than minimum size.
Quipyowert2 Nov 27, 2022
c0e4a4d
Fix missing template argument with GCC 7.5.0.
Quipyowert2 Dec 24, 2022
69c7619
Fix black window upon resizing.
Quipyowert2 Dec 25, 2022
05be3cf
Fix white screen in software renderered mode.
Quipyowert2 Dec 28, 2022
34885f0
Disable resize during loading screen.
Quipyowert2 Dec 28, 2022
8d8d3ac
Hook resize event on Windows.
Quipyowert2 Mar 8, 2023
3c95f3b
Use a mutex when painting or changing gfx surface.
Quipyowert2 Mar 24, 2023
c8073e7
Move draw code in MapEdit::run into MapEdit::draw.
Quipyowert2 Apr 17, 2023
5b530e5
WIP: Implement painting MapEdit and Screen objects.
Quipyowert2 Apr 20, 2023
8c15bc2
WIP: Fix crash when resizing.
Quipyowert2 Apr 24, 2023
63b9bf0
Fix globules' sprites flickering to white and back.
Quipyowert2 May 15, 2023
38f3ea1
Fix intermittent crash during window resizing.
Quipyowert2 Jun 14, 2023
2cfc719
Name logic thread so I can tell which thread it is.
Quipyowert2 Jun 16, 2023
dbeefd5
Document EventListener.
Quipyowert2 Jun 16, 2023
df0dbd3
The queue doesn't need to be double-ended.
Quipyowert2 Jun 16, 2023
f2f17d4
Fix flickering during window resize.
Quipyowert2 Jun 16, 2023
06e3983
Fix textures turning white after resizing window.
Quipyowert2 Jun 16, 2023
8e21b7c
Rename poorly-named variable.
Quipyowert2 Jun 16, 2023
60a544b
Fix cursor flickering at screen edge when resizing.
Quipyowert2 Nov 7, 2023
7f2ff28
Fix textures flickering to white, try 4.
Quipyowert2 Nov 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion glob2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<ClCompile Include="gnupg\sha1.c" />
<ClCompile Include="libgag\src\BinaryStream.cpp" />
<ClCompile Include="libgag\src\CursorManager.cpp" />
<ClCompile Include="libgag\src\EventListener.cpp" />
<ClCompile Include="libgag\src\FileManager.cpp">
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug SDL|Win32'">ZLIB_WINAPI;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug SDL|x64'">ZLIB_WINAPI;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -507,6 +508,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="libgag\include\DX9GraphicContext.h" />
<ClInclude Include="libgag\include\EventListener.h" />
<ClInclude Include="libgag\include\FileManager.h" />
<ClInclude Include="libgag\include\GAG.h" />
<ClInclude Include="libgag\include\GAGSys.h" />
Expand Down Expand Up @@ -622,4 +624,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions libgag/include/CursorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace GAGCore
CursorManager();
//! Load the cursor sprites
void load(void);
void reinitTextures(void);
//! Select the next type given the mouse position
void nextTypeFromMouse(DrawableSurface *ds, int x, int y, bool button);
//! Manually set the next type
Expand Down
67 changes: 67 additions & 0 deletions libgag/include/EventListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright (C) 2022 Nathan Mills
for any question or comment contact us at <the dot true dot nathan dot mills at gmail dot com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __EVENTLISTENER_H
#define __EVENTLISTENER_H
#include "GraphicContext.h"
#include <SDL.h>
#include <queue>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <map>

#if defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
#define WINDOWS_OR_MINGW 1
#endif

namespace GAGCore {
extern std::queue<SDL_Event> events;
class EventListener {
public:
EventListener(GraphicContext* gfx);
void run();
void stop();
bool isRunning();
bool isResizing();
int poll(SDL_Event* e);
static EventListener *instance();
~EventListener();
static std::mutex startMutex;
static std::condition_variable startedCond;
static std::mutex doneMutex;
static std::condition_variable doneCond;
static std::recursive_mutex renderMutex;
void setPainter(std::function<void()> f);
void addPainter(const std::string& name, std::function<void()> f);
void removePainter(const std::string& name);
static void ensureContext();
void paint();
private:
std::function<void()> painter;
std::multimap<const std::string, std::function<void()> > painters;
GraphicContext* gfx;
static EventListener* el;
std::atomic<bool> quit, done;
std::atomic<int> depth;

static std::mutex queueMutex; // used when pushing/popping queue.
};
}
#endif //__EVENTLISTENER_H
15 changes: 15 additions & 0 deletions libgag/include/SDLGraphicContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace GAGCore
protected:
friend struct Color;
friend class GraphicContext;
friend class Sprite;
//! the underlying software SDL surface
SDL_Surface *sdlsurface;
//! The clipping rect, we do not draw outside it
Expand Down Expand Up @@ -318,12 +319,16 @@ namespace GAGCore
protected:
//! the minimum acceptable resolution
int minW, minH;
int prevW, prevH;
SDL_Window *window = nullptr;
SDL_GLContext context = nullptr;
friend class DrawableSurface;
//! option flags
Uint32 optionFlags;
std::string windowTitle;
std::string appIcon;
int resizeTimer;
Sint64 framesDrawn, frameStartResize, frameStopResize;

public:
//! Constructor. Create a new window of size (w,h). If useGPU is true, use GPU for accelerated 2D (OpenGL or DX)
Expand All @@ -334,6 +339,14 @@ namespace GAGCore
// modifiers
virtual bool setRes(int w, int h, Uint32 flags);
virtual void setRes(int w, int h) { setRes(w, h, optionFlags); }
virtual SDL_Surface *getOrCreateSurface(int w, int h, Uint32 flags);
virtual SDL_Rect getRes();
virtual bool resChanged();
virtual void createGLContext();
virtual void unsetContext();
static GraphicContext* instance();
void resetMatrices();
bool isResizing();
virtual void setClipRect(int x, int y, int w, int h);
virtual void setClipRect(void);
virtual void nextFrame(void);
Expand Down Expand Up @@ -437,6 +450,8 @@ namespace GAGCore

//! Load a sprite from the file, return true if any frame have been loaded
bool load(const std::string filename);

void reinit();

//! Set the (r,g,b) color to a sprite's base color
virtual void setBaseColor(Uint8 r, Uint8 g, Uint8 b) { actColor = Color(r, g, b); }
Expand Down
8 changes: 8 additions & 0 deletions libgag/src/CursorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ namespace GAGCore
cursors.push_back(Toolkit::getSprite("data/gfx/cursor/mark"));
setDefaultColor();
}

void CursorManager::reinitTextures(void)
{
for (Sprite *cursor : cursors)
{
cursor->reinit();
}
}

void CursorManager::nextTypeFromMouse(DrawableSurface *ds, int x, int y, bool button)
{
Expand Down
Loading