From cc3452bd0df7ee276a8f635cca8bb1de63d2bc20 Mon Sep 17 00:00:00 2001 From: David Dormagen Date: Sun, 6 Sep 2015 19:02:31 +0200 Subject: [PATCH] custom guis: properly scale with font size now Previously, the em <-> pixels conversion was a hardcoded value. Now the GUI scales with the font size that can be selected in the options. Sadly, all scales were off since the hardcoded value was too low. --- .../ControllerActionBar.ocd/Script.c | 8 +-- .../ControllerCrewBar.ocd/Script.c | 24 ++++---- .../ControllerGoal.ocd/Script.c | 18 +++--- .../ControllerInventoryBar.ocd/Script.c | 6 +- .../ControllerWealth.ocd/Script.c | 4 +- .../MenuStyles.ocd/Classic.ocd/Script.c | 14 ++--- .../MenuStyles.ocd/Default.ocd/Script.c | 8 +-- .../HUD.ocd/MenuStyles.ocd/Grid.ocd/Script.c | 2 +- .../HUD.ocd/MenuStyles.ocd/List.ocd/Script.c | 2 +- .../ObjectInteractionMenu.ocd/Script.c | 61 +++++++++---------- .../Libraries.ocd/Constructor.ocd/Script.c | 38 ++++++------ .../Libraries.ocd/Producer.ocd/Script.c | 12 ++-- .../Libraries.ocd/Structure.ocd/Script.c | 12 ++-- .../Structures.ocd/Flagpole.ocd/Script.c | 6 +- .../Structures.ocd/Pump.ocd/Script.c | 6 +- .../Structures.ocd/Sawmill.ocd/Script.c | 6 +- src/graphics/C4FontLoader.h | 9 ++- src/gui/C4ScriptGuiWindow.cpp | 14 ++++- src/gui/C4ScriptGuiWindow.h | 6 +- 19 files changed, 136 insertions(+), 120 deletions(-) diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c index fcc73741a..16ef8dd58 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerActionBar.ocd/Script.c @@ -10,8 +10,8 @@ static const GUI_MAX_ACTIONBAR = 10; // maximum amount of actionbar-slots static const GUI_Controller_ActionBar_Delay = 20; // delay before the action bar is shown when pressing Interact // all values given in 10 em (-> 10 = 1.0em) -static const GUI_Controller_ActionBar_IconSize = 80; -static const GUI_Controller_ActionBar_Margin = 20; +static const GUI_Controller_ActionBar_IconSize = 40; +static const GUI_Controller_ActionBar_Margin = 10; local interaction_check_active; local actionbar_gui_target; @@ -209,8 +209,8 @@ func UpdateActionBarDisplay() info_icon = { Priority = 2, - Left = "+1em", Right = "0%+4.5em", - Top = "+1em", Bottom = "0%+4.5em" + Left = "+0.5em", Right = "0%+2.2em", + Top = "+0.5em", Bottom = "0%+2.2em" }, OnClick = GuiAction_Call(this, "OnActionBarSelected", button_number), OnMouseIn = GuiAction_SetTag("OnHover"), diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerCrewBar.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerCrewBar.ocd/Script.c index 9625febac..b3e1a2447 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerCrewBar.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerCrewBar.ocd/Script.c @@ -9,8 +9,8 @@ // TODO: Use old bars. // HUD margin and size in tenths of em. -static const GUI_Controller_CrewBar_IconSize = 80; -static const GUI_Controller_CrewBar_IconMargin = 10; +static const GUI_Controller_CrewBar_IconSize = 40; +static const GUI_Controller_CrewBar_IconMargin = 5; // Local variables to keep track of the crew HUD menu. local crew_gui_target; @@ -309,8 +309,8 @@ private func AddCrewHUDMenuMember(object crew, int index, int margin, int size) Style = GUI_NoCrop, Left = "0%", Right = "100%", - Top = "100%+0.4em", - Bottom = "100%+1.3em", + Top = "100%+0.2em", + Bottom = "100%+0.65em", BackgroundColor = RGB(40, 40, 40), Priority = 6, value = @@ -318,16 +318,16 @@ private func AddCrewHUDMenuMember(object crew, int index, int margin, int size) Target = crew_gui_target, ID = 100 * (index + 1) + 9, Style = GUI_NoCrop, - Left = "0.2em", + Left = "0.1em", Right = Format("%s%s", ToPercentString(health_ratio), ToEmString((500 - health_ratio) / 250)), - Margin = ["0em", ToEmString(2)], + Margin = ["0em", "0.1em"], BackgroundColor = RGB(160, 0, 0), Priority = 7, text = { Target = crew_gui_target, ID = 100 * (index + 1) + 10, - Top = "-0.9em", + Top = "-0.45em", Style = GUI_TextHCenter, Text = Format("%d", health_val), Priority = 8, @@ -341,8 +341,8 @@ private func AddCrewHUDMenuMember(object crew, int index, int margin, int size) Style = GUI_NoCrop, Left = "0%", Right = "100%", - Top = "100%+1.5em", - Bottom = "100%+2.4em", + Top = "100%+0.75em", + Bottom = "100%+1.2em", Priority = 6, value = { @@ -350,7 +350,7 @@ private func AddCrewHUDMenuMember(object crew, int index, int margin, int size) ID = 100 * (index + 1) + 12, Left = "0.2em", Right = Format("%s%s", ToPercentString(breath_ratio), ToEmString((500 - breath_ratio) / 250)), - Margin = ["0em", ToEmString(2)], + Margin = ["0em", "0.1em"], Priority = 7, }, }, @@ -448,7 +448,7 @@ private func CrewHUDMenuUpdateHealth(object clonk, int health, int health_ratio) if (!crew_menu) return; var health_menu = crew_menu[0].health; - health_menu.value.Right = Format("%s%s", ToPercentString(health_ratio), ToEmString((500 - health_ratio) / 250)); + health_menu.value.Right = Format("%s%s", ToPercentString(health_ratio), ToEmString((500 - health_ratio) / 500)); health_menu.value.text.Text = Format("%d", health); GuiUpdate(health_menu, crew_gui_id, health_menu.ID, health_menu.Target); return; @@ -460,7 +460,7 @@ private func CrewHUDMenuUpdateBreath(object clonk, int breath, int breath_ratio) if (!crew_menu) return; var breath_menu = crew_menu[0].breath; - breath_menu.value.Right = Format("%s%s", ToPercentString(breath_ratio), ToEmString((500 - breath_ratio) / 250)); + breath_menu.value.Right = Format("%s%s", ToPercentString(breath_ratio), ToEmString((500 - breath_ratio) / 500)); GuiUpdate(breath_menu, crew_gui_id, breath_menu.ID, breath_menu.Target); return; } diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerGoal.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerGoal.ocd/Script.c index 8da086791..3ac097e6f 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerGoal.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerGoal.ocd/Script.c @@ -7,8 +7,8 @@ // HUD margin and size in tenths of em. -static const GUI_Controller_Goal_IconSize = 60; -static const GUI_Controller_Goal_IconMargin = 10; +static const GUI_Controller_Goal_IconSize = 30; +static const GUI_Controller_Goal_IconMargin = 5; // Local variables to keep track of the goal HUD menu. local goal_gui_target; @@ -115,7 +115,7 @@ private func OpenGoalWindow(int plr) { var goals = FindObjects(Find_Category(C4D_Goal)); var nr_goals = GetLength(goals); - var menu_width = BoundBy(nr_goals * 4, 20, 40); // in em + var menu_width = BoundBy(nr_goals * 2, 10, 20); // in em // Create a menu target. goal_info_target = CreateObject(Dummy, AbsX(0), AbsY(0), plr); @@ -132,8 +132,8 @@ private func OpenGoalWindow(int plr) Decoration = GUI_MenuDeco, Left = Format("50%%-%dem", menu_width), Right = Format("50%%+%dem", menu_width), - Top = "50%-8em", - Bottom = "50%+16em", + Top = "50%-4em", + Bottom = "50%+8em", BackgroundColor = {Std = 0}, OnClose = GuiAction_Call(this, "OnGoalWindowClosed"), }; @@ -148,7 +148,7 @@ private func OpenGoalWindow(int plr) ID = 1, Left = "0%", Right = "100%", - Top = "0%+8em", + Top = "0%+4em", Bottom = "100%", Text = "", BackgroundColor = {Std = 0}, @@ -188,7 +188,7 @@ public func OnGoalWindowClosed() private func GoalSubMenu(object goal, int nr, int size) { if (size == nil) - size = 8; + size = 4; // Create the goal submenu with id counting upwards from 2. var prop_goal = @@ -212,10 +212,10 @@ private func GoalSubMenu(object goal, int nr, int size) prop_goal.star = { Target = goal_info_target, - Left = "100%-2em", + Left = "100%-1em", Right = "100%", Top = "0%", - Bottom = "0%+2em", + Bottom = "0%+1em", Symbol = Icon_Ok, BackgroundColor = {Std = 0}, }; diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerInventoryBar.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerInventoryBar.ocd/Script.c index 10b638e73..34d793159 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerInventoryBar.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerInventoryBar.ocd/Script.c @@ -13,9 +13,9 @@ */ // all values given in 10 em (-> 10 = 1.0em) -static const GUI_Controller_InventoryBar_IconMarginScreenBottom = 2; // margin from left border of screen -static const GUI_Controller_InventoryBar_IconSize = 40; -static const GUI_Controller_InventoryBar_IconMargin = 10; +static const GUI_Controller_InventoryBar_IconMarginScreenBottom = 1; // margin from left border of screen +static const GUI_Controller_InventoryBar_IconSize = 20; +static const GUI_Controller_InventoryBar_IconMargin = 5; local inventory_slots; local inventory_gui_target; diff --git a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerWealth.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerWealth.ocd/Script.c index fa8e1c2b5..ac71a0ba3 100644 --- a/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerWealth.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/Controller.ocd/ControllerWealth.ocd/Script.c @@ -7,8 +7,8 @@ // HUD margin and size in tenths of em. -static const GUI_Controller_Wealth_IconSize = 60; -static const GUI_Controller_Wealth_IconMargin = 10; +static const GUI_Controller_Wealth_IconSize = 30; +static const GUI_Controller_Wealth_IconMargin = 5; // Local variables to keep track of the wealth HUD menu. local wealth_gui_target; diff --git a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Classic.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Classic.ocd/Script.c index 702865493..ba8828059 100644 --- a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Classic.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Classic.ocd/Script.c @@ -35,16 +35,16 @@ global func CreateClassicMenu(id symbol, object command_object, int extra, strin Target = menu, inner = { - Margin = "1em", + Margin = "0.5em", header = { - Bottom = "2em", - icon = {Symbol = symbol, Right = "2em", Bottom = "2em"}, - caption = {Left = "2em", Text = caption, Style = GUI_TextVCenter} + Bottom = "1em", + icon = {Symbol = symbol, Right = "1em", Bottom = "1em"}, + caption = {Left = "1em", Text = caption, Style = GUI_TextVCenter} }, body = { - Top = "2em", + Top = "1em", items = { Right = "50%", @@ -72,8 +72,8 @@ public func AddMenuItem(string caption, string command, symbol, int count, param ID = ID, BackgroundColor = {Std = 0, Hover = 0x50ff0000}, Symbol = symbol, - Right = "+4em", - Bottom = "+4em", + Right = "+2em", + Bottom = "+2em", Text = Format("%dx", count), Priority = ID, OnClick = GuiAction_Call(this, "OnClick", [symbol, ID, command, parameter]), diff --git a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Default.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Default.ocd/Script.c index 89841e383..8bedcb698 100644 --- a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Default.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Default.ocd/Script.c @@ -17,7 +17,7 @@ func Construction() _inherited(...); this.topic = { - Bottom = "3em", + Bottom = "1.5em", BackgroundColor = RGB(50, 50, 50), Style = GUI_TextHCenter | GUI_TextVCenter, ID = 2, @@ -33,9 +33,9 @@ func Construction() ID = 5, Target = this, Left = "50%", - textbox = {Top = "12em"}, - headline = {Top = "9em", Bottom = "11em", BackgroundColor = RGB(50, 50, 50), Style = GUI_TextVCenter | GUI_TextHCenter}, - icon = {Bottom = "8em"} + textbox = {Top = "6em"}, + headline = {Top = "4.5em", Bottom = "5.5em", BackgroundColor = RGB(50, 50, 50), Style = GUI_TextVCenter | GUI_TextHCenter}, + icon = {Bottom = "4em"} } }; this.Target = this; diff --git a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Grid.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Grid.ocd/Script.c index efe2760ff..68cc981fb 100644 --- a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Grid.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/Grid.ocd/Script.c @@ -15,7 +15,7 @@ func Construction() func MakeEntryProplist(symbol, text) { - var custom_entry = {Bottom = "+4em", Right = "+4em", desc = {Style = GUI_TextRight | GUI_TextBottom}}; + var custom_entry = {Bottom = "+2em", Right = "+2em", desc = {Style = GUI_TextRight | GUI_TextBottom}}; custom_entry.Symbol = symbol; custom_entry.desc.Text = text; custom_entry.BackgroundColor = {Std = 0, OnHover = 0x50ff0000}; diff --git a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/List.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/List.ocd/Script.c index e3e0d34bc..d8ca406e4 100644 --- a/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/List.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/MenuStyles.ocd/List.ocd/Script.c @@ -62,7 +62,7 @@ func SetMouseOutCallback(proplist target, callback) // can be overloaded for custom menu styles func MakeEntryProplist(symbol, text) { - var custom_entry = {Bottom = "+4em", sym = {Right = "+4em", Bottom = "+4em"}, desc = {Left = "+4em"}}; + var custom_entry = {Bottom = "+2em", sym = {Right = "+2em", Bottom = "+2em"}, desc = {Left = "+2em"}}; custom_entry.sym.Symbol = symbol; custom_entry.desc.Text = text; custom_entry.desc.Style = GUI_TextVCenter; diff --git a/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c b/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c index 51fc45b33..99b36b988 100644 --- a/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c +++ b/planet/Objects.ocd/HUD.ocd/ObjectInteractionMenu.ocd/Script.c @@ -8,7 +8,7 @@ local Name = "$Name$"; local Description = "$Description$"; -static const InteractionMenu_SideBarSize = 80; // in tenth-em +static const InteractionMenu_SideBarSize = 40; // in tenth-em static const InteractionMenu_Contents = 2; static const InteractionMenu_Custom = 4; @@ -258,8 +258,8 @@ func OpenMenuForObject(object obj, int slot, bool forced) var sidebar_size_em = ToEmString(InteractionMenu_SideBarSize); var part_menu = { - Left = "0%", Right = "50%-2em", - Bottom = "100%-14em", + Left = "0%", Right = "50%-1em", + Bottom = "100%-7em", sidebar = sidebar, main = main, Target = current_menus[slot].menu_object, ID = 1 @@ -267,7 +267,7 @@ func OpenMenuForObject(object obj, int slot, bool forced) if (slot == 1) { - part_menu.Left = "50%+2em"; + part_menu.Left = "50%+1em"; part_menu.Right = "100%"; } @@ -298,8 +298,8 @@ func OpenMenuForObject(object obj, int slot, bool forced) minimize_button = { Bottom = "100%", - Top = "100% - 2em", - Right = "8em", + Top = "100% - 1em", + Right = "4em", Text = "$Minimize$", BackgroundColor = {Std = RGB(50, 50, 50), OnHover = RGB(200, 0, 0)}, OnMouseIn = GuiAction_SetTag("OnHover"), @@ -308,16 +308,16 @@ func OpenMenuForObject(object obj, int slot, bool forced) }, center_column = { - Left = "50%-2em", - Right = "50%+2em", + Left = "50%-1em", + Right = "50%+1em", Top = "1.75em", - Bottom = "100%-14em", + Bottom = "100%-7em", Style = GUI_VerticalLayout, move_all_left = { Target = current_center_column_target, ID = 10 + 0, - Right = "4em", Bottom = "6em", + Right = "2em", Bottom = "3em", Style = GUI_TextHCenter | GUI_TextVCenter, Symbol = Icon_MoveItems, GraphicsName = "Left", Tooltip = "", @@ -330,7 +330,7 @@ func OpenMenuForObject(object obj, int slot, bool forced) { Target = current_center_column_target, ID = 10 + 1, - Right = "4em", Bottom = "6em", + Right = "2em", Bottom = "3em", Style = GUI_TextHCenter | GUI_TextVCenter, Symbol = Icon_MoveItems, Tooltip = "", @@ -342,21 +342,21 @@ func OpenMenuForObject(object obj, int slot, bool forced) }, description_box = { - Top = "100%-10em", + Top = "100%-5em", Margin = [sidebar_size_em, "0em"], BackgroundColor = RGB(25, 25, 25), symbol_part = { - Right = "10em", + Right = "5em", Symbol = nil, - Margin = "1em", + Margin = "0.5em", ID = 1, Target = current_description_box.symbol_target }, desc_part = { - Left = "10em", - Margin = "1em", + Left = "5em", + Margin = "0.5em", ID = 1, Target = current_description_box.target, real_contents = // nested one more time so it can dynamically be replaced without messing up the layout @@ -534,8 +534,8 @@ func CreateSideBar(int slot) OnMouseOut = GuiAction_SetTag("Std"), OnClick = GuiAction_Call(this, "OnSidebarEntrySelected", {slot = slot, obj = obj}), Text = obj->GetName(), - obj_symbol = {Symbol = obj, Margin = "0.5em", Priority = 1}, - obj_symbol_deactivated = {Symbol = deactivation_symbol, Margin = "1.0em", Priority = 2, Target = obj, ID = 1 + slot} + obj_symbol = {Symbol = obj, Margin = "0.25em", Priority = 1}, + obj_symbol_deactivated = {Symbol = deactivation_symbol, Margin = "0.5em", Priority = 2, Target = obj, ID = 1 + slot} }; GuiAddSubwindow(entry, sidebar); @@ -577,13 +577,13 @@ func CreateMainMenu(object obj, int slot) Right = Format("100%% %s", ToEmString(-InteractionMenu_SideBarSize)), container = { - Top = "2em", + Top = "1em", Style = GUI_VerticalLayout, BackgroundColor = RGB(25, 25, 25), }, headline = { - Bottom = "2em", + Bottom = "1em", Text = obj->GetName(), Style = GUI_TextHCenter | GUI_TextVCenter, BackgroundColor = 0xff000000 @@ -646,11 +646,10 @@ func CreateMainMenu(object obj, int slot) } menu.menu_object = CreateObject(MenuStyle_Grid); - menu.menu_object.Top = "+2em"; + menu.menu_object.Top = "+1em"; menu.menu_object.Priority = 2; menu.menu_object->SetPermanent(); menu.menu_object->SetFitChildren(); - //menu.menu_object.Bottom = "4em"; menu.menu_object->SetMouseOverCallback(this, "OnMenuEntryHover"); for (var e = 0; e < GetLength(menu.entries); ++e) { @@ -668,15 +667,15 @@ func CreateMainMenu(object obj, int slot) { Priority = 1, Style = GUI_TextVCenter | GUI_TextHCenter, - Bottom = "+1.5em", + Bottom = "+0.75em", Text = menu.title, BackgroundColor = 0xa0000000, //Decoration = menu.decoration - hline = {Bottom = "0.1em", BackgroundColor = RGB(100, 100, 100)} + hline = {Bottom = "0.05em", BackgroundColor = RGB(100, 100, 100)} }, - Margin = [nil, nil, nil, "0.5em"], + Margin = [nil, nil, nil, "0.25em"], real_menu = menu.menu_object, - spacer = {Left = "0em", Right = "0em", Bottom = "6em"} // guarantees a minimum height + spacer = {Left = "0em", Right = "0em", Bottom = "3em"} // guarantees a minimum height }; if (menu.flag == InteractionMenu_Contents) all.BackgroundColor = RGB(0, 50, 0); @@ -885,11 +884,11 @@ func FxIntRefreshContentsMenuTimer(target, effect, time) custom = MenuStyle_Grid->MakeEntryProplist(symbol, nil); // Pack it into a larger frame to allow for another button below. // The entries with contents are sorted to the back of the inventory menu. This makes for a nicer layout. - custom = {Right = custom.Right, Bottom = "8em", top = custom, Priority = 10000 + obj->GetValue()}; + custom = {Right = custom.Right, Bottom = "4em", top = custom, Priority = 10000 + obj->GetValue()}; // Then add a little container-symbol (that can be clicked). custom.bottom = { - Top = "4em", + Top = "2em", BackgroundColor = {Std = 0, Selected = RGBa(255, 100, 100, 100)}, OnMouseIn = GuiAction_SetTag("Selected"), OnMouseOut = GuiAction_SetTag("Std"), @@ -910,7 +909,7 @@ func FxIntRefreshContentsMenuTimer(target, effect, time) custom.bottom.contents = { Symbol = obj->Contents(0)->GetID(), - Margin = "0.25em", + Margin = "0.125em", Priority = 2 }; // Possibly add text for stackable items - this is an special exception for the Library_Stackable. @@ -922,8 +921,8 @@ func FxIntRefreshContentsMenuTimer(target, effect, time) custom.bottom.contents.Style = GUI_TextBottom | GUI_TextRight; } // Also make the chest smaller, so that the contents symbol is not obstructed. - custom.bottom.container.Bottom = "2em"; - custom.bottom.container.Left = "2em"; + custom.bottom.container.Bottom = "1em"; + custom.bottom.container.Left = "1em"; } } // Add to menu! diff --git a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/Script.c index 8870b3663..4a3814230 100644 --- a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/Script.c @@ -225,7 +225,7 @@ public func OpenConstructionMenu(object clonk) menu_controller = clonk; // Size of the grid items in em. - var item_size = 8; + var item_size = 4; // Construction menu proplist. menu = @@ -240,7 +240,7 @@ public func OpenConstructionMenu(object clonk) menu.separator = { Left = "60%", - Right = "60%+1em", + Right = "60%+0.5em", BackgroundColor = {Std = 0x50888888} }; @@ -269,16 +269,16 @@ public func CreateStructureInfo() { Target = menu_target, ID = 2, - Left = "60%+1em" + Left = "60%+0.5em" }; // Bottom part for material costs, description and other written information. structinfo.description = { Target = menu_target, Priority = 0x0fffff, - Left = "0.5em", - Right = "100%-0.5em", - Top = "100%-6em", + Left = "0.25em", + Right = "100%-0.25em", + Top = "100%-3em", Bottom = "100%", Text = nil // will be updated }; @@ -286,40 +286,40 @@ public func CreateStructureInfo() { Target = menu_target, Priority = 0x0fffff, - Left = "0.5em", - Right = "100%-0.5em", - Top = "100%-10em", - Bottom = "100%-6em", + Left = "0.25em", + Right = "100%-0.25em", + Top = "100%-5em", + Bottom = "100%-3em", Text = nil // will be updated }; // Upper part is for the picture and power display. structinfo.picture = { Target = menu_target, - Bottom = "100%-10em", - Margin = ["10%+1em"], + Bottom = "100%-5em", + Margin = ["10%+0.5em"], Symbol = nil, // will be updated power_consumer = { Target = menu_target, - Right = "3em", - Bottom = "3em", + Right = "1.5em", + Bottom = "1.5em", Symbol = nil // will be updated }, power_producer = { Target = menu_target, - Left = "3em", - Right = "6em", - Bottom = "3em", + Left = "1.5em", + Right = "3em", + Bottom = "1.5em", Symbol = nil // will be updated } }; structinfo.close_button = { Target = menu_target, - Left = "100%-4em", - Bottom = "4em", + Left = "100%-2em", + Bottom = "2em", Symbol = Icon_Cancel, BackgroundColor = {Std = 0, Hover = 0x50ffff00}, OnMouseIn = GuiAction_SetTag("Hover"), diff --git a/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c index e3952f5bb..a05d6b470 100644 --- a/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Producer.ocd/Script.c @@ -57,14 +57,14 @@ public func GetProductionMenuEntries() var custom_entry = { - Right = "8em%", Bottom = "4em", + Right = "4em", Bottom = "2em", // BackgroundColor = {Std = 0, OnHover = 0x50ff0000}, - image = {Prototype = control_prototype, Right = "4em", Style = GUI_TextBottom | GUI_TextRight}, + image = {Prototype = control_prototype, Right = "2em", Style = GUI_TextBottom | GUI_TextRight}, controls = { - Left = "4em", - remove = {Prototype = control_prototype, Bottom = "2em", Symbol = Icon_Number, GraphicsName = "Minus", Tooltip = "$QueueRemove$"}, - endless = {Prototype = control_prototype, Top = "2em", Symbol = Icon_Number, GraphicsName = "Inf", Tooltip = "$QueueInf$"} + Left = "2em", + remove = {Prototype = control_prototype, Bottom = "1em", Symbol = Icon_Number, GraphicsName = "Minus", Tooltip = "$QueueRemove$"}, + endless = {Prototype = control_prototype, Top = "1em", Symbol = Icon_Number, GraphicsName = "Inf", Tooltip = "$QueueInf$"} } }; @@ -139,7 +139,7 @@ public func OnProductHover(symbol, extra_data, desc_menu_target, menu_id) Text = Format("%s:|%s", symbol.Name, symbol.Description,), requirements = { - Top = "100% - 2em", + Top = "100% - 1em", Style = GUI_TextBottom } }; diff --git a/planet/Objects.ocd/Libraries.ocd/Structure.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Structure.ocd/Script.c index 762b3252c..ef69b5c99 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structure.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Structure.ocd/Script.c @@ -227,17 +227,17 @@ public func GetDamageMenuEntries() var menu = { - Bottom = "4em", + Bottom = "2em", right = { - Left = "4em", - Right = "100% - 1em", - bottom = {Top = "50%", Margin = "0.2em", BackgroundColor = RGB(0, 0, 0)}, + Left = "2em", + Right = "100% - 0.5em", + bottom = {Top = "50%", Margin = "0.1em", BackgroundColor = RGB(0, 0, 0)}, top = {Text = damage_text, Style = GUI_TextHCenter} }, symbol = { - Right = "4em", + Right = "2em", Symbol = Hammer } }; @@ -250,7 +250,7 @@ public func GetDamageMenuEntries() if (GetDamage() == 0) { // Cross out hammer symbol. - menu.symbol.overlay = {Margin = "0.5em", Symbol = Icon_Cancel}; + menu.symbol.overlay = {Margin = "0.25em", Symbol = Icon_Cancel}; } } diff --git a/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c index 22ba9be62..d0cbd6db4 100644 --- a/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Flagpole.ocd/Script.c @@ -61,10 +61,10 @@ public func GetBuyMenuEntries(object clonk) // default design of a control menu item var custom_entry = { - Right = "8em", Bottom = "4em", + Right = "4em", Bottom = "2em", BackgroundColor = {Std = 0, OnHover = 0x50ff0000}, - image = {Right = "4em", Style = GUI_TextBottom | GUI_TextRight}, - price = {Left = "4em", Priority = 3} + image = {Right = "2em", Style = GUI_TextBottom | GUI_TextRight}, + price = {Left = "2em", Priority = 3} }; var wealth = GetWealth(GetOwner()); // Note that the flag owner pays for everything atm. diff --git a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c index 71384c9ac..6e0f591d7 100644 --- a/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Pump.ocd/Script.c @@ -58,10 +58,10 @@ public func GetPumpControlMenuEntries(object clonk) // default design of a control menu item var custom_entry = { - Right = "100%", Bottom = "4em", + Right = "100%", Bottom = "2em", BackgroundColor = {Std = 0, OnHover = 0x50ff0000}, - image = {Right = "4em"}, - text = {Left = "4em"} + image = {Right = "2em"}, + text = {Left = "2em"} }; if (!switched_on) diff --git a/planet/Objects.ocd/Structures.ocd/Sawmill.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Sawmill.ocd/Script.c index 6866e8ddc..8b6071b6d 100644 --- a/planet/Objects.ocd/Structures.ocd/Sawmill.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Sawmill.ocd/Script.c @@ -58,9 +58,9 @@ public func GetProductionMenuEntries() { return [{symbol = Wood, custom = { - Right = "100%", Bottom = "8em", - text = {Left = "4em", Text = "$AutoProduction$", Style = GUI_TextVCenter | GUI_TextHCenter}, - image = {Right = "4em", Bottom = "4em", Symbol = Wood} + Right = "100%", Bottom = "4em", + text = {Left = "2em", Text = "$AutoProduction$", Style = GUI_TextVCenter | GUI_TextHCenter}, + image = {Right = "2em", Bottom = "2em", Symbol = Wood} } }]; } diff --git a/src/graphics/C4FontLoader.h b/src/graphics/C4FontLoader.h index 0bb919b8e..f0679c732 100644 --- a/src/graphics/C4FontLoader.h +++ b/src/graphics/C4FontLoader.h @@ -145,7 +145,14 @@ public: #else return iLineHgt; #endif - } // Sometimes, only the width of a text is needed + } + // get height of the font in pixels (without line spacing) + inline int GetFontHeight() const + { + // Currently, we do not use spacing between lines - if someone implements that, this needs to be adjusted. + return GetLineHeight(); + } + // Sometimes, only the width of a text is needed int32_t GetTextWidth(const char *szText, bool fCheckMarkup = true) { int32_t x, y; GetTextExtent(szText, x, y, fCheckMarkup); return x; } // insert line breaks into a message and return overall height - uses and regards '|' as line breaks int BreakMessage(const char *szMsg, int iWdt, char *szOut, int iMaxOutLen, bool fCheckMarkup, float fZoom=1.0f); diff --git a/src/gui/C4ScriptGuiWindow.cpp b/src/gui/C4ScriptGuiWindow.cpp index dc1f43f56..ae58b635f 100644 --- a/src/gui/C4ScriptGuiWindow.cpp +++ b/src/gui/C4ScriptGuiWindow.cpp @@ -50,8 +50,18 @@ #define MenuDebugLogF(...) ((void)0) // This in in EM! Also, golden ratio -const float C4ScriptGuiWindow::standardWidth = 100.0f; -const float C4ScriptGuiWindow::standardHeight = 61.8f; +const float C4ScriptGuiWindow::standardWidth = 50.0f; +const float C4ScriptGuiWindow::standardHeight = 31.0f; + +float C4ScriptGuiWindow::Em2Pix(float em) +{ + return static_cast(::GraphicsResource.FontRegular.GetFontHeight()) * em; +} + +float C4ScriptGuiWindow::Pix2Em(float pix) +{ + return pix / static_cast(::GraphicsResource.FontRegular.GetFontHeight()); +} C4ScriptGuiWindowAction::~C4ScriptGuiWindowAction() { diff --git a/src/gui/C4ScriptGuiWindow.h b/src/gui/C4ScriptGuiWindow.h index 8650aa496..28e15f52c 100644 --- a/src/gui/C4ScriptGuiWindow.h +++ b/src/gui/C4ScriptGuiWindow.h @@ -340,9 +340,9 @@ public: void OnMouseIn(int32_t player, int32_t parentOffsetX, int32_t parentOffsetY); bool HasMouseFocus() { return currentMouseState & MouseState::Focus; } private: - // TODO: actually scale with font size (needs font to be able to scale first..) - float Em2Pix(float em) { return 12.0f * em; } - float Pix2Em(float pix) { return pix / 12.0f; } + // Use the currently loaded font to determine on-screen size of 1 EM. + static float Em2Pix(float em); + static float Pix2Em(float pix); }; #endif