Add AboutDialog to GUI and menu.

This commit is contained in:
Joseph Lenox 2018-04-28 20:53:49 -05:00
parent 47354beacc
commit ac24ab827e
4 changed files with 146 additions and 1 deletions

View File

@ -147,7 +147,7 @@ include_directories(${Boost_INCLUDE_DIRS})
set(wxWidgets_USE_STATIC OFF) set(wxWidgets_USE_STATIC OFF)
set(wxWidgets_USE_UNICODE ON) set(wxWidgets_USE_UNICODE ON)
find_package(wxWidgets COMPONENTS base aui core) find_package(wxWidgets COMPONENTS base aui core html)
IF(CMAKE_HOST_UNIX) IF(CMAKE_HOST_UNIX)
#set(Boost_LIBRARIES bsystem bthread bfilesystem) #set(Boost_LIBRARIES bsystem bthread bfilesystem)
@ -165,6 +165,7 @@ IF(wxWidgets_FOUND)
${GUI_LIBDIR}/MainFrame.cpp ${GUI_LIBDIR}/MainFrame.cpp
${GUI_LIBDIR}/GUI.cpp ${GUI_LIBDIR}/GUI.cpp
${GUI_LIBDIR}/Settings.cpp ${GUI_LIBDIR}/Settings.cpp
${GUI_LIBDIR}/AboutDialog.cpp
${GUI_LIBDIR}/misc_ui.cpp ${GUI_LIBDIR}/misc_ui.cpp
) )
#only build GUI lib if building with wx #only build GUI lib if building with wx

98
src/GUI/AboutDialog.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "AboutDialog.hpp"
namespace Slic3r { namespace GUI {
static void link_clicked(wxHtmlLinkEvent& e)
{
wxLaunchDefaultBrowser(e.GetLinkInfo().GetHref());
e.Skip(0);
}
AboutDialog::AboutDialog(wxWindow* parent) : wxDialog(parent, -1, _("About Slic3r"), wxDefaultPosition, wxSize(600, 460), wxCAPTION)
{
auto hsizer { new wxBoxSizer(wxHORIZONTAL) } ;
auto vsizer { new wxBoxSizer(wxVERTICAL) } ;
// logo
auto logo { new AboutDialogLogo(this) };
hsizer->Add(logo, 0, wxEXPAND | wxLEFT | wxRIGHT, 30);
// title
auto title { new wxStaticText(this, -1, "Slic3r", wxDefaultPosition, wxDefaultSize) };
auto title_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
title_font.SetWeight(wxFONTWEIGHT_BOLD);
title_font.SetFamily(wxFONTFAMILY_ROMAN);
title_font.SetPointSize(24);
title->SetFont(title_font);
vsizer->Add(title, 0, wxALIGN_LEFT | wxTOP, 30);
// version
auto version {new wxStaticText(this, -1, wxString("Version ") + wxString(SLIC3R_VERSION), wxDefaultPosition, wxDefaultSize) };
auto version_font { wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
version_font.SetPointSize((the_os == OS::Windows ? 9 : 11));
version->SetFont(version_font);
vsizer->Add(version, 0, wxALIGN_LEFT | wxBOTTOM, 10);
// text
wxString text {""};
text << "<html>"
<< "<body>"
<< "Copyright &copy; 2011-2017 Alessandro Ranellucci. <br />"
<< "<a href=\"http://slic3r.org/\">Slic3r</a> is licensed under the "
<< "<a href=\"http://www.gnu.org/licenses/agpl-3.0.html\">GNU Affero General Public License, version 3</a>."
<< "<br /><br /><br />"
<< "Contributions by Henrik Brix Andersen, Vojtech Bubnik, Nicolas Dandrimont, Mark Hindess, "
<< "Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Kliment Yanev and numerous others. "
<< "Manual by Gary Hodgson. Inspired by the RepRap community. <br />"
<< "Slic3r logo designed by Corey Daniels, <a href=\"http://www.famfamfam.com/lab/icons/silk/\">Silk Icon Set</a> designed by Mark James. "
<< "<br /><br />"
<< "Built on " << build_date << " at git version " << git_version << "."
<< "</body>"
<< "</html>";
auto html {new wxHtmlWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER)};
html->SetBorders(2);
html->SetPage(text);
html->Bind(wxEVT_HTML_LINK_CLICKED, [=](wxHtmlLinkEvent& e){ link_clicked(e); });
vsizer->Add(html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 20);
// buttons
auto buttons = this->CreateStdDialogButtonSizer(wxOK);
this->SetEscapeId(wxID_CLOSE);
vsizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3);
hsizer->Add(vsizer, 1, wxEXPAND, 0);
this->SetSizer(hsizer);
};
AboutDialogLogo::AboutDialogLogo(wxWindow* parent) :
wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize)
{
this->logo = wxBitmap(var("Slic3r_192px.png"), wxBITMAP_TYPE_PNG);
this->SetMinSize(wxSize(this->logo.GetWidth(), this->logo.GetHeight()));
this->Bind(wxEVT_PAINT, [=](wxPaintEvent& e) { this->repaint(e);});
}
void AboutDialogLogo::repaint(wxPaintEvent& event)
{
auto dc { new wxPaintDC(this) };
dc->SetBackgroundMode(wxPENSTYLE_TRANSPARENT);
const auto size {this->GetSize()};
const auto logo_w {this->logo.GetWidth()};
const auto logo_h {this->logo.GetHeight()};
dc->DrawBitmap(this->logo, (size.GetWidth() - logo_w) / 2, (size.GetHeight() - logo_h) / 2, 1);
event.Skip();
}
}} // namespace Slic3r::GUI

41
src/GUI/AboutDialog.hpp Normal file
View File

@ -0,0 +1,41 @@
#ifndef ABOUTDIALOG_HPP
#define ABOUTDIALOG_HPP
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/settings.h>
#include <wx/colour.h>
#include <wx/html/htmlwin.h>
#include <wx/event.h>
#include <string>
#include "libslic3r.h"
#include "misc_ui.hpp"
#ifndef SLIC3R_BUILD_COMMIT
#define SLIC3R_BUILD_COMMIT "(Unknown revision)"
#endif
namespace Slic3r { namespace GUI {
const wxString build_date {__DATE__};
const wxString git_version {SLIC3R_BUILD_COMMIT};
class AboutDialogLogo : public wxPanel {
private:
wxBitmap logo;
public:
AboutDialogLogo(wxWindow* parent);
void repaint(wxPaintEvent& event);
};
class AboutDialog : public wxDialog {
public:
/// Build and show the About popup.
AboutDialog(wxWindow* parent);
};
}} // namespace Slic3r::GUI
#endif // ABOUTDIALOG_HPP

View File

@ -3,6 +3,8 @@
#include <wx/accel.h> #include <wx/accel.h>
#include <wx/utils.h> #include <wx/utils.h>
#include "AboutDialog.hpp"
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) wxBEGIN_EVENT_TABLE(MainFrame, wxFrame)
@ -151,6 +153,9 @@ void MainFrame::init_menubar()
}); });
append_menu_item(menuHelp, _("&About Slic3r"), _("Show about dialog"), [=](wxCommandEvent& e) append_menu_item(menuHelp, _("&About Slic3r"), _("Show about dialog"), [=](wxCommandEvent& e)
{ {
auto about = new AboutDialog(nullptr);
about->ShowModal();
about->Destroy();
}, wxID_ABOUT); }, wxID_ABOUT);
} }