Some fixes to window placement
This commit is contained in:
@@ -937,7 +937,10 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
Game::NewEvent(new ScriptEventCompanyBankrupt(c_index));
|
Game::NewEvent(new ScriptEventCompanyBankrupt(c_index));
|
||||||
CompanyAdminRemove(c_index, (CompanyRemoveReason)reason);
|
CompanyAdminRemove(c_index, (CompanyRemoveReason)reason);
|
||||||
|
|
||||||
if (StoryPage::GetNumItems() == 0 || Goal::GetNumItems() == 0) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
if (StoryPage::GetNumItems() == 0 || Goal::GetNumItems() == 0) {
|
||||||
|
InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
||||||
|
InvalidateWindowData(WC_MAIN_TOOLBAR_RIGHT, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -461,6 +461,7 @@ struct MainWindow : Window
|
|||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
/* Forward the message to the appropriate toolbar (ingame or scenario editor) */
|
/* Forward the message to the appropriate toolbar (ingame or scenario editor) */
|
||||||
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
|
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
|
||||||
|
InvalidateWindowData(WC_MAIN_TOOLBAR_RIGHT, 0, data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HotkeyList hotkeys;
|
static HotkeyList hotkeys;
|
||||||
|
|||||||
@@ -135,6 +135,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
WC_MAIN_TOOLBAR = ::WC_MAIN_TOOLBAR,
|
WC_MAIN_TOOLBAR = ::WC_MAIN_TOOLBAR,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main toolbar (the long bar at the top); %Window numbers:
|
||||||
|
* - 0 = #ToolbarNormalWidgets
|
||||||
|
* - 0 = #ToolbarEditorWidgets
|
||||||
|
*/
|
||||||
|
WC_MAIN_TOOLBAR_RIGHT = ::WC_MAIN_TOOLBAR_RIGHT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statusbar (at the bottom of your screen); %Window numbers:
|
* Statusbar (at the bottom of your screen); %Window numbers:
|
||||||
* - 0 = #StatusbarWidgets
|
* - 0 = #StatusbarWidgets
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ RailType _last_built_railtype;
|
|||||||
RoadType _last_built_roadtype;
|
RoadType _last_built_roadtype;
|
||||||
|
|
||||||
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
|
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
|
||||||
|
int _last_clicked_toolbar_idx = 0;
|
||||||
|
|
||||||
/** Toobar modes */
|
/** Toobar modes */
|
||||||
enum ToolbarMode {
|
enum ToolbarMode {
|
||||||
@@ -170,7 +171,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
|
static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
|
||||||
{
|
{
|
||||||
ShowDropDownList(w, list, def, widget, 0, true, true);
|
if (!_settings_client.gui.vertical_toolbar) {
|
||||||
|
ShowDropDownList(w, list, def, widget, 0, true, true);
|
||||||
|
} else {
|
||||||
|
Rect wi_rect;
|
||||||
|
NWidgetCore *nwi = w->GetWidget<NWidgetCore>(widget);
|
||||||
|
wi_rect.left = ((int)nwi->pos_x < _screen.width / 2) ? nwi->pos_x + nwi->current_x - 1 : nwi->pos_x - nwi->current_x;
|
||||||
|
wi_rect.right = ((int)nwi->pos_x < _screen.width / 2) ? nwi->pos_x + nwi->current_x * 2 : nwi->pos_x - 1;
|
||||||
|
wi_rect.top = nwi->pos_y;
|
||||||
|
wi_rect.bottom = nwi->pos_y + nwi->current_y - 1;
|
||||||
|
ShowDropDownListAt(w, list, def, widget, wi_rect, nwi->colour, true, true);
|
||||||
|
}
|
||||||
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1796,8 +1807,10 @@ enum MainToolbarHotkeys {
|
|||||||
/** Main toolbar. */
|
/** Main toolbar. */
|
||||||
struct MainToolbarWindow : Window {
|
struct MainToolbarWindow : Window {
|
||||||
CallBackFunction last_started_action; ///< Last started user action.
|
CallBackFunction last_started_action; ///< Last started user action.
|
||||||
|
int *clickedFlag;
|
||||||
|
int clickedValue;
|
||||||
|
|
||||||
MainToolbarWindow(WindowDesc *desc) : Window(desc)
|
MainToolbarWindow(WindowDesc *desc, int *clickedFlag = NULL, int clickedValue = 0) : Window(desc), clickedFlag(clickedFlag), clickedValue(clickedValue)
|
||||||
{
|
{
|
||||||
this->InitNested(0);
|
this->InitNested(0);
|
||||||
|
|
||||||
@@ -1829,11 +1842,15 @@ struct MainToolbarWindow : Window {
|
|||||||
|
|
||||||
virtual void OnClick(Point pt, int widget, int click_count)
|
virtual void OnClick(Point pt, int widget, int click_count)
|
||||||
{
|
{
|
||||||
|
if (clickedFlag)
|
||||||
|
*clickedFlag = clickedValue;
|
||||||
if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
|
if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnDropdownSelect(int widget, int index)
|
virtual void OnDropdownSelect(int widget, int index)
|
||||||
{
|
{
|
||||||
|
if (clickedFlag)
|
||||||
|
*clickedFlag = clickedValue;
|
||||||
CallBackFunction cbf = _menu_clicked_procs[widget](index);
|
CallBackFunction cbf = _menu_clicked_procs[widget](index);
|
||||||
if (cbf != CBF_NONE) this->last_started_action = cbf;
|
if (cbf != CBF_NONE) this->last_started_action = cbf;
|
||||||
}
|
}
|
||||||
@@ -2425,9 +2442,9 @@ void AllocateToolbar()
|
|||||||
new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
|
new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
|
||||||
} else {
|
} else {
|
||||||
if (_settings_client.gui.vertical_toolbar) {
|
if (_settings_client.gui.vertical_toolbar) {
|
||||||
MainToolbarWindow *w = new MainToolbarWindow(&_toolb_vertical_left_desc);
|
MainToolbarWindow *w = new MainToolbarWindow(&_toolb_vertical_left_desc, &_last_clicked_toolbar_idx, 0);
|
||||||
w->left = 0;
|
w->left = 0;
|
||||||
w = new MainToolbarWindow(&_toolb_vertical_right_desc);
|
w = new MainToolbarWindow(&_toolb_vertical_right_desc, &_last_clicked_toolbar_idx, 1);
|
||||||
w->left = _screen.width - w->width;
|
w->left = _screen.width - w->width;
|
||||||
SetDirtyBlocks(0, w->top, _screen.width, w->top + w->height);
|
SetDirtyBlocks(0, w->top, _screen.width, w->top + w->height);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -18,4 +18,6 @@ void ToggleDirtyBlocks();
|
|||||||
|
|
||||||
void ResetTabletWindow();
|
void ResetTabletWindow();
|
||||||
|
|
||||||
|
extern int _last_clicked_toolbar_idx;
|
||||||
|
|
||||||
#endif /* TOOLBAR_GUI_H */
|
#endif /* TOOLBAR_GUI_H */
|
||||||
|
|||||||
@@ -1261,6 +1261,7 @@ static uint GetWindowZPriority(const Window *w)
|
|||||||
++z_priority;
|
++z_priority;
|
||||||
|
|
||||||
case WC_MAIN_TOOLBAR:
|
case WC_MAIN_TOOLBAR:
|
||||||
|
case WC_MAIN_TOOLBAR_RIGHT:
|
||||||
case WC_STATUS_BAR:
|
case WC_STATUS_BAR:
|
||||||
++z_priority;
|
++z_priority;
|
||||||
|
|
||||||
@@ -1475,6 +1476,10 @@ void Window::FindWindowPlacementAndResize(int def_width, int def_height)
|
|||||||
|
|
||||||
int enlarge_x = max(min(def_width - this->width, _screen.width - this->width), 0);
|
int enlarge_x = max(min(def_width - this->width, _screen.width - this->width), 0);
|
||||||
int enlarge_y = max(min(def_height - this->height, free_height - this->height), 0);
|
int enlarge_y = max(min(def_height - this->height, free_height - this->height), 0);
|
||||||
|
if (wt && _settings_client.gui.vertical_toolbar &&
|
||||||
|
enlarge_x > _screen.width - wt->width * 2) {
|
||||||
|
//enlarge_x = _screen.width - wt->width * 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* X and Y has to go by step.. calculate it.
|
/* X and Y has to go by step.. calculate it.
|
||||||
* The cast to int is necessary else x/y are implicitly casted to
|
* The cast to int is necessary else x/y are implicitly casted to
|
||||||
@@ -1525,7 +1530,11 @@ static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &po
|
|||||||
int bottom = height + top;
|
int bottom = height + top;
|
||||||
|
|
||||||
const Window *main_toolbar = FindWindowByClass(WC_MAIN_TOOLBAR);
|
const Window *main_toolbar = FindWindowByClass(WC_MAIN_TOOLBAR);
|
||||||
if (left < 0 || (main_toolbar != NULL && top < main_toolbar->height) || right > _screen.width || bottom > _screen.height) return false;
|
if (!_settings_client.gui.vertical_toolbar || !main_toolbar) {
|
||||||
|
if (left < 0 || (main_toolbar != NULL && top < main_toolbar->height) || right > _screen.width || bottom > _screen.height) return false;
|
||||||
|
} else {
|
||||||
|
if (left < main_toolbar->width || top < 0 || right > _screen.width - main_toolbar->width * 2 || bottom > _screen.height) return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make sure it is not obscured by any window. */
|
/* Make sure it is not obscured by any window. */
|
||||||
const Window *w;
|
const Window *w;
|
||||||
@@ -1636,6 +1645,10 @@ static Point GetAutoPlacePosition(int width, int height)
|
|||||||
* of (+5, +5)
|
* of (+5, +5)
|
||||||
*/
|
*/
|
||||||
int left = 0, top = 24;
|
int left = 0, top = 24;
|
||||||
|
if (_settings_client.gui.vertical_toolbar) {
|
||||||
|
left = main_toolbar != NULL ? main_toolbar->width : 0;
|
||||||
|
top = 0;
|
||||||
|
}
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
FOR_ALL_WINDOWS_FROM_BACK(w) {
|
FOR_ALL_WINDOWS_FROM_BACK(w) {
|
||||||
@@ -1663,15 +1676,12 @@ Point GetToolbarAlignedWindowPosition(int window_width)
|
|||||||
assert(w != NULL);
|
assert(w != NULL);
|
||||||
Point pt;
|
Point pt;
|
||||||
if (_settings_client.gui.vertical_toolbar) {
|
if (_settings_client.gui.vertical_toolbar) {
|
||||||
pt.x = _current_text_dir == TD_RTL ? w->left + w->width : _screen.width - window_width - w->width;
|
// Retermine if the window was opened from the left or the right toolbar
|
||||||
|
pt.x = (_last_clicked_toolbar_idx == 0) ? w->left + w->width : _screen.width - w->width - window_width - 1;
|
||||||
pt.y = w->top;
|
pt.y = w->top;
|
||||||
} else {
|
} else {
|
||||||
|
pt.x = _current_text_dir == TD_RTL ? w->left : (w->left + w->width) - window_width;
|
||||||
pt.y = w->top + w->height;
|
pt.y = w->top + w->height;
|
||||||
if (_settings_client.gui.touchscreen_mode != TSC_NONE) {
|
|
||||||
pt.x = _current_text_dir == TD_RTL ? 0 : (_screen.width - window_width);
|
|
||||||
} else {
|
|
||||||
pt.x = _current_text_dir == TD_RTL ? w->left : (w->left + w->width) - window_width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return pt;
|
return pt;
|
||||||
}
|
}
|
||||||
@@ -1705,13 +1715,9 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
|
|||||||
(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
|
(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
|
||||||
w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
|
w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
|
||||||
|
|
||||||
if (_settings_client.gui.touchscreen_mode != TSC_NONE) {
|
pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10);
|
||||||
pt.x = _current_text_dir == TD_RTL ? 0 : (_screen.width - default_width);
|
if (pt.x > _screen.width + 10 - default_width) {
|
||||||
} else {
|
pt.x = (_screen.width + 10 - default_width) - 20;
|
||||||
pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10);
|
|
||||||
if (pt.x > _screen.width + 10 - default_width) {
|
|
||||||
pt.x = (_screen.width + 10 - default_width) - 20;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? w->height : 10);
|
pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? w->height : 10);
|
||||||
@@ -2064,6 +2070,7 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny)
|
|||||||
|
|
||||||
/* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */
|
/* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */
|
||||||
PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);
|
PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN);
|
||||||
|
PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR_RIGHT, 0), w->left, PHD_DOWN);
|
||||||
PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP);
|
PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2124,6 +2131,7 @@ void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
|
|||||||
*/
|
*/
|
||||||
int GetMainViewTop()
|
int GetMainViewTop()
|
||||||
{
|
{
|
||||||
|
if (_settings_client.gui.vertical_toolbar) return 0;
|
||||||
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
||||||
return (w == NULL) ? 0 : w->top + w->height;
|
return (w == NULL) ? 0 : w->top + w->height;
|
||||||
}
|
}
|
||||||
@@ -3290,6 +3298,7 @@ restart_search:
|
|||||||
if (w->window_class != WC_MAIN_WINDOW &&
|
if (w->window_class != WC_MAIN_WINDOW &&
|
||||||
w->window_class != WC_SELECT_GAME &&
|
w->window_class != WC_SELECT_GAME &&
|
||||||
w->window_class != WC_MAIN_TOOLBAR &&
|
w->window_class != WC_MAIN_TOOLBAR &&
|
||||||
|
w->window_class != WC_MAIN_TOOLBAR_RIGHT &&
|
||||||
w->window_class != WC_STATUS_BAR &&
|
w->window_class != WC_STATUS_BAR &&
|
||||||
w->window_class != WC_TOOLTIPS &&
|
w->window_class != WC_TOOLTIPS &&
|
||||||
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
|
(w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
|
||||||
@@ -3506,6 +3515,7 @@ void RelocateAllWindows(int neww, int newh)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
case WC_MAIN_TOOLBAR:
|
case WC_MAIN_TOOLBAR:
|
||||||
|
case WC_MAIN_TOOLBAR_RIGHT:
|
||||||
ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false);
|
ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false);
|
||||||
|
|
||||||
top = w->top;
|
top = w->top;
|
||||||
|
|||||||
Reference in New Issue
Block a user