mirror of https://github.com/OpenTTD/OpenTTD
(svn r13025) -Codechange: remove the need for two WindowEvents.
parent
f438700402
commit
68a1d75d9e
|
@ -1480,8 +1480,6 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
|
||||||
// Save our client
|
// Save our client
|
||||||
WP(w, menu_d).main_button = client_no;
|
WP(w, menu_d).main_button = client_no;
|
||||||
WP(w, menu_d).sel_index = 0;
|
WP(w, menu_d).sel_index = 0;
|
||||||
// We are a popup
|
|
||||||
_popup_menu_active = true;
|
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -1513,25 +1511,22 @@ static void ClientListPopupWndProc(Window *w, WindowEvent *e)
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_POPUPMENU_SELECT: {
|
case WE_MOUSELOOP: {
|
||||||
/* We selected an action */
|
/* We selected an action */
|
||||||
int index = (e->we.popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
|
int index = (_cursor.pos.y - w->top) / CLNWND_ROWSIZE;
|
||||||
|
|
||||||
if (index >= 0 && e->we.popupmenu.pt.y >= w->top) {
|
if (_left_button_down) {
|
||||||
HandleClientListPopupClick(index, WP(w, menu_d).main_button);
|
if (index == -1 || index == WP(w, menu_d).sel_index) return;
|
||||||
|
|
||||||
|
WP(w, menu_d).sel_index = index;
|
||||||
|
SetWindowDirty(w);
|
||||||
|
} else {
|
||||||
|
if (index >= 0 && _cursor.pos.y >= w->top) {
|
||||||
|
HandleClientListPopupClick(index, WP(w, menu_d).main_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteWindowById(WC_TOOLBAR_MENU, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteWindowById(WC_TOOLBAR_MENU, 0);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case WE_POPUPMENU_OVER: {
|
|
||||||
/* Our mouse hoovers over an action? Select it! */
|
|
||||||
int index = (e->we.popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
|
|
||||||
|
|
||||||
if (index == -1 || index == WP(w, menu_d).sel_index) return;
|
|
||||||
|
|
||||||
WP(w, menu_d).sel_index = index;
|
|
||||||
SetWindowDirty(w);
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,11 @@ static Point GetToolbarDropdownPos(uint16 parent_button, int width, int height)
|
||||||
* @param y Y coordinate of the position
|
* @param y Y coordinate of the position
|
||||||
* @return Index number of the menu item, or \c -1 if no valid selection under position
|
* @return Index number of the menu item, or \c -1 if no valid selection under position
|
||||||
*/
|
*/
|
||||||
static int GetMenuItemIndex(const Window *w, int x, int y)
|
static int GetMenuItemIndex(const Window *w)
|
||||||
{
|
{
|
||||||
|
int x = _cursor.pos.x;
|
||||||
|
int y = _cursor.pos.y;
|
||||||
|
|
||||||
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
|
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
|
||||||
y /= 10;
|
y /= 10;
|
||||||
|
|
||||||
|
@ -1153,34 +1156,30 @@ static void MenuWndProc(Window *w, WindowEvent *e)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WE_POPUPMENU_SELECT: {
|
case WE_MOUSELOOP: {
|
||||||
int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
|
int index = GetMenuItemIndex(w);
|
||||||
|
|
||||||
if (index < 0) {
|
if (_left_button_down) {
|
||||||
Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
|
if (index == -1 || index == WP(w, menu_d).sel_index) return;
|
||||||
if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button)
|
|
||||||
index = WP(w, menu_d).sel_index;
|
WP(w, menu_d).sel_index = index;
|
||||||
|
w->SetDirty();
|
||||||
|
} else {
|
||||||
|
if (index < 0) {
|
||||||
|
Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
|
||||||
|
if (GetWidgetFromPos(w2, _cursor.pos.x - w2->left, _cursor.pos.y - w2->top) == WP(w, menu_d).main_button)
|
||||||
|
index = WP(w, menu_d).sel_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
int action_id = WP(w, menu_d).action_id;
|
||||||
|
delete w;
|
||||||
|
|
||||||
|
if (index >= 0) {
|
||||||
|
assert((uint)index <= lengthof(_menu_clicked_procs));
|
||||||
|
_menu_clicked_procs[action_id](index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int action_id = WP(w, menu_d).action_id;
|
|
||||||
delete w;
|
|
||||||
|
|
||||||
if (index >= 0) {
|
|
||||||
assert((uint)index <= lengthof(_menu_clicked_procs));
|
|
||||||
_menu_clicked_procs[action_id](index);
|
|
||||||
}
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_POPUPMENU_OVER: {
|
|
||||||
int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
|
|
||||||
|
|
||||||
if (index == -1 || index == WP(w, menu_d).sel_index) return;
|
|
||||||
|
|
||||||
WP(w, menu_d).sel_index = index;
|
|
||||||
w->SetDirty();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1262,8 +1261,6 @@ static Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base
|
||||||
WP(w, menu_d).checked_items = 0;
|
WP(w, menu_d).checked_items = 0;
|
||||||
WP(w, menu_d).disabled_items = disabled_mask;
|
WP(w, menu_d).disabled_items = disabled_mask;
|
||||||
|
|
||||||
_popup_menu_active = true;
|
|
||||||
|
|
||||||
SndPlayFx(SND_15_BEEP);
|
SndPlayFx(SND_15_BEEP);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -1350,51 +1347,48 @@ static void PlayerMenuWndProc(Window *w, WindowEvent *e)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WE_POPUPMENU_SELECT: {
|
case WE_MOUSELOOP: {
|
||||||
int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
|
int index = GetMenuItemIndex(w);
|
||||||
int action_id = WP(w, menu_d).action_id;
|
|
||||||
|
|
||||||
/* We have a new entry at the top of the list of menu 9 when networking
|
if (_left_button_down) {
|
||||||
* so keep that in count */
|
UpdatePlayerMenuHeight(w);
|
||||||
if (_networking && WP(w, menu_d).main_button == 9) {
|
/* We have a new entry at the top of the list of menu 9 when networking
|
||||||
if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
|
* so keep that in count */
|
||||||
|
if (_networking && WP(w, menu_d).main_button == 9) {
|
||||||
|
if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
|
||||||
|
} else {
|
||||||
|
index = GetPlayerIndexFromMenu(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == -1 || index == WP(w, menu_d).sel_index) return;
|
||||||
|
|
||||||
|
WP(w, menu_d).sel_index = index;
|
||||||
|
w->SetDirty();
|
||||||
} else {
|
} else {
|
||||||
index = GetPlayerIndexFromMenu(index);
|
int action_id = WP(w, menu_d).action_id;
|
||||||
}
|
|
||||||
|
|
||||||
if (index < 0) {
|
/* We have a new entry at the top of the list of menu 9 when networking
|
||||||
Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
|
* so keep that in count */
|
||||||
if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button)
|
if (_networking && WP(w, menu_d).main_button == 9) {
|
||||||
index = WP(w, menu_d).sel_index;
|
if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
|
||||||
}
|
} else {
|
||||||
|
index = GetPlayerIndexFromMenu(index);
|
||||||
|
}
|
||||||
|
|
||||||
delete w;
|
if (index < 0) {
|
||||||
|
Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
|
||||||
|
if (GetWidgetFromPos(w2, _cursor.pos.x - w2->left, _cursor.pos.y - w2->top) == WP(w, menu_d).main_button)
|
||||||
|
index = WP(w, menu_d).sel_index;
|
||||||
|
}
|
||||||
|
|
||||||
if (index >= 0) {
|
delete w;
|
||||||
assert(index >= 0 && index < 30);
|
|
||||||
_menu_clicked_procs[action_id](index);
|
if (index >= 0) {
|
||||||
|
assert(index >= 0 && index < 30);
|
||||||
|
_menu_clicked_procs[action_id](index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_POPUPMENU_OVER: {
|
|
||||||
int index;
|
|
||||||
UpdatePlayerMenuHeight(w);
|
|
||||||
index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
|
|
||||||
|
|
||||||
/* We have a new entry at the top of the list of menu 9 when networking
|
|
||||||
* so keep that in count */
|
|
||||||
if (_networking && WP(w, menu_d).main_button == 9) {
|
|
||||||
if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1;
|
|
||||||
} else {
|
|
||||||
index = GetPlayerIndexFromMenu(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == -1 || index == WP(w, menu_d).sel_index) return;
|
|
||||||
|
|
||||||
WP(w, menu_d).sel_index = index;
|
|
||||||
w->SetDirty();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1426,7 +1420,7 @@ static Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray)
|
||||||
WP(w, menu_d).main_button = main_button;
|
WP(w, menu_d).main_button = main_button;
|
||||||
WP(w, menu_d).checked_items = gray;
|
WP(w, menu_d).checked_items = gray;
|
||||||
WP(w, menu_d).disabled_items = 0;
|
WP(w, menu_d).disabled_items = 0;
|
||||||
_popup_menu_active = true;
|
|
||||||
SndPlayFx(SND_15_BEEP);
|
SndPlayFx(SND_15_BEEP);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ byte _scroller_click_timeout;
|
||||||
|
|
||||||
bool _scrolling_scrollbar;
|
bool _scrolling_scrollbar;
|
||||||
bool _scrolling_viewport;
|
bool _scrolling_viewport;
|
||||||
bool _popup_menu_active;
|
|
||||||
|
|
||||||
byte _special_mouse_mode;
|
byte _special_mouse_mode;
|
||||||
|
|
||||||
|
@ -1131,31 +1130,6 @@ static bool HandleDragDrop()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandlePopupMenu()
|
|
||||||
{
|
|
||||||
if (!_popup_menu_active) return true;
|
|
||||||
|
|
||||||
Window *w = FindWindowById(WC_TOOLBAR_MENU, 0);
|
|
||||||
if (w == NULL) {
|
|
||||||
_popup_menu_active = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowEvent e;
|
|
||||||
if (_left_button_down) {
|
|
||||||
e.event = WE_POPUPMENU_OVER;
|
|
||||||
e.we.popupmenu.pt = _cursor.pos;
|
|
||||||
} else {
|
|
||||||
_popup_menu_active = false;
|
|
||||||
e.event = WE_POPUPMENU_SELECT;
|
|
||||||
e.we.popupmenu.pt = _cursor.pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
w->HandleWindowEvent(&e);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool HandleMouseOver()
|
static bool HandleMouseOver()
|
||||||
{
|
{
|
||||||
Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
|
Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
|
||||||
|
@ -1827,7 +1801,6 @@ void MouseLoop(MouseClick click, int mousewheel)
|
||||||
UpdateTileSelection();
|
UpdateTileSelection();
|
||||||
if (!VpHandlePlaceSizingDrag()) return;
|
if (!VpHandlePlaceSizingDrag()) return;
|
||||||
if (!HandleDragDrop()) return;
|
if (!HandleDragDrop()) return;
|
||||||
if (!HandlePopupMenu()) return;
|
|
||||||
if (!HandleWindowDragging()) return;
|
if (!HandleWindowDragging()) return;
|
||||||
if (!HandleScrollbarScrolling()) return;
|
if (!HandleScrollbarScrolling()) return;
|
||||||
if (!HandleViewportScroll()) return;
|
if (!HandleViewportScroll()) return;
|
||||||
|
|
|
@ -126,8 +126,6 @@ enum WindowEventCodes {
|
||||||
WE_ABORT_PLACE_OBJ,
|
WE_ABORT_PLACE_OBJ,
|
||||||
WE_ON_EDIT_TEXT,
|
WE_ON_EDIT_TEXT,
|
||||||
WE_ON_EDIT_TEXT_CANCEL,
|
WE_ON_EDIT_TEXT_CANCEL,
|
||||||
WE_POPUPMENU_SELECT,
|
|
||||||
WE_POPUPMENU_OVER,
|
|
||||||
WE_DRAGDROP,
|
WE_DRAGDROP,
|
||||||
WE_PLACE_DRAG,
|
WE_PLACE_DRAG,
|
||||||
WE_PLACE_MOUSEUP,
|
WE_PLACE_MOUSEUP,
|
||||||
|
@ -178,10 +176,6 @@ struct WindowEvent {
|
||||||
char *str;
|
char *str;
|
||||||
} edittext;
|
} edittext;
|
||||||
|
|
||||||
struct {
|
|
||||||
Point pt;
|
|
||||||
} popupmenu;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int button;
|
int button;
|
||||||
int index;
|
int index;
|
||||||
|
@ -563,7 +557,6 @@ extern byte _scroller_click_timeout;
|
||||||
|
|
||||||
extern bool _scrolling_scrollbar;
|
extern bool _scrolling_scrollbar;
|
||||||
extern bool _scrolling_viewport;
|
extern bool _scrolling_viewport;
|
||||||
extern bool _popup_menu_active;
|
|
||||||
|
|
||||||
extern byte _special_mouse_mode;
|
extern byte _special_mouse_mode;
|
||||||
enum SpecialMouseMode {
|
enum SpecialMouseMode {
|
||||||
|
|
Loading…
Reference in New Issue