Skip to content

Commit

Permalink
GTK3 Support for Linux build (#964)
Browse files Browse the repository at this point in the history
* Add support for wxWidgets built with GTK3

Specify -DWX_GTK3=ON when configuring cmake

Seems to work fine for the most part, except for the splash window which doesn't want to show at all

* Make GTK3 the default option

* Improved cmake wxWidgets detection and ability to specify wx lib path

Should properly detect installed wx libs now, default cmake findwxwidgets module seems to have broken at some point.

This should also allow the path to a custom built wx to be specified via the WITH_WXPATH option (untested)

wx detection cmake script taken from CodeLite

* Ensure UI scale doesn't go below 1x

For some reason gtk3 reports 75dpi

* Use default spin control size in linux

* Force inactive text colour in wxPropertyGrid

* Ensure wx-config selects gtk3 when WX_GTK3 cmake option is enabled

* Fix calltip border being cut off

Not sure how this didn't affect Windows tbh

* Use custom GL angle control for thing angle selection

Since the one using radio buttons was broken on anything but windows. This one I had intended to use ages ago but it didn't work properly in linux for some reason. Seems ok now, need to test it in windows and macos

* Ensure preferences page title text doesn't get cut off

* Fix base resource dropdown size being too small for some gtk themes
  • Loading branch information
sirjuddington authored Nov 25, 2018
1 parent d23d61c commit 66879ff
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 121 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(SLADE_OUTPUT_DIR ${CMAKE_BINARY_DIR} CACHE PATH "Directory where slade will

OPTION(NO_WEBVIEW "Disable wxWebview usage (for start page and documentation)" OFF)
OPTION(USE_SFML_RENDERWINDOW "Use SFML RenderWindow for OpenGL displays" OFF)
OPTION(WX_GTK3 "Use GTK3 (if wx is built with it)" ON)

# c++14 is required to compile
if(CMAKE_VERSION VERSION_LESS 3.1)
Expand Down
2 changes: 2 additions & 0 deletions src/Application/SLADEWxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ bool SLADEWxApp::OnInit()
// Calculate scaling factor (from system ppi)
wxMemoryDC dc;
double ui_scale = (double)(dc.GetPPI().x) / 96.0;
if (ui_scale < 1.)
ui_scale = 1.;
#endif // __APPLE__

// Get Windows version
Expand Down
73 changes: 71 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,50 @@ if(NOT WX_VERSION)
endif(NOT WX_VERSION)

# wxWidgets libs
if (WITH_WXPATH)
set(ENV{PATH} ${WITH_WXPATH}:$ENV{PATH})
endif()
unset(WITH_WXPATH CACHE)

set( CL_WX_CONFIG wx-config )

if (UNIX OR MINGW)
execute_process(COMMAND which ${CL_WX_CONFIG} OUTPUT_VARIABLE WX_TOOL OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT WX_TOOL)
message(FATAL_ERROR
"\nNo functional wx_config script was found in your PATH.\nIs the wxWidgets development package installed?\nIf you built wxWidgets yourself, you can specify the path to your built wx-config executable via WITH_WXPATH\neg. -DWITH_WXPATH=\"/path/to/wx-config/\""
)
else()
execute_process(COMMAND sh ${WX_TOOL} --version OUTPUT_VARIABLE WX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(SUBSTRING "${WX_VERSION}" "0" "1" wxMAJOR_VERSION)
string(SUBSTRING "${WX_VERSION}" "2" "1" wxMINOR_VERSION)
string(SUBSTRING "${WX_VERSION}" "4" "1" wxRELEASE_NUMBER)
if ( wxMAJOR_VERSION LESS 3 )
message(FATAL_ERROR
"\nBuilding SLADE requires at least wxWidgets-3.0.0"
)
endif()
if (MINGW)
execute_process(COMMAND sh ${WX_TOOL} --debug=no --rescomp OUTPUT_VARIABLE WX_RC_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "windres" "" WX_RC_FLAGS ${WX_RC_FLAGS})
set (CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} ${WX_RC_FLAGS}")
add_definitions(-D__WXMSW__)
endif (MINGW)
endif()
message("-- wx-config used is: ${WX_TOOL}")
message("-- wxWidgets version is: ${WX_VERSION}")
if (NOT APPLE AND NOT MINGW)
# Is the wx we are using built on gtk2 or 3?
execute_process(COMMAND ${WX_TOOL} --selected_config OUTPUT_VARIABLE WX_GTK_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(SUBSTRING "${WX_GTK_VERSION}" "3" "1" GTK_VERSION)
message("-- gtk version is: ${GTK_VERSION}")
endif()
endif (UNIX OR MINGW)

if (WX_GTK3)
set(wxWidgets_CONFIG_OPTIONS --toolkit=gtk3)
endif (WX_GTK3)

SET(WX_LIBS std aui gl stc richtext propgrid media)
if (NO_WEBVIEW)
SET(WX_LIBS ${WX_LIBS} html)
Expand Down Expand Up @@ -41,7 +85,11 @@ if (APPLE)
# Although, GLib is required by FluidSynth
pkg_check_modules (GLib REQUIRED glib-2.0)
else (APPLE)
if (WX_GTK3)
pkg_check_modules (GTK3 REQUIRED gtk+-3.0)
else (WX_GTK3)
pkg_check_modules (GTK2 REQUIRED gtk+-2.0)
endif (WX_GTK3)
endif (APPLE)

if(NOT NO_FLUIDSYNTH)
Expand All @@ -57,7 +105,23 @@ find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(Freetype REQUIRED)
find_package(CURL REQUIRED)
include_directories(${FREEIMAGE_INCLUDE_DIR} ${SFML_INCLUDE_DIR} ${FTGL_INCLUDE_DIR} ${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${GTK2_INCLUDE_DIRS} ${CURL_INCLUDE_DIR} . ./External/dumb ./Application)
include_directories(
${FREEIMAGE_INCLUDE_DIR}
${SFML_INCLUDE_DIR}
${FTGL_INCLUDE_DIR}
${FREETYPE_INCLUDE_DIRS}
${GLEW_INCLUDE_PATH}
${CURL_INCLUDE_DIR}
.
./External/dumb
./Application
)

if (WX_GTK3)
include_directories(${GTK3_INCLUDE_DIRS})
else (WX_GTK3)
include_directories(${GTK2_INCLUDE_DIRS})
endif (WX_GTK3)

if (NOT NO_FLUIDSYNTH)
include_directories(${FLUIDSYNTH_INCLUDE_DIR})
Expand Down Expand Up @@ -117,10 +181,15 @@ target_link_libraries(slade
${OPENGL_LIBRARIES}
${FREETYPE_LIBRARIES}
${GLEW_LIBRARY}
${GTK2_LIBRARIES}
${CURL_LIBRARIES}
)

if (WX_GTK3)
target_link_libraries(slade ${GTK3_LIBRARIES})
else(WX_GTK3)
target_link_libraries(slade ${GTK2_LIBRARIES})
endif(WX_GTK3)

if (NOT NO_FLUIDSYNTH)
target_link_libraries(slade ${FLUIDSYNTH_LIBRARIES})
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/Dialogs/Preferences/AdvancedPrefsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ AdvancedPrefsPanel::AdvancedPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(sizer);

const wxColour& inactiveTextColour =
wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT);

// Add property grid
pg_cvars_ = new wxPropertyGrid(
this,
Expand All @@ -60,6 +63,8 @@ AdvancedPrefsPanel::AdvancedPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent
wxDefaultSize,
wxPG_BOLD_MODIFIED | wxPG_SPLITTER_AUTO_CENTER | wxPG_TOOLTIPS | wxPG_HIDE_MARGIN
);
pg_cvars_->SetCaptionTextColour(inactiveTextColour);
pg_cvars_->SetCellDisabledTextColour(inactiveTextColour);
sizer->Add(pg_cvars_, 1, wxEXPAND);

// Init property grid
Expand Down
5 changes: 5 additions & 0 deletions src/Dialogs/Preferences/ColourPrefsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ ColourPrefsPanel::ColourPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent)
choice_configs_->Append(cnames[a]);
sizer->Add(WxUtils::createLabelHBox(this, "Preset:", choice_configs_), 0, wxEXPAND | wxBOTTOM, UI::pad());

const wxColour& inactiveTextColour =
wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT);

// Create property grid
pg_colours_ = new wxPropertyGrid(
this,
Expand All @@ -71,6 +74,8 @@ ColourPrefsPanel::ColourPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent)
wxDefaultSize,
wxPG_BOLD_MODIFIED | wxPG_SPLITTER_AUTO_CENTER | wxPG_TOOLTIPS
);
pg_colours_->SetCaptionTextColour(inactiveTextColour);
pg_colours_->SetCellDisabledTextColour(inactiveTextColour);
sizer->Add(pg_colours_, 1, wxEXPAND);

// Load colour config into grid
Expand Down
1 change: 1 addition & 0 deletions src/Dialogs/Preferences/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ wxSizer* createTitleSizer(wxWindow* parent, const string& title, const string& d
auto title_label = new wxStaticText(parent, -1, title);
auto font = title_label->GetFont();
title_label->SetFont(font.MakeLarger().MakeLarger().MakeBold());
title_label->SetMinSize(wxSize(-1, title_label->GetTextExtent("Wy").y));
sizer->Add(title_label, 0, wxEXPAND);

// Description
Expand Down
5 changes: 4 additions & 1 deletion src/General/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void UI::init(double scale)
px_pad = 12 * scale;
px_pad_min = 3 * scale;
px_splitter = 10 * scale;
px_spin_width = 64 * scale;
if (App::platform() == App::Platform::Linux)
px_spin_width = -1;
else
px_spin_width = 64 * scale;
}

void UI::enableSplash(bool enable)
Expand Down
9 changes: 9 additions & 0 deletions src/MapEditor/UI/PropsPanel/MapObjectPropsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ MapObjectPropsPanel::MapObjectPropsPanel(wxWindow* parent, bool no_apply) :
stc_sections_ = STabCtrl::createControl(this);
sizer->Add(stc_sections_, 1, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, UI::pad());

const wxColour& inactiveTextColour =
wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT);

// Add main property grid
pg_properties_ = new wxPropertyGrid(
stc_sections_,
Expand All @@ -87,6 +90,8 @@ MapObjectPropsPanel::MapObjectPropsPanel(wxWindow* parent, bool no_apply) :
wxDefaultSize,
wxPG_TOOLTIPS|wxPG_SPLITTER_AUTO_CENTER
);
pg_properties_->SetCaptionTextColour(inactiveTextColour);
pg_properties_->SetCellDisabledTextColour(inactiveTextColour);
stc_sections_->AddPage(pg_properties_, "Properties");

// Create side property grids
Expand All @@ -97,13 +102,17 @@ MapObjectPropsPanel::MapObjectPropsPanel(wxWindow* parent, bool no_apply) :
wxDefaultSize,
wxPG_TOOLTIPS|wxPG_SPLITTER_AUTO_CENTER
);
pg_props_side1_->SetCaptionTextColour(inactiveTextColour);
pg_props_side1_->SetCellDisabledTextColour(inactiveTextColour);
pg_props_side2_ = new wxPropertyGrid(
stc_sections_,
-1,
wxDefaultPosition,
wxDefaultSize,
wxPG_TOOLTIPS|wxPG_SPLITTER_AUTO_CENTER
);
pg_props_side2_->SetCaptionTextColour(inactiveTextColour);
pg_props_side2_->SetCellDisabledTextColour(inactiveTextColour);

// Add buttons
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
Expand Down
Loading

0 comments on commit 66879ff

Please sign in to comment.