Skip to content

Commit d1a1c5c

Browse files
committedAug 3, 2019
Add custom colorable GUIButton implementation
1 parent 41ad0f4 commit d1a1c5c

File tree

9 files changed

+2471
-19
lines changed

9 files changed

+2471
-19
lines changed
 

‎build/android/jni/Android.mk

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ LOCAL_SRC_FILES := \
186186
jni/src/gui/guiPasswordChange.cpp \
187187
jni/src/gui/guiPathSelectMenu.cpp \
188188
jni/src/gui/guiScrollBar.cpp \
189+
jni/src/gui/guiSkin.cpp \
189190
jni/src/gui/guiTable.cpp \
190191
jni/src/gui/guiVolumeChange.cpp \
191192
jni/src/gui/intlGUIEditBox.cpp \

‎src/client/renderingengine.cpp

+47-17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3535
#include "render/factory.h"
3636
#include "inputhandler.h"
3737
#include "gettext.h"
38+
#include "../gui/guiSkin.h"
3839

3940
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) && \
4041
!defined(SERVER) && !defined(__HAIKU__)
@@ -44,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4445
#include <X11/Xlib.h>
4546
#include <X11/Xutil.h>
4647
#include <X11/Xatom.h>
48+
4749
#endif
4850

4951
#ifdef __ANDROID__
@@ -52,6 +54,29 @@ with this program; if not, write to the Free Software Foundation, Inc.,
5254

5355
RenderingEngine *RenderingEngine::s_singleton = nullptr;
5456

57+
58+
static gui::GUISkin* createSkin(gui::IGUIEnvironment *environment,
59+
gui::EGUI_SKIN_TYPE type, video::IVideoDriver *driver)
60+
{
61+
gui::GUISkin* skin = new gui::GUISkin(type, driver);
62+
63+
gui::IGUIFont* builtinfont = environment->getBuiltInFont();
64+
gui::IGUIFontBitmap* bitfont = 0;
65+
if (builtinfont && builtinfont->getType() == gui::EGFT_BITMAP)
66+
bitfont = (gui::IGUIFontBitmap*)builtinfont;
67+
68+
gui::IGUISpriteBank* bank = 0;
69+
skin->setFont(builtinfont);
70+
71+
if (bitfont)
72+
bank = bitfont->getSpriteBank();
73+
74+
skin->setSpriteBank(bank);
75+
76+
return skin;
77+
}
78+
79+
5580
RenderingEngine::RenderingEngine(IEventReceiver *receiver)
5681
{
5782
sanity_check(!s_singleton);
@@ -112,6 +137,11 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
112137
driver = m_device->getVideoDriver();
113138

114139
s_singleton = this;
140+
141+
auto skin = createSkin(m_device->getGUIEnvironment(),
142+
gui::EGST_WINDOWS_METALLIC, driver);
143+
m_device->getGUIEnvironment()->setSkin(skin);
144+
skin->drop();
115145
}
116146

117147
RenderingEngine::~RenderingEngine()
@@ -193,7 +223,7 @@ bool RenderingEngine::setupTopLevelWindow(const std::string &name)
193223
// sort here that would call the correct toplevel setup methods for
194224
// the environment Minetest is running in but for now not deviating
195225
// from the original pattern.
196-
226+
197227
/* Setting Xorg properties for the top level window */
198228
setupTopLevelXorgWindow(name);
199229
/* Done with Xorg properties */
@@ -211,7 +241,7 @@ bool RenderingEngine::setupTopLevelWindow(const std::string &name)
211241
/* Done with general properties */
212242

213243
// FIXME: setWindowIcon returns a bool result but it is unused.
214-
// For now continue to return this result.
244+
// For now continue to return this result.
215245
return result;
216246
}
217247

@@ -223,7 +253,7 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
223253
Display *x11_dpl = reinterpret_cast<Display *>(exposedData.OpenGLLinux.X11Display);
224254
if (x11_dpl == NULL) {
225255
warningstream << "Client: Could not find X11 Display in ExposedVideoData"
226-
<< std::endl;
256+
<< std::endl;
227257
return;
228258
}
229259

@@ -244,30 +274,30 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
244274

245275
// FIXME: In the future WMNormalHints should be set ... e.g see the
246276
// gtk/gdk code (gdk/x11/gdksurface-x11.c) for the setup_top_level
247-
// method. But for now (as it would require some significant changes)
248-
// leave the code as is.
249-
277+
// method. But for now (as it would require some significant changes)
278+
// leave the code as is.
279+
250280
// The following is borrowed from the above gdk source for setting top
251281
// level windows. The source indicates and the Xlib docs suggest that
252-
// this will set the WM_CLIENT_MACHINE and WM_LOCAL_NAME. This will not
253-
// set the WM_CLIENT_MACHINE to a Fully Qualified Domain Name (FQDN) which is
282+
// this will set the WM_CLIENT_MACHINE and WM_LOCAL_NAME. This will not
283+
// set the WM_CLIENT_MACHINE to a Fully Qualified Domain Name (FQDN) which is
254284
// required by the Extended Window Manager Hints (EWMH) spec when setting
255285
// the _NET_WM_PID (see further down) but running Minetest in an env
256286
// where the window manager is on another machine from Minetest (therefore
257287
// making the PID useless) is not expected to be a problem. Further
258288
// more, using gtk/gdk as the model it would seem that not using a FQDN is
259289
// not an issue for modern Xorg window managers.
260-
290+
261291
verbosestream << "Client: Setting Xorg window manager Properties"
262292
<< std::endl;
263293

264294
XSetWMProperties (x11_dpl, x11_win, NULL, NULL, NULL, 0, NULL, NULL, NULL);
265295

266-
// Set the _NET_WM_PID window property according to the EWMH spec. _NET_WM_PID
267-
// (in conjunction with WM_CLIENT_MACHINE) can be used by window managers to
268-
// force a shutdown of an application if it doesn't respond to the destroy
269-
// window message.
270-
296+
// Set the _NET_WM_PID window property according to the EWMH spec. _NET_WM_PID
297+
// (in conjunction with WM_CLIENT_MACHINE) can be used by window managers to
298+
// force a shutdown of an application if it doesn't respond to the destroy
299+
// window message.
300+
271301
verbosestream << "Client: Setting Xorg _NET_WM_PID extened window manager property"
272302
<< std::endl;
273303

@@ -277,12 +307,12 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
277307
infostream << "Client: PID is '" << static_cast<long>(pid) << "'"
278308
<< std::endl;
279309

280-
XChangeProperty(x11_dpl, x11_win, NET_WM_PID,
281-
XA_CARDINAL, 32, PropModeReplace,
310+
XChangeProperty(x11_dpl, x11_win, NET_WM_PID,
311+
XA_CARDINAL, 32, PropModeReplace,
282312
reinterpret_cast<unsigned char *>(&pid),1);
283313

284314
// Set the WM_CLIENT_LEADER window property here. Minetest has only one
285-
// window and that window will always be the leader.
315+
// window and that window will always be the leader.
286316

287317
verbosestream << "Client: Setting Xorg WM_CLIENT_LEADER property"
288318
<< std::endl;

‎src/gui/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(gui_SRCS
2+
${CMAKE_CURRENT_SOURCE_DIR}/guiButton.cpp
23
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
34
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
45
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
@@ -8,6 +9,7 @@ set(gui_SRCS
89
${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp
910
${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp
1011
${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp
1113
${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp
1214
${CMAKE_CURRENT_SOURCE_DIR}/guiVolumeChange.cpp
1315
${CMAKE_CURRENT_SOURCE_DIR}/intlGUIEditBox.cpp

0 commit comments

Comments
 (0)
Please sign in to comment.