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

Editor Previews - Improve support for images with non-16/9 aspect ratios #600

Merged
merged 2 commits into from
Oct 13, 2021
Merged
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
9 changes: 8 additions & 1 deletion addons/editor_previews/functions/fnc_handleMouseUpdate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ if (_type isEqualTo "") then {
_ctrlGroup ctrlShow false;
};

getTextureInfo _image params ["_width", "_height"];
private _ratio = _width / _height;

private _ctrlImage = _display displayCtrl IDC_PREVIEW_IMAGE;
_ctrlImage ctrlSetPositionW POS_W(IMAGE_HEIGHT * _ratio);
_ctrlImage ctrlSetText _image;
_ctrlImage ctrlCommit 0;

_ctrlGroup ctrlShow true;
_ctrlGroup ctrlSetPositionY (getMousePosition select 1) min (safeZoneY + safeZoneH - POS_H(5.6));
_ctrlGroup ctrlSetPositionX (safeZoneX + safeZoneW - POS_W(POS_EDGE(12.5,11) + IMAGE_HEIGHT * _ratio + 3 * BORDER_SIZE));
Kexanone marked this conversation as resolved.
Show resolved Hide resolved
_ctrlGroup ctrlSetPositionY (getMousePosition select 1) min (safeZoneY + safeZoneH - POS_H(IMAGE_HEIGHT + 3 * BORDER_SIZE));
_ctrlGroup ctrlSetPositionW POS_W(IMAGE_HEIGHT * _ratio + 2 * BORDER_SIZE);
_ctrlGroup ctrlCommit 0;
};

Expand Down
5 changes: 5 additions & 0 deletions addons/editor_previews/functions/fnc_initDisplayCurator.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ if (!GVAR(enabled)) exitWith {};

params ["_display"];

// Disable pixel rounding to fix inconsistent border size for images with different aspect ratios
private _ctrlGroup = _display ctrlCreate [QGVAR(control), IDC_PREVIEW_GROUP];
_ctrlGroup ctrlSetPixelPrecision 2;
_ctrlGroup ctrlShow false;

private _ctrlImage = _display displayCtrl IDC_PREVIEW_IMAGE;
_ctrlImage ctrlSetPixelPrecision 2;

{
private _ctrlTree = _display displayCtrl _x;
_ctrlTree ctrlAddEventHandler ["TreeMouseMove", {call FUNC(handleMouseUpdate)}];
Expand Down
18 changes: 9 additions & 9 deletions addons/editor_previews/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ class ctrlControlsGroupNoScrollbars;

class GVAR(control): ctrlControlsGroupNoScrollbars {
idc = IDC_PREVIEW_GROUP;
x = safeZoneX + safeZoneW - POS_EDGE(12.5,11) * GUI_GRID_W - POS_W(9.8);
x = 0;
y = 0;
w = POS_W(9.6);
h = POS_H(5.4);
w = 0;
h = POS_H(IMAGE_HEIGHT + 2 * BORDER_SIZE);
class controls {
class Background: ctrlStatic {
idc = -1;
x = 0;
y = 0;
w = POS_W(9.6);
h = POS_H(5.4);
w = 1;
h = 1;
colorBackground[] = {0.1, 0.1, 0.1, 0.5};
};
class Image: ctrlStaticPictureKeepAspect {
idc = IDC_PREVIEW_IMAGE;
x = POS_W(0.1);
y = POS_H(0.1);
w = POS_W(9.4);
h = POS_H(5.2);
x = POS_W(BORDER_SIZE);
y = POS_H(BORDER_SIZE);
w = 0;
h = POS_H(IMAGE_HEIGHT);
};
};
};
6 changes: 6 additions & 0 deletions addons/editor_previews/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@

#define IDC_PREVIEW_GROUP 98470
#define IDC_PREVIEW_IMAGE 98480

// Height of the image - other control positions are based on this value and the aspect ratio of the image
#define IMAGE_HEIGHT 5.2

// Size of the border around the image on one side
#define BORDER_SIZE 0.2