Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Scale (fit)" background image mode #2023

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions data/gsettings/com.gexperts.Tilix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
<!-- Background Image Options -->
<enum id='com.gexperts.Tilix.Background.Image.Mode'>
<value nick='scale' value='0'/>
<value nick='tile' value='1'/>
<value nick='center' value='2'/>
<value nick='stretch' value='3'/>
<value nick='scale-fit' value='1'/>
<value nick='tile' value='2'/>
<value nick='center' value='3'/>
<value nick='stretch' value='4'/>
</enum>

<!-- Background Image Scaling Options, note these
Expand Down
5 changes: 3 additions & 2 deletions source/gx/gtk/cairo.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Pixbuf getWidgetImage(Widget widget, double factor, int width, int height) {
}
}

enum ImageLayoutMode {SCALE, TILE, CENTER, STRETCH};
enum ImageLayoutMode {SCALE, SCALE_FIT, TILE, CENTER, STRETCH};

ImageSurface renderImage(Pixbuf pb, bool alpha = false) {
cairo_format_t format = alpha?cairo_format_t.ARGB32:cairo_format_t.RGB24;
Expand Down Expand Up @@ -161,9 +161,10 @@ void renderImage(Context cr, ImageSurface isSource, int outputWidth, int outputH
}
final switch (mode) {
case ImageLayoutMode.SCALE:
case ImageLayoutMode.SCALE_FIT:
double xScale = to!double(outputWidth) / to!double(isSource.getWidth());
double yScale = to!double(outputHeight) / to!double(isSource.getHeight());
double ratio = max(xScale, yScale);
double ratio = mode == ImageLayoutMode.SCALE ? max(xScale, yScale) : min(xScale, yScale);
double xOffset = (outputWidth - (isSource.getWidth() * ratio)) / 2.0;
double yOffset = (outputHeight - (isSource.getHeight() * ratio)) / 2.0;
cr.translate(xOffset, yOffset);
Expand Down
3 changes: 3 additions & 0 deletions source/gx/tilix/appwindow.d
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,9 @@ public:
case SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_VALUE:
mode = ImageLayoutMode.SCALE;
break;
case SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_FIT_VALUE:
mode = ImageLayoutMode.SCALE_FIT;
break;
case SETTINGS_BACKGROUND_IMAGE_MODE_TILE_VALUE:
mode = ImageLayoutMode.TILE;
break;
Expand Down
2 changes: 1 addition & 1 deletion source/gx/tilix/prefeditor/prefdialog.d
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ class AppearancePreferences: Box {
gsSettings.reset(SETTINGS_BACKGROUND_IMAGE_KEY);
});

ComboBox cbImageMode = createNameValueCombo([_("Scale"), _("Tile"), _("Center"),_("Stretch")], SETTINGS_BACKGROUND_IMAGE_MODE_VALUES);
ComboBox cbImageMode = createNameValueCombo([_("Scale"), _("Scale (fit)"), _("Tile"), _("Center"),_("Stretch")], SETTINGS_BACKGROUND_IMAGE_MODE_VALUES);
bh.bind(SETTINGS_BACKGROUND_IMAGE_MODE_KEY, cbImageMode, "active-id", GSettingsBindFlags.DEFAULT);

// Background image settings only enabled if transparency is enabled
Expand Down
3 changes: 2 additions & 1 deletion source/gx/tilix/preferences.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ enum SETTINGS_BACKGROUND_IMAGE_KEY = "background-image";
enum SETTINGS_BACKGROUND_IMAGE_SCALE_KEY = "background-image-scale";
enum SETTINGS_BACKGROUND_IMAGE_MODE_KEY = "background-image-mode";
enum SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_VALUE = "scale";
enum SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_FIT_VALUE = "scale-fit";
enum SETTINGS_BACKGROUND_IMAGE_MODE_TILE_VALUE = "tile";
enum SETTINGS_BACKGROUND_IMAGE_MODE_CENTER_VALUE = "center";
enum SETTINGS_BACKGROUND_IMAGE_MODE_STRETCH_VALUE = "stretch";
immutable string[] SETTINGS_BACKGROUND_IMAGE_MODE_VALUES = [SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_TILE_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_CENTER_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_STRETCH_VALUE];
immutable string[] SETTINGS_BACKGROUND_IMAGE_MODE_VALUES = [SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_SCALE_FIT_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_TILE_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_CENTER_VALUE,SETTINGS_BACKGROUND_IMAGE_MODE_STRETCH_VALUE];

enum SETTINGS_SIDEBAR_RIGHT = "sidebar-on-right";
enum SETTINGS_RECENT_SESSION_FILES_KEY = "recent-session-files";
Expand Down