@@ -26,7 +26,11 @@
|
||||
#include "rtimage.h"
|
||||
#include "whitebalance.h"
|
||||
|
||||
extern int scale;
|
||||
float fontScale = 1.f;
|
||||
Glib::RefPtr<Gtk::CssProvider> cssForced;
|
||||
Glib::RefPtr<Gtk::CssProvider> cssRT;
|
||||
|
||||
extern unsigned char initialGdkScale;
|
||||
|
||||
#if defined(__APPLE__)
|
||||
static gboolean
|
||||
@@ -99,6 +103,136 @@ RTWindow::RTWindow ()
|
||||
ProfilePanel::init (this);
|
||||
MyExpander::init();
|
||||
|
||||
// ------- loading theme files
|
||||
|
||||
Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
|
||||
|
||||
if (screen) {
|
||||
Gtk::Settings::get_for_screen (screen)->property_gtk_theme_name() = "Adwaita";
|
||||
Gtk::Settings::get_for_screen (screen)->property_gtk_application_prefer_dark_theme() = true;
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// This will force screen resolution regarding font, but I don't think it's compliant with Gtk guidelines...
|
||||
// Do not confuse with screen scaling, where everything is scaled up !
|
||||
screen->set_resolution (96.);
|
||||
#endif
|
||||
|
||||
Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create (THEMEREGEXSTR, Glib::RegexCompileFlags::REGEX_CASELESS);
|
||||
Glib::ustring filename;
|
||||
Glib::MatchInfo mInfo;
|
||||
bool match = regex->match(options.theme + ".css", mInfo);
|
||||
if (match) {
|
||||
// save old theme (name + version)
|
||||
Glib::ustring initialTheme(options.theme);
|
||||
|
||||
// update version
|
||||
auto pos = options.theme.find("-GTK3-");
|
||||
Glib::ustring themeRootName(options.theme.substr(0, pos));
|
||||
if (GTK_MINOR_VERSION < 20) {
|
||||
options.theme = themeRootName + "-GTK3-_19";
|
||||
} else {
|
||||
options.theme = themeRootName + "-GTK3-20_";
|
||||
}
|
||||
// check if this version exist
|
||||
if (!Glib::file_test(Glib::build_filename(argv0, "themes", options.theme + ".css"), Glib::FILE_TEST_EXISTS)) {
|
||||
// set back old theme version if the actual one doesn't exist yet
|
||||
options.theme = initialTheme;
|
||||
}
|
||||
}
|
||||
filename = Glib::build_filename(argv0, "themes", options.theme + ".css");
|
||||
|
||||
if (!match || !Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
|
||||
options.theme = "RawTherapee-GTK";
|
||||
|
||||
// We're not testing GTK_MAJOR_VERSION == 3 here, since this branch requires Gtk3 only
|
||||
if (GTK_MINOR_VERSION < 20) {
|
||||
options.theme = options.theme + "3-_19";
|
||||
} else {
|
||||
options.theme = options.theme + "3-20_";
|
||||
}
|
||||
|
||||
filename = Glib::build_filename (argv0, "themes", options.theme + ".css");
|
||||
}
|
||||
|
||||
cssRT = Gtk::CssProvider::create();
|
||||
|
||||
try {
|
||||
cssRT->load_from_path (filename);
|
||||
Gtk::StyleContext::add_provider_for_screen (screen, cssRT, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
} catch (Glib::Error &err) {
|
||||
printf ("Error: Can't load css file \"%s\"\nMessage: %s\n", filename.c_str(), err.what().c_str());
|
||||
} catch (...) {
|
||||
printf ("Error: Can't load css file \"%s\"\n", filename.c_str());
|
||||
}
|
||||
|
||||
// Set the font face and size
|
||||
Glib::ustring css;
|
||||
if (options.fontFamily != "default") {
|
||||
//GTK318
|
||||
#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION < 20
|
||||
css = Glib::ustring::compose ("* { font-family: %1; font-size: %2px}", options.fontFamily, options.fontSize * (int)initialGdkScale);
|
||||
#else
|
||||
css = Glib::ustring::compose ("* { font-family: %1; font-size: %2pt}", options.fontFamily, options.fontSize * (int)initialGdkScale);
|
||||
#endif
|
||||
//GTK318
|
||||
fontScale = options.fontSize / 9.f;
|
||||
printf("\"Non-Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", options.fontSize, (int)initialGdkScale, fontScale);
|
||||
} else {
|
||||
Glib::RefPtr<Gtk::StyleContext> style = Gtk::StyleContext::create();
|
||||
Pango::FontDescription pfd = style->get_font(Gtk::STATE_FLAG_NORMAL);
|
||||
int pt;
|
||||
if (pfd.get_set_fields() & Pango::FONT_MASK_SIZE) {
|
||||
int fontSize = pfd.get_size();
|
||||
bool isPix = pfd.get_size_is_absolute();
|
||||
int resolution = (int)style->get_screen()->get_resolution();
|
||||
if (isPix) {
|
||||
// HOMBRE: guessing here...
|
||||
// if resolution is lower than 192ppi, we're supposing that it's already expressed in a scale==1 scenario
|
||||
if (resolution >= 192) {
|
||||
// converting the resolution to a scale==1 scenario
|
||||
resolution /= 2;
|
||||
}
|
||||
// 1pt = 1/72in @ 96 ppi
|
||||
// HOMBRE: If the font unit is px, is it alredy scaled up to match the resolution ?
|
||||
// px >inch >pt >"scaled pt"
|
||||
pt = (int)(fontSize / 96. * 72 * (96. / resolution) + 0.49);
|
||||
} else {
|
||||
pt = fontSize / Pango::SCALE;
|
||||
}
|
||||
fontScale = (float)pt / 9.f;
|
||||
if ((int)initialGdkScale > 1 || pt != 9) {
|
||||
css = Glib::ustring::compose ("* { font-size: %1pt}", pt * (int)initialGdkScale);
|
||||
printf("\"Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", pt, (int)initialGdkScale, fontScale);
|
||||
}
|
||||
} else {
|
||||
fontScale = 1.f;
|
||||
}
|
||||
}
|
||||
if (!css.empty()) {
|
||||
printf("CSS:\n%s\n\n", css.c_str());
|
||||
try {
|
||||
cssForced = Gtk::CssProvider::create();
|
||||
cssForced->load_from_data (css);
|
||||
|
||||
Gtk::StyleContext::add_provider_for_screen (screen, cssForced, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
} catch (Glib::Error &err) {
|
||||
printf ("Error: \"%s\"\n", err.what().c_str());
|
||||
} catch (...) {
|
||||
printf ("Error: Can't find the font named \"%s\"\n", options.fontFamily.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
else if (!screen) {
|
||||
printf ("ERROR: Can't get default screen!\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ------- end loading theme files
|
||||
|
||||
#ifndef WIN32
|
||||
const std::vector<Glib::RefPtr<Gdk::Pixbuf>> appIcons = {
|
||||
RTImage::createPixbufFromFile("rawtherapee-logo-16.png"),
|
||||
@@ -405,10 +539,11 @@ bool RTWindow::on_configure_event (GdkEventConfigure* event)
|
||||
get_position (options.windowX, options.windowY);
|
||||
}
|
||||
|
||||
int newScale = scale;
|
||||
double newDPI = get_window()->get_screen()->get_resolution();
|
||||
RTImage::setDPInScale(newDPI, newScale); // will update the RTImage on scale/resolution change
|
||||
RTSurface::setDPInScale(newDPI, newScale); // will update the RTSurface on scale/resolution change
|
||||
//int newScale = rtengine::max((int)initialGdkScale, get_window()->get_scale_factor());
|
||||
//double newDPI = get_window()->get_screen()->get_resolution();
|
||||
printf("RTWindow::on_configure_event / newScale:%d / newDPI: %.3f\n", RTScalable::getScale(), RTScalable::getDPI());
|
||||
RTImage::setDPInScale(RTScalable::getDPI(), RTScalable::getScale()); // will update the RTImage on scale/resolution change
|
||||
RTSurface::setDPInScale(RTScalable::getDPI(), RTScalable::getScale()); // will update the RTSurface on scale/resolution change
|
||||
|
||||
return Gtk::Widget::on_configure_event (event);
|
||||
}
|
||||
|
Reference in New Issue
Block a user