mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
This commit is contained in:
parent
480ced43c9
commit
a014ef6340
22
widget.c
22
widget.c
|
@ -125,14 +125,11 @@ void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y)
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************
|
/** Returns the index for the widget located at the given position
|
||||||
* Returns the index for the widget located at the given
|
* relative to the window. It includes all widget-corner pixels as well.
|
||||||
* position relative to the window.
|
* @param *w Window to look inside
|
||||||
* Parameters:
|
* @param x,y Window client coordinates
|
||||||
* w - Window
|
* @return A widget index, or -1 if no widget was found.
|
||||||
* x/y - Window client coordinates
|
|
||||||
* Returns:
|
|
||||||
* A widget index, or -1 if no widget was found.
|
|
||||||
*/
|
*/
|
||||||
int GetWidgetFromPos(Window *w, int x, int y)
|
int GetWidgetFromPos(Window *w, int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -141,19 +138,16 @@ int GetWidgetFromPos(Window *w, int x, int y)
|
||||||
|
|
||||||
// Go through the widgets and check if we find the widget that the coordinate is
|
// Go through the widgets and check if we find the widget that the coordinate is
|
||||||
// inside.
|
// inside.
|
||||||
for(index=0,wi=w->widget; wi->type != WWT_LAST; index++, wi++) {
|
for (index = 0,wi = w->widget; wi->type != WWT_LAST; index++, wi++) {
|
||||||
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME)
|
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x >= wi->left &&
|
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom &&
|
||||||
x < wi->right &&
|
!HASBIT(w->hidden_state,index)) {
|
||||||
y >= wi->top &&
|
|
||||||
y < wi->bottom && !HASBIT(w->hidden_state,index)) {
|
|
||||||
found_index = index;
|
found_index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the index
|
|
||||||
return found_index;
|
return found_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
window.c
17
window.c
|
@ -98,13 +98,22 @@ void DispatchRightClickEvent(Window *w, int x, int y) {
|
||||||
w->wndproc(w, &e);
|
w->wndproc(w, &e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Dispatch the mousewheel-action to the window which will scroll any
|
||||||
void DispatchMouseWheelEvent(Window *w, uint widget, int wheel)
|
* compatible scrollbars if the mouse is pointed over the bar or its contents
|
||||||
|
* @param *w Window
|
||||||
|
* @param widget the widget where the scrollwheel was used
|
||||||
|
* @param wheel scroll up or down
|
||||||
|
*/
|
||||||
|
void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
|
||||||
{
|
{
|
||||||
const Widget *wi1 = &w->widget[widget];
|
const Widget *wi1, *wi2;
|
||||||
const Widget *wi2 = &w->widget[widget + 1];
|
|
||||||
Scrollbar *sb;
|
Scrollbar *sb;
|
||||||
|
|
||||||
|
if (widget < 0) return;
|
||||||
|
|
||||||
|
wi1 = &w->widget[widget];
|
||||||
|
wi2 = &w->widget[widget + 1];
|
||||||
|
|
||||||
/* The listbox can only scroll if scrolling was done on the scrollbar itself,
|
/* The listbox can only scroll if scrolling was done on the scrollbar itself,
|
||||||
* or on the listbox (and the next item is (must be) the scrollbar)
|
* or on the listbox (and the next item is (must be) the scrollbar)
|
||||||
* XXX - should be rewritten as a widget-dependent scroller but that's
|
* XXX - should be rewritten as a widget-dependent scroller but that's
|
||||||
|
|
2
window.h
2
window.h
|
@ -546,7 +546,7 @@ enum WindowFlags {
|
||||||
|
|
||||||
void DispatchLeftClickEvent(Window *w, int x, int y);
|
void DispatchLeftClickEvent(Window *w, int x, int y);
|
||||||
void DispatchRightClickEvent(Window *w, int x, int y);
|
void DispatchRightClickEvent(Window *w, int x, int y);
|
||||||
void DispatchMouseWheelEvent(Window *w, uint widget, int wheel);
|
void DispatchMouseWheelEvent(Window *w, int widget, int wheel);
|
||||||
|
|
||||||
/* window.c */
|
/* window.c */
|
||||||
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
|
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
|
||||||
|
|
Loading…
Reference in New Issue