mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 12:00:31 +01:00
Added ScaleX and ScaleY macros to WINGs
To reduce code duplication the ScaleX and ScaleY macros have been
moved to WUtil.h. Along with the function WMGetScaleBaseFromSystemFont
these macros can be used in all panels to scale the widgets based on
the current system font size instead of giving fixed pixel sizes which
messes up the panels if a larger system font is selected in WPrefs.
Use the macros in the following way:
instead of WMResizeWidget(widget, 128, 64);
WMMoveWidget(widget, 32, 32);
use int fw, fh;
WMGetScaleBaseFromSystemFont(scr->wmscreen, &fw, &fh);
WMResizeWidget(widget, ScaleX(128), ScaleY(64));
WMMoveWidget(widget, ScaleX(32), ScaleY(32));
This commit is contained in:
committed by
Carlos R. Mafra
parent
8f29bdc690
commit
b185d46286
@@ -795,6 +795,8 @@ char* WMGetFontName(WMFont *font);
|
||||
|
||||
unsigned int WMFontHeight(WMFont *font);
|
||||
|
||||
void WMGetScaleBaseFromSystemFont(WMScreen *scrPtr, int *alphabetWidth, int *fontHeight);
|
||||
|
||||
void WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font);
|
||||
|
||||
void WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font);
|
||||
|
||||
@@ -193,6 +193,16 @@ typedef void WMNotificationObserverAction(void *observerData,
|
||||
sizeof(array) / sizeof(array[0]); \
|
||||
})
|
||||
|
||||
/* These macros can be used to adjust the location and size pixel values in
|
||||
* the panel layouts so that they match the configured size of the system
|
||||
* font (useful with high DPI screens, where you have to increase this size).
|
||||
* The macros require two local variables to be set:
|
||||
* fw: the width of the alphabet in the current system font
|
||||
* fh: the height of the current system font
|
||||
* Use the WMGetScaleBaseFromSystemFont function to set these values.
|
||||
*/
|
||||
#define ScaleX(value) ((int)((double)value / 164.0 * (double)fw + 0.5))
|
||||
#define ScaleY(value) ((int)((double)value / 14.0 * (double)fh + 0.5))
|
||||
|
||||
/* ---[ WINGs/memory.c ]-------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -237,6 +237,16 @@ char *WMGetFontName(WMFont * font)
|
||||
return font->name;
|
||||
}
|
||||
|
||||
void WMGetScaleBaseFromSystemFont(WMScreen *scrPtr, int *alphabetWidth, int *fontHeight)
|
||||
{
|
||||
WMFont *font;
|
||||
|
||||
font = WMDefaultSystemFont(scrPtr);
|
||||
*alphabetWidth = WMWidthOfString(font, "abcdefghijklmnopqrstuvwxyz", 26);
|
||||
*fontHeight = WMFontHeight(font);
|
||||
WMReleaseFont(font);
|
||||
}
|
||||
|
||||
WMFont *WMDefaultSystemFont(WMScreen * scrPtr)
|
||||
{
|
||||
return WMRetainFont(scrPtr->normalFont);
|
||||
|
||||
@@ -218,13 +218,6 @@ static void panelBtnCallback(WMWidget * self, void *data)
|
||||
DestroyDockAppSettingsPanel(panel);
|
||||
}
|
||||
|
||||
/* These macros are used to scale the coordinates in ShowDockAppSettingsPanel.
|
||||
* They are based on the width of "abcdefghijklmnopqrstuvwxyz" and the height
|
||||
* of the default system font (Sans, size 11): 164x14.
|
||||
*/
|
||||
#define SCALEX(value) ((int)((double)value / 164.0 * (double)fw + 0.5))
|
||||
#define SCALEY(value) ((int)((double)value / 14.0 * (double)fh + 0.5))
|
||||
|
||||
void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
{
|
||||
AppSettingsPanel *panel;
|
||||
@@ -237,26 +230,23 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
int pwidth, pheight;
|
||||
int iconSize;
|
||||
|
||||
/* get the width and height values of the system font for use in the SCALE macros */
|
||||
font = WMDefaultSystemFont(scr->wmscreen);
|
||||
fw = WMWidthOfString(font, "abcdefghijklmnopqrstuvwxyz", 26);
|
||||
fh = WMFontHeight(font);
|
||||
WMReleaseFont(font);
|
||||
/* get the width and height values of the system font for use with the ScaleX/ScaleY macros */
|
||||
WMGetScaleBaseFromSystemFont(scr->wmscreen, &fw, &fh);
|
||||
|
||||
/* calculate the required width and height for the panel */
|
||||
iconSize = wPreferences.icon_size;
|
||||
pwidth = SCALEX(300);
|
||||
pheight = SCALEY(10) /* upper margin */
|
||||
pwidth = ScaleX(300);
|
||||
pheight = ScaleY(10) /* upper margin */
|
||||
+ iconSize /* icon and its label */
|
||||
+ SCALEY(10) /* padding */
|
||||
+ SCALEY(20) + SCALEY(2) /* start option */
|
||||
+ SCALEY(20) + SCALEY(5) /* lock option */
|
||||
+ SCALEY(50) + SCALEY(5) /* app path and arguments */
|
||||
+ SCALEY(70) + SCALEY(5) /* middle-click command */
|
||||
+ SCALEY(70) + SCALEY(5) /* drag&drop command */
|
||||
+ SCALEY(50) + SCALEY(10) /* icon file */
|
||||
+ SCALEY(24) /* buttons */
|
||||
+ SCALEY(10); /* lower margin */
|
||||
+ ScaleY(10) /* padding */
|
||||
+ ScaleY(20) + ScaleY(2) /* start option */
|
||||
+ ScaleY(20) + ScaleY(5) /* lock option */
|
||||
+ ScaleY(50) + ScaleY(5) /* app path and arguments */
|
||||
+ ScaleY(70) + ScaleY(5) /* middle-click command */
|
||||
+ ScaleY(70) + ScaleY(5) /* drag&drop command */
|
||||
+ ScaleY(50) + ScaleY(10) /* icon file */
|
||||
+ ScaleY(24) /* buttons */
|
||||
+ ScaleY(10); /* lower margin */
|
||||
|
||||
panel = wmalloc(sizeof(AppSettingsPanel));
|
||||
|
||||
@@ -270,13 +260,13 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
|
||||
panel->iconLabel = WMCreateLabel(panel->win);
|
||||
WMResizeWidget(panel->iconLabel, iconSize, iconSize);
|
||||
WMMoveWidget(panel->iconLabel, SCALEX(10), SCALEY(10));
|
||||
WMMoveWidget(panel->iconLabel, ScaleX(10), ScaleY(10));
|
||||
WMSetLabelImagePosition(panel->iconLabel, WIPImageOnly);
|
||||
|
||||
panel->nameLabel = WMCreateLabel(panel->win);
|
||||
font = WMBoldSystemFontOfSize(scr->wmscreen, SCALEY(14));
|
||||
WMResizeWidget(panel->nameLabel, SCALEX(190), SCALEY(18));
|
||||
WMMoveWidget(panel->nameLabel, 2 * SCALEX(10) + iconSize, SCALEY(10) + ((iconSize - WMFontHeight(font)) / 2));
|
||||
font = WMBoldSystemFontOfSize(scr->wmscreen, ScaleY(14));
|
||||
WMResizeWidget(panel->nameLabel, ScaleX(190), ScaleY(18));
|
||||
WMMoveWidget(panel->nameLabel, 2 * ScaleX(10) + iconSize, ScaleY(10) + ((iconSize - WMFontHeight(font)) / 2));
|
||||
WMSetLabelTextAlignment(panel->nameLabel, WALeft);
|
||||
WMSetLabelFont(panel->nameLabel, font);
|
||||
WMReleaseFont(font);
|
||||
@@ -286,41 +276,41 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
WMSetLabelText(panel->nameLabel, aicon->wm_class);
|
||||
|
||||
vbox = WMCreateBox(panel->win);
|
||||
WMResizeWidget(vbox, pwidth - 2 * SCALEX(10), pheight - iconSize - 3 * SCALEY(10));
|
||||
WMMoveWidget(vbox, SCALEX(10), iconSize + 2 * SCALEY(10));
|
||||
WMResizeWidget(vbox, pwidth - 2 * ScaleX(10), pheight - iconSize - 3 * ScaleY(10));
|
||||
WMMoveWidget(vbox, ScaleX(10), iconSize + 2 * ScaleY(10));
|
||||
|
||||
panel->autoLaunchBtn = WMCreateSwitchButton(vbox);
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->autoLaunchBtn), False, True, SCALEY(20), SCALEY(20), SCALEY(2));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->autoLaunchBtn), False, True, ScaleY(20), ScaleY(20), ScaleY(2));
|
||||
WMSetButtonText(panel->autoLaunchBtn, _("Start when Window Maker is started"));
|
||||
WMSetButtonSelected(panel->autoLaunchBtn, aicon->auto_launch);
|
||||
|
||||
panel->lockBtn = WMCreateSwitchButton(vbox);
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->lockBtn), False, True, SCALEY(20), SCALEY(20), SCALEY(5));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->lockBtn), False, True, ScaleY(20), ScaleY(20), ScaleY(5));
|
||||
WMSetButtonText(panel->lockBtn, _("Lock (prevent accidental removal)"));
|
||||
WMSetButtonSelected(panel->lockBtn, aicon->lock);
|
||||
|
||||
panel->commandFrame = WMCreateFrame(vbox);
|
||||
WMSetFrameTitle(panel->commandFrame, _("Application path and arguments"));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->commandFrame), False, True, SCALEY(50), SCALEY(50), SCALEY(5));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->commandFrame), False, True, ScaleY(50), ScaleY(50), ScaleY(5));
|
||||
|
||||
panel->commandField = WMCreateTextField(panel->commandFrame);
|
||||
WMResizeWidget(panel->commandField, SCALEX(260), SCALEY(20));
|
||||
WMMoveWidget(panel->commandField, SCALEX(10), SCALEY(20));
|
||||
WMResizeWidget(panel->commandField, ScaleX(260), ScaleY(20));
|
||||
WMMoveWidget(panel->commandField, ScaleX(10), ScaleY(20));
|
||||
WMSetTextFieldText(panel->commandField, aicon->command);
|
||||
|
||||
WMMapSubwidgets(panel->commandFrame);
|
||||
|
||||
panel->pasteCommandFrame = WMCreateFrame(vbox);
|
||||
WMSetFrameTitle(panel->pasteCommandFrame, _("Command for middle-click launch"));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->pasteCommandFrame), False, True, SCALEY(70), SCALEY(70), SCALEY(5));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->pasteCommandFrame), False, True, ScaleY(70), ScaleY(70), ScaleY(5));
|
||||
|
||||
panel->pasteCommandField = WMCreateTextField(panel->pasteCommandFrame);
|
||||
WMResizeWidget(panel->pasteCommandField, SCALEX(260), SCALEY(20));
|
||||
WMMoveWidget(panel->pasteCommandField, SCALEX(10), SCALEY(20));
|
||||
WMResizeWidget(panel->pasteCommandField, ScaleX(260), ScaleY(20));
|
||||
WMMoveWidget(panel->pasteCommandField, ScaleX(10), ScaleY(20));
|
||||
|
||||
panel->pasteCommandLabel = WMCreateLabel(panel->pasteCommandFrame);
|
||||
WMResizeWidget(panel->pasteCommandLabel, SCALEX(260), SCALEY(18));
|
||||
WMMoveWidget(panel->pasteCommandLabel, SCALEX(10), SCALEY(45));
|
||||
WMResizeWidget(panel->pasteCommandLabel, ScaleX(260), ScaleY(18));
|
||||
WMMoveWidget(panel->pasteCommandLabel, ScaleX(10), ScaleY(45));
|
||||
|
||||
WMSetTextFieldText(panel->pasteCommandField, aicon->paste_command);
|
||||
WMSetLabelText(panel->pasteCommandLabel, _("%s will be replaced with current selection"));
|
||||
@@ -328,15 +318,15 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
|
||||
panel->dndCommandFrame = WMCreateFrame(vbox);
|
||||
WMSetFrameTitle(panel->dndCommandFrame, _("Command for dragged and dropped files"));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->dndCommandFrame), False, True, SCALEY(70), SCALEY(70), SCALEY(5));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->dndCommandFrame), False, True, ScaleY(70), ScaleY(70), ScaleY(5));
|
||||
|
||||
panel->dndCommandField = WMCreateTextField(panel->dndCommandFrame);
|
||||
WMResizeWidget(panel->dndCommandField, SCALEX(260), SCALEY(20));
|
||||
WMMoveWidget(panel->dndCommandField, SCALEX(10), SCALEY(20));
|
||||
WMResizeWidget(panel->dndCommandField, ScaleX(260), ScaleY(20));
|
||||
WMMoveWidget(panel->dndCommandField, ScaleX(10), ScaleY(20));
|
||||
|
||||
panel->dndCommandLabel = WMCreateLabel(panel->dndCommandFrame);
|
||||
WMResizeWidget(panel->dndCommandLabel, SCALEX(260), SCALEY(18));
|
||||
WMMoveWidget(panel->dndCommandLabel, SCALEX(10), SCALEY(45));
|
||||
WMResizeWidget(panel->dndCommandLabel, ScaleX(260), ScaleY(18));
|
||||
WMMoveWidget(panel->dndCommandLabel, ScaleX(10), ScaleY(45));
|
||||
#ifdef USE_DOCK_XDND
|
||||
WMSetTextFieldText(panel->dndCommandField, aicon->dnd_command);
|
||||
WMSetLabelText(panel->dndCommandLabel, _("%d will be replaced with the file name"));
|
||||
@@ -351,16 +341,16 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
|
||||
panel->iconFrame = WMCreateFrame(vbox);
|
||||
WMSetFrameTitle(panel->iconFrame, _("Icon Image"));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->iconFrame), False, True, SCALEY(50), SCALEY(50), SCALEY(10));
|
||||
WMAddBoxSubview(vbox, WMWidgetView(panel->iconFrame), False, True, ScaleY(50), ScaleY(50), ScaleY(10));
|
||||
|
||||
panel->iconField = WMCreateTextField(panel->iconFrame);
|
||||
WMResizeWidget(panel->iconField, SCALEX(180), SCALEY(20));
|
||||
WMMoveWidget(panel->iconField, SCALEX(10), SCALEY(20));
|
||||
WMResizeWidget(panel->iconField, ScaleX(180), ScaleY(20));
|
||||
WMMoveWidget(panel->iconField, ScaleX(10), ScaleY(20));
|
||||
WMSetTextFieldText(panel->iconField, wDefaultGetIconFile(aicon->wm_instance, aicon->wm_class, False));
|
||||
|
||||
panel->browseBtn = WMCreateCommandButton(panel->iconFrame);
|
||||
WMResizeWidget(panel->browseBtn, SCALEX(70), SCALEY(24));
|
||||
WMMoveWidget(panel->browseBtn, SCALEX(200), SCALEY(18));
|
||||
WMResizeWidget(panel->browseBtn, ScaleX(70), ScaleY(24));
|
||||
WMMoveWidget(panel->browseBtn, ScaleX(200), ScaleY(18));
|
||||
WMSetButtonText(panel->browseBtn, _("Browse..."));
|
||||
WMSetButtonAction(panel->browseBtn, chooseIconCallback, panel);
|
||||
|
||||
@@ -369,17 +359,17 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
|
||||
hbox = WMCreateBox(vbox);
|
||||
WMSetBoxHorizontal(hbox, True);
|
||||
WMAddBoxSubview(vbox, WMWidgetView(hbox), False, True, SCALEY(24), SCALEY(24), 0);
|
||||
WMAddBoxSubview(vbox, WMWidgetView(hbox), False, True, ScaleY(24), ScaleY(24), 0);
|
||||
|
||||
panel->okBtn = WMCreateCommandButton(hbox);
|
||||
WMSetButtonText(panel->okBtn, _("OK"));
|
||||
WMSetButtonAction(panel->okBtn, panelBtnCallback, panel);
|
||||
WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->okBtn), False, True, SCALEX(80), SCALEX(80), 0);
|
||||
WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->okBtn), False, True, ScaleX(80), ScaleX(80), 0);
|
||||
|
||||
panel->cancelBtn = WMCreateCommandButton(hbox);
|
||||
WMSetButtonText(panel->cancelBtn, _("Cancel"));
|
||||
WMSetButtonAction(panel->cancelBtn, panelBtnCallback, panel);
|
||||
WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->cancelBtn), False, True, SCALEX(80), SCALEX(80), 5);
|
||||
WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->cancelBtn), False, True, ScaleX(80), ScaleX(80), 5);
|
||||
|
||||
WMMapSubwidgets(hbox);
|
||||
}
|
||||
@@ -406,13 +396,13 @@ void ShowDockAppSettingsPanel(WAppIcon * aicon)
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
else if (y + pheight > rect.pos.y + rect.size.height)
|
||||
y = rect.pos.y + rect.size.height - pheight - 3 * SCALEY(10);
|
||||
y = rect.pos.y + rect.size.height - pheight - 3 * ScaleY(10);
|
||||
|
||||
if (aicon->dock && aicon->dock->type == WM_DOCK) {
|
||||
if (aicon->dock->on_right_side)
|
||||
x = rect.pos.x + rect.size.width / 2;
|
||||
else
|
||||
x = rect.pos.x + rect.size.width / 2 - pwidth - SCALEX(2);
|
||||
x = rect.pos.x + rect.size.width / 2 - pwidth - ScaleX(2);
|
||||
} else {
|
||||
x = rect.pos.x + (rect.size.width - pwidth) / 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user