Skip to content

Commit

Permalink
Allow Gource to render at native resolution on High DPI displays
Browse files Browse the repository at this point in the history
  • Loading branch information
acaudwell committed Mar 3, 2022
1 parent 745f14e commit 0419ef1
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 22 deletions.
8 changes: 8 additions & 0 deletions gource.pro
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,11 @@ HEADERS += \
core/timezone.h \
core/vbo.h \
core/vectors.h

DISTFILES += \
data/shaders/bloom.frag \
data/shaders/shadow.frag \
data/shaders/text.frag \
data/shaders/bloom.vert \
data/shaders/shadow.vert \
data/shaders/text.vert
2 changes: 1 addition & 1 deletion src/core
Submodule core updated 2 files
+51 −0 display.cpp
+2 −0 display.h
2 changes: 1 addition & 1 deletion src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ RFile::RFile(const std::string & name, const vec3 & colour, const vec2 & pos, in
}

if(!file_font.initialized()) {
file_font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.filename_font_size);
file_font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_filename_font_size);
file_font.dropShadow(true);
file_font.roundCoordinates(false);
file_font.setColour(vec4(gGourceSettings.filename_colour, 1.0f));
Expand Down
26 changes: 16 additions & 10 deletions src/gource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ Gource::Gource(FrameExporter* exporter) {
gGourceSettings.file_graphic = texturemanager.grab("file.png", true, GL_CLAMP_TO_EDGE);
}

fontlarge = fontmanager.grab(gGourceSettings.font_file, 42);
if(gGourceSettings.default_font_scale) {
gGourceSettings.font_scale = (float) glm::max(1, display.width / 1920);
debugLog("setting font scale for resolution %d x %d to %.2f", display.width, display.height, gGourceSettings.font_scale);
gGourceSettings.setScaledFontSizes();
}

fontlarge = fontmanager.grab(gGourceSettings.font_file, 42 * gGourceSettings.font_scale);
fontlarge.dropShadow(true);
fontlarge.roundCoordinates(true);

fontmedium = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.font_size);
fontmedium = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_font_size);
fontmedium.dropShadow(true);
fontmedium.roundCoordinates(false);

Expand All @@ -49,11 +55,11 @@ Gource::Gource(FrameExporter* exporter) {
fontcaption.roundCoordinates(false);
fontcaption.alignTop(false);

font = fontmanager.grab(gGourceSettings.font_file, 14);
font = fontmanager.grab(gGourceSettings.font_file, 14 * gGourceSettings.font_scale);
font.dropShadow(true);
font.roundCoordinates(true);

fontdirname = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.dirname_font_size);
fontdirname = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_dirname_font_size);
fontdirname.dropShadow(true);
fontdirname.roundCoordinates(true);

Expand Down Expand Up @@ -126,7 +132,7 @@ Gource::Gource(FrameExporter* exporter) {
date_x_offset = 0;
starting_z = -300.0f;

textbox = TextBox(fontmanager.grab(gGourceSettings.font_file, 18));
textbox = TextBox(fontmanager.grab(gGourceSettings.font_file, 18 * gGourceSettings.font_scale));
textbox.setBrightness(0.5f);
textbox.show();

Expand Down Expand Up @@ -2601,11 +2607,11 @@ void Gource::draw(float t, float dt) {

if(splash>0.0f) {
int logowidth = fontlarge.getWidth("Gource");
int logoheight = 100;
int logoheight = 100 * gGourceSettings.font_scale;
int cwidth = font.getWidth("Software Version Control Visualization");
int awidth = font.getWidth("(C) 2009 Andrew Caudwell");

vec2 corner(display.width/2 - logowidth/2 - 30.0f, display.height/2 - 40);
vec2 corner(display.width/2 - logowidth/2 - 30.0f * gGourceSettings.font_scale, display.height/2 - 40 * gGourceSettings.font_scale);

glDisable(GL_TEXTURE_2D);
glColor4f(0.0f, 0.5f, 1.0f, splash * 0.015f);
Expand All @@ -2619,11 +2625,11 @@ void Gource::draw(float t, float dt) {
glEnable(GL_TEXTURE_2D);

fontlarge.setColour(vec4(1.0f));
fontlarge.draw(display.width/2 - logowidth/2,display.height/2 - 30, "Gource");
fontlarge.draw(display.width/2 - logowidth/2,display.height/2 - 30 * gGourceSettings.font_scale, "Gource");

font.setColour(vec4(1.0f));
font.draw(display.width/2 - cwidth/2,display.height/2 + 10, "Software Version Control Visualization");
font.draw(display.width/2 - awidth/2,display.height/2 + 30, "(C) 2009 Andrew Caudwell");
font.draw(display.width/2 - cwidth/2,display.height/2 + 10 * gGourceSettings.font_scale, "Software Version Control Visualization");
font.draw(display.width/2 - awidth/2,display.height/2 + 30 * gGourceSettings.font_scale, "(C) 2009 Andrew Caudwell");
}

// text using the specified font goes here
Expand Down
20 changes: 15 additions & 5 deletions src/gource_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,13 @@ void GourceSettings::setGourceDefaults() {
title = "";

font_scale = 1.0f;
default_font_scale = true;
font_file = GOURCE_FONT_FILE;
font_size = 16;
filename_font_size = 14;
dirname_font_size = 14;
user_font_size = 14;

dir_colour = vec3(1.0f);
font_colour = vec3(1.0f);
highlight_colour = vec3(1.0f);
Expand Down Expand Up @@ -505,6 +507,16 @@ void GourceSettings::setGourceDefaults() {
delete (*it);
}
user_show_filters.clear();


setScaledFontSizes();
}

void GourceSettings::setScaledFontSizes() {
scaled_font_size = glm::clamp((int)(font_size * font_scale), 1, 100);
scaled_user_font_size = glm::clamp((int)(user_font_size * font_scale), 1, 100);
scaled_dirname_font_size = glm::clamp((int)(dirname_font_size * font_scale), 1, 100);
scaled_filename_font_size = glm::clamp((int)(filename_font_size * font_scale), 1, 100);
}

void GourceSettings::commandLineOption(const std::string& name, const std::string& value) {
Expand Down Expand Up @@ -1031,16 +1043,14 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
if(!entry->hasValue()) conffile.entryException(entry, "specify font scale");

font_scale = entry->getFloat();
default_font_scale = false;

if(font_scale<0.0f || font_scale>10.0f) {
conffile.invalidValueException(entry);
}

font_size = glm::clamp((int)(font_size * font_scale), 1, 100);
user_font_size = glm::clamp((int)(user_font_size * font_scale), 1, 100);
dirname_font_size = glm::clamp((int)(dirname_font_size * font_scale), 1, 100);
filename_font_size = glm::clamp((int)(filename_font_size * font_scale), 1, 100);
}
setScaledFontSizes();
}

if((entry = gource_settings->getEntry("hash-seed")) != 0) {

Expand Down
8 changes: 8 additions & 0 deletions src/gource_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class GourceSettings : public SDLAppSettings {
int user_font_size;
vec3 font_colour;
float font_scale;
bool default_font_scale;

int scaled_font_size;
int scaled_filename_font_size;
int scaled_dirname_font_size;
int scaled_user_font_size;

float elasticity;

Expand Down Expand Up @@ -167,6 +173,8 @@ class GourceSettings : public SDLAppSettings {

void setGourceDefaults();

void setScaledFontSizes();

void importGourceSettings(ConfFile& conf, ConfSection* gource_settings = 0);

void help(bool extended_help=false);
Expand Down
8 changes: 4 additions & 4 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ FileKeyEntry::FileKeyEntry(const FXFont& font, const std::string& ext, const vec
shadow = vec2(3.0, 3.0);

width = 90.0f * gGourceSettings.font_scale;
height = gGourceSettings.font_size + 4.0f;
left_margin = gGourceSettings.font_size + 4.0f;
height = gGourceSettings.scaled_font_size + 4.0f;
left_margin = gGourceSettings.scaled_font_size + 4.0f;
count = 0;
brightness = 1.0f;
alpha = 0.0f;
Expand Down Expand Up @@ -163,7 +163,7 @@ FileKey::FileKey() {
FileKey::FileKey(float update_interval) {
this->update_interval = update_interval;
interval_remaining = 1.0f;
font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.font_size);
font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_font_size);
font.dropShadow(false);
font.roundCoordinates(false);
show = true;
Expand Down Expand Up @@ -280,7 +280,7 @@ void FileKey::logic(float dt) {
}

//set position
float offset_y = gGourceSettings.font_size + 6.0f;
float offset_y = gGourceSettings.scaled_font_size + 6.0f;
float key_y = offset_y;

for(std::vector<FileKeyEntry*>::iterator it = active_keys.begin(); it != active_keys.end(); it++) {
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ int main(int argc, char *argv[]) {
display.enableResize(true);
}

//Stop OS interfering with the requested resolution on Retina / Ultra HD displays
display.enableHighDPIAwareness(true);

try {

display.init("Gource", gGourceSettings.display_width, gGourceSettings.display_height, gGourceSettings.fullscreen, gGourceSettings.screen);
Expand Down
2 changes: 1 addition & 1 deletion src/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void RUser::updateFont() {
font = fontmanager.grab(gGourceSettings.font_file, 18);
font.dropShadow(true);
} else {
font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.user_font_size);
font = fontmanager.grab(gGourceSettings.font_file, gGourceSettings.scaled_user_font_size);
font.dropShadow(true);
}

Expand Down

0 comments on commit 0419ef1

Please sign in to comment.