truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: #include "window.h" truelight@0: #include "gfx.h" darkvater@152: #include "viewport.h" dominik@126: #include "console.h" truelight@0: tron@350: // delta between mouse cursor and upper left corner of dragged window tron@350: static Point _drag_delta; tron@350: truelight@0: void HandleButtonClick(Window *w, byte widget) truelight@0: { truelight@0: w->click_state |= (1 << widget); truelight@0: w->flags4 |= 5 << WF_TIMEOUT_SHL; truelight@0: InvalidateWidget(w, widget); truelight@0: } truelight@0: truelight@0: void DispatchLeftClickEvent(Window *w, int x, int y) { truelight@0: WindowEvent e; truelight@0: const Widget *wi; truelight@0: truelight@0: e.click.pt.x = x; truelight@0: e.click.pt.y = y; truelight@0: e.event = WE_CLICK; truelight@0: truelight@0: if (w->desc_flags & WDF_DEF_WIDGET) { truelight@158: e.click.widget = GetWidgetFromPos(w, x, y); truelight@0: if (e.click.widget < 0) return; /* exit if clicked outside of widgets */ truelight@158: truelight@0: wi = &w->widget[e.click.widget]; darkvater@222: darkvater@211: /* don't allow any interaction if the button has been disabled */ darkvater@211: if (HASBIT(w->disabled_state, e.click.widget)) darkvater@211: return; truelight@0: truelight@0: if (wi->type & 0xE0) { darkvater@211: /* special widget handling for buttons*/ truelight@0: switch(wi->type) { darkvater@211: case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */ darkvater@211: case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ truelight@0: HandleButtonClick(w, e.click.widget); truelight@0: break; truelight@0: case WWT_NODISTXTBTN: truelight@158: break; truelight@0: } truelight@0: } else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_HSCROLLBAR) { truelight@0: ScrollbarClickHandler(w, wi, e.click.pt.x, e.click.pt.y); truelight@0: } truelight@0: truelight@0: w->wndproc(w, &e); truelight@158: truelight@0: if (w->desc_flags & WDF_STD_BTN) { truelight@0: if (e.click.widget == 0) DeleteWindow(w); truelight@158: else { truelight@0: if (e.click.widget == 1) { truelight@158: if (_ctrl_pressed) truelight@158: StartWindowSizing(w); truelight@158: else truelight@0: StartWindowDrag(w); truelight@0: } truelight@0: } truelight@0: } truelight@0: } else { truelight@0: w->wndproc(w, &e); truelight@0: } truelight@0: } truelight@0: truelight@0: void DispatchRightClickEvent(Window *w, int x, int y) { truelight@0: WindowEvent e; truelight@0: truelight@0: /* default tooltips handler? */ truelight@0: if (w->desc_flags & WDF_STD_TOOLTIPS) { truelight@0: e.click.widget = GetWidgetFromPos(w, x, y); truelight@0: if (e.click.widget < 0) truelight@0: return; /* exit if clicked outside of widgets */ truelight@0: truelight@0: if (w->widget[e.click.widget].tooltips != 0) { truelight@0: GuiShowTooltips(w->widget[e.click.widget].tooltips); truelight@0: return; truelight@0: } truelight@0: } truelight@0: truelight@0: e.event = WE_RCLICK; truelight@0: e.click.pt.x = x; truelight@0: e.click.pt.y = y; truelight@158: w->wndproc(w, &e); truelight@0: } truelight@0: truelight@0: truelight@0: void DispatchMouseWheelEvent(Window *w, int wheel) truelight@0: { dominik@86: if (w->vscroll.count > w->vscroll.cap) { truelight@0: int pos = clamp(w->vscroll.pos + wheel, 0, w->vscroll.count - w->vscroll.cap); truelight@0: if (pos != w->vscroll.pos) { truelight@0: w->vscroll.pos = pos; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) truelight@0: { truelight@0: Window *w; truelight@0: DrawPixelInfo bk; truelight@0: _cur_dpi = &bk; truelight@0: truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@158: if (right > w->left && truelight@0: bottom > w->top && truelight@0: left < w->left + w->width && truelight@0: top < w->top + w->height) { truelight@158: DrawOverlappedWindow(w, left, top, right, bottom); truelight@158: } truelight@0: } truelight@0: } truelight@0: truelight@0: void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom) truelight@0: { truelight@0: Window *v = w; truelight@0: int x; truelight@0: truelight@0: while (++v != _last_window) { truelight@0: if (right > v->left && truelight@0: bottom > v->top && truelight@0: left < v->left + v->width && truelight@0: top < v->top + v->height) { truelight@158: truelight@0: if (left < (x=v->left)) { truelight@0: DrawOverlappedWindow(w, left, top, x, bottom); truelight@0: DrawOverlappedWindow(w, x, top, right, bottom); truelight@0: return; truelight@0: } truelight@0: truelight@0: if (right > (x=v->left + v->width)) { truelight@0: DrawOverlappedWindow(w, left, top, x, bottom); truelight@0: DrawOverlappedWindow(w, x, top, right, bottom); truelight@0: return; truelight@0: } truelight@0: truelight@0: if (top < (x=v->top)) { truelight@0: DrawOverlappedWindow(w, left, top, right, x); truelight@0: DrawOverlappedWindow(w, left, x, right, bottom); truelight@0: return; truelight@0: } truelight@0: truelight@0: if (bottom > (x=v->top + v->height)) { truelight@0: DrawOverlappedWindow(w, left, top, right, x); truelight@0: DrawOverlappedWindow(w, left, x, right, bottom); truelight@0: return; truelight@0: } truelight@0: truelight@0: return; truelight@0: } truelight@0: } truelight@0: truelight@0: { truelight@158: DrawPixelInfo *dp = _cur_dpi; truelight@0: dp->width = right - left; truelight@0: dp->height = bottom - top; truelight@0: dp->left = left - w->left; truelight@0: dp->top = top - w->top; truelight@0: dp->pitch = _screen.pitch; truelight@0: dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left; truelight@0: dp->zoom = 0; truelight@0: CallWindowEventNP(w, WE_PAINT); truelight@0: } truelight@0: } truelight@0: truelight@0: void CallWindowEventNP(Window *w, int event) truelight@0: { truelight@0: WindowEvent e; truelight@0: e.event = event; truelight@0: w->wndproc(w, &e); truelight@0: } truelight@0: truelight@0: void SetWindowDirty(Window *w) truelight@0: { truelight@0: if (w == NULL) truelight@0: return; truelight@158: truelight@0: SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); truelight@0: } truelight@0: truelight@0: void DeleteWindow(Window *w) truelight@0: { truelight@0: WindowClass wc; truelight@0: WindowNumber wn; truelight@0: ViewPort *vp; truelight@0: Window *v; truelight@0: int count; truelight@0: truelight@0: if (w == NULL) truelight@0: return; truelight@0: truelight@0: if (_thd.place_mode != 0 && _thd.window_class == w->window_class && _thd.window_number == w->window_number) { truelight@0: ResetObjectToPlace(); truelight@0: } truelight@0: truelight@0: wc = w->window_class; truelight@0: wn = w->window_number; truelight@0: truelight@0: CallWindowEventNP(w, WE_DESTROY); truelight@0: truelight@0: w = FindWindowById(wc, wn); truelight@0: truelight@0: vp = w->viewport; truelight@0: w->viewport = NULL; truelight@0: if (vp != NULL) { truelight@0: _active_viewports &= ~(1 << (vp - _viewports)); truelight@0: vp->width = 0; truelight@0: } truelight@0: truelight@0: SetWindowDirty(w); truelight@0: truelight@0: v = --_last_window; truelight@0: count = (byte*)v - (byte*)w; truelight@0: memcpy(w, w + 1, count); truelight@0: } truelight@0: truelight@0: Window *FindWindowById(WindowClass cls, WindowNumber number) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@158: if (w->window_class == cls && truelight@0: w->window_number == number) { truelight@0: return w; truelight@0: } truelight@158: } truelight@0: truelight@0: return NULL; truelight@0: } truelight@0: truelight@0: void DeleteWindowById(WindowClass cls, WindowNumber number) truelight@0: { truelight@0: DeleteWindow(FindWindowById(cls, number)); truelight@158: } truelight@0: truelight@0: Window *BringWindowToFrontById(WindowClass cls, WindowNumber number) truelight@0: { truelight@0: Window *w = FindWindowById(cls, number); truelight@0: truelight@0: if (w != NULL) { truelight@0: w->flags4 |= WF_WHITE_BORDER_MASK; truelight@0: SetWindowDirty(w); truelight@0: BringWindowToFront(w); truelight@0: } truelight@0: truelight@0: return w; truelight@0: } truelight@0: truelight@0: Window *BringWindowToFront(Window *w) truelight@0: { truelight@0: Window *v; truelight@0: truelight@0: v = _last_window; truelight@0: do { truelight@0: if (--v < _windows) truelight@0: return w; truelight@0: } while (v->window_class == WC_MAIN_TOOLBAR || v->window_class == WC_STATUS_BAR || v->window_class == WC_NEWS_WINDOW); truelight@0: truelight@0: if (w == v) truelight@0: return w; truelight@0: truelight@0: assert(w < v); truelight@0: truelight@0: do { truelight@0: memswap(w, w+1, sizeof(Window)); truelight@0: w++; truelight@0: } while (v != w); truelight@0: truelight@0: SetWindowDirty(w); truelight@0: truelight@0: return w; truelight@0: } truelight@0: truelight@0: Window *AllocateWindow( truelight@0: int x, truelight@0: int y, truelight@0: int width, truelight@0: int height, truelight@158: WindowProc *proc, truelight@0: WindowClass cls, truelight@0: const Widget *widget) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: restart:; truelight@0: w = _last_window; truelight@0: truelight@0: if (w >= endof(_windows)) { truelight@0: for(w=_windows; ;w++) { truelight@0: assert(w < _last_window); truelight@0: truelight@0: if (w->window_class != WC_MAIN_WINDOW && w->window_class != WC_MAIN_TOOLBAR && truelight@0: w->window_class != WC_STATUS_BAR && w->window_class != WC_NEWS_WINDOW) { truelight@158: truelight@0: DeleteWindow(w); truelight@0: goto restart; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: if (w != _windows && cls != WC_NEWS_WINDOW) { truelight@0: Window *v; truelight@0: truelight@0: v = FindWindowById(WC_MAIN_TOOLBAR, 0); truelight@0: if (v) { truelight@0: memmove(v+1, v, (byte*)w - (byte*)v); truelight@0: w = v; truelight@0: } truelight@0: truelight@0: v = FindWindowById(WC_STATUS_BAR, 0); truelight@0: if (v) { truelight@0: memmove(v+1, v, (byte*)w - (byte*)v); truelight@0: w = v; truelight@0: } truelight@0: } truelight@0: truelight@0: /* XXX: some more code here */ truelight@0: w->window_class = cls; truelight@0: w->flags4 = WF_WHITE_BORDER_MASK; truelight@0: w->caption_color = 0xFF; truelight@0: w->window_number = 0; truelight@0: w->left = x; truelight@0: w->top = y; truelight@0: w->width = width; truelight@0: w->height = height; truelight@0: w->viewport = NULL; truelight@0: w->desc_flags = 0; truelight@0: // w->landscape_assoc = 0xFFFF; truelight@0: w->wndproc = proc; truelight@0: w->click_state = 0; truelight@0: w->disabled_state = 0; truelight@0: w->hidden_state = 0; truelight@0: // w->unk22 = 0xFFFF; truelight@0: w->vscroll.pos = 0; truelight@0: w->vscroll.count = 0; truelight@0: w->hscroll.pos = 0; truelight@0: w->hscroll.count = 0; truelight@0: w->widget = widget; truelight@0: truelight@158: { truelight@158: int i; truelight@158: for (i=0;icustom);i++) truelight@158: w->custom[i] = 0; truelight@158: } truelight@0: truelight@0: _last_window++; truelight@0: truelight@0: SetWindowDirty(w); truelight@158: dominik@116: CallWindowEventNP(w, WE_CREATE); truelight@0: truelight@0: return w; truelight@0: } truelight@0: truelight@0: Window *AllocateWindowAutoPlace2( truelight@0: WindowClass exist_class, truelight@0: WindowNumber exist_num, truelight@0: int width, truelight@0: int height, truelight@158: WindowProc *proc, truelight@0: WindowClass cls, truelight@0: const Widget *widget) truelight@0: { truelight@0: Window *w; truelight@0: int x; truelight@158: truelight@0: w = FindWindowById(exist_class, exist_num); truelight@0: if (w == NULL || w->left >= (_screen.width-20) || w->left <= -60 || w->top >= (_screen.height-20)) { truelight@0: return AllocateWindowAutoPlace(width,height,proc,cls,widget); truelight@158: } truelight@0: truelight@0: x = w->left; truelight@0: if (x > _screen.width - width) truelight@0: x = (_screen.width - width) - 20; truelight@0: truelight@0: return AllocateWindow(x+10,w->top+10,width,height,proc,cls,widget); truelight@0: } truelight@0: truelight@0: truelight@0: typedef struct SizeRect { truelight@0: int left,top,width,height; truelight@0: } SizeRect; truelight@0: truelight@0: truelight@0: static SizeRect _awap_r; truelight@0: truelight@0: static bool IsGoodAutoPlace1(int left, int top) truelight@0: { truelight@0: int right,bottom; truelight@0: Window *w; truelight@0: truelight@0: _awap_r.left= left; truelight@0: _awap_r.top = top; truelight@0: right = _awap_r.width + left; truelight@0: bottom = _awap_r.height + top; truelight@0: truelight@0: if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) truelight@0: return false; truelight@0: truelight@158: // Make sure it is not obscured by any window. truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class == WC_MAIN_WINDOW) truelight@0: continue; truelight@0: truelight@158: if (right > w->left && truelight@0: w->left + w->width > left && truelight@0: bottom > w->top && truelight@0: w->top + w->height > top) truelight@0: return false; truelight@158: } truelight@0: truelight@0: return true; truelight@0: } truelight@0: truelight@0: static bool IsGoodAutoPlace2(int left, int top) truelight@0: { truelight@0: int width,height; truelight@0: Window *w; truelight@0: truelight@0: _awap_r.left= left; truelight@0: _awap_r.top = top; truelight@0: width = _awap_r.width; truelight@0: height = _awap_r.height; truelight@0: truelight@0: if (left < -(width>>2) || left > _screen.width - (width>>1)) truelight@0: return false; truelight@0: if (top < 22 || top > _screen.height - (height>>2)) truelight@0: return false; truelight@0: truelight@158: // Make sure it is not obscured by any window. truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class == WC_MAIN_WINDOW) truelight@0: continue; truelight@0: truelight@158: if (left + width > w->left && truelight@0: w->left + w->width > left && truelight@0: top + height > w->top && truelight@0: w->top + w->height > top) truelight@0: return false; truelight@158: } truelight@0: truelight@0: return true; truelight@0: } truelight@0: truelight@0: Point GetAutoPlacePosition(int width, int height) { truelight@0: Window *w; truelight@0: Point pt; truelight@0: truelight@0: _awap_r.width = width; truelight@0: _awap_r.height = height; truelight@0: truelight@0: if (IsGoodAutoPlace1(0, 24)) goto ok_pos; truelight@0: truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class == WC_MAIN_WINDOW) truelight@0: continue; truelight@0: truelight@0: if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos; truelight@0: if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos; truelight@158: } truelight@158: truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class == WC_MAIN_WINDOW) truelight@0: continue; truelight@0: truelight@0: if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos; truelight@0: if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos; truelight@0: if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos; truelight@0: if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos; truelight@0: } truelight@0: truelight@0: { truelight@0: int left=0,top=24; truelight@158: truelight@0: restart:; truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->left == left && w->top == top) { truelight@0: left += 5; truelight@0: top += 5; truelight@0: goto restart; truelight@0: } truelight@0: } truelight@158: truelight@0: pt.x = left; truelight@0: pt.y = top; truelight@0: return pt; truelight@0: } truelight@158: truelight@0: ok_pos:; truelight@0: pt.x = _awap_r.left; truelight@0: pt.y = _awap_r.top; truelight@0: return pt; truelight@0: } truelight@0: truelight@0: Window *AllocateWindowAutoPlace( truelight@0: int width, truelight@0: int height, truelight@158: WindowProc *proc, truelight@0: WindowClass cls, truelight@0: const Widget *widget) { truelight@0: truelight@0: Point pt = GetAutoPlacePosition(width, height); truelight@0: return AllocateWindow(pt.x, pt.y, width, height, proc, cls, widget); truelight@0: } truelight@0: truelight@0: Window *AllocateWindowDescFront(const WindowDesc *desc, int value) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: if (BringWindowToFrontById(desc->cls, value)) truelight@0: return NULL; truelight@0: w = AllocateWindowDesc(desc); truelight@0: w->window_number = value; truelight@0: return w; truelight@0: } truelight@0: truelight@0: Window *AllocateWindowDesc(const WindowDesc *desc) truelight@0: { truelight@0: Point pt; truelight@0: Window *w; truelight@0: truelight@158: if (desc->parent_cls != WC_MAIN_WINDOW && truelight@0: (w = FindWindowById(desc->parent_cls, _alloc_wnd_parent_num), _alloc_wnd_parent_num=0, w) != NULL && truelight@0: w->left < _screen.width-20 && w->left > -60 && w->top < _screen.height-20) { truelight@0: pt.x = w->left + 10; truelight@0: if (pt.x > _screen.width + 10 - desc->width) truelight@0: pt.x = (_screen.width + 10 - desc->width) - 20; truelight@0: pt.y = w->top + 10; darkvater@77: } else if (desc->cls == WC_BUILD_TOOLBAR) { // open Build Toolbars aligned darkvater@68: /* Override the position if a toolbar is opened according to the place of the maintoolbar darkvater@68: * The main toolbar (WC_MAIN_TOOLBAR) is 640px in width */ darkvater@68: switch (_patches.toolbar_pos) { darkvater@68: case 1: pt.x = ((_screen.width + 640) >> 1) - desc->width; break; darkvater@68: case 2: pt.x = _screen.width - desc->width; break; darkvater@68: default: pt.x = 640 - desc->width; darkvater@68: } darkvater@68: pt.y = desc->top; truelight@0: } else { truelight@0: pt.x = desc->left; truelight@0: pt.y = desc->top; truelight@0: if (pt.x == WDP_AUTO) { truelight@0: pt = GetAutoPlacePosition(desc->width, desc->height); truelight@0: } else { truelight@0: if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1; truelight@0: if (pt.y == WDP_CENTER) pt.y = (_screen.height - desc->height) >> 1; truelight@0: } truelight@0: } truelight@0: truelight@0: w = AllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets); truelight@0: w->desc_flags = desc->flags; truelight@0: return w; truelight@0: } truelight@0: truelight@0: Window *FindWindowFromPt(int x, int y) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: for(w=_last_window; w != _windows;) { truelight@0: --w; truelight@0: if (IS_INSIDE_1D(x, w->left, w->width) && truelight@0: IS_INSIDE_1D(y, w->top, w->height)) truelight@0: return w; truelight@0: } truelight@0: truelight@0: return NULL; truelight@0: } truelight@0: truelight@0: truelight@0: void InitWindowSystem() darkvater@152: { dominik@136: IConsoleClose(); truelight@0: memset(&_windows, 0, sizeof(_windows)); truelight@0: _last_window = _windows; truelight@0: memset(_viewports, 0, sizeof(_viewports)); truelight@0: _active_viewports = 0; truelight@0: } truelight@0: truelight@0: void DecreaseWindowCounters() truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: truelight@0: for(w=_last_window; w != _windows;) { truelight@0: --w; truelight@0: // Unclick scrollbar buttons if they are pressed. truelight@0: if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { truelight@0: w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: CallWindowEventNP(w, WE_MOUSELOOP); truelight@0: } truelight@0: truelight@0: for(w=_last_window; w != _windows;) { truelight@0: --w; truelight@158: truelight@0: if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { truelight@0: CallWindowEventNP(w, WE_TIMEOUT); truelight@0: if (w->desc_flags & WDF_UNCLICK_BUTTONS) truelight@0: UnclickWindowButtons(w); truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: Window *GetCallbackWnd() truelight@0: { truelight@0: return FindWindowById(_thd.window_class, _thd.window_number); truelight@0: } truelight@0: truelight@0: void HandlePlacePresize() truelight@0: { truelight@0: Window *w; truelight@0: WindowEvent e; truelight@0: truelight@0: if (_special_mouse_mode != WSM_PRESIZE) truelight@0: return; truelight@0: truelight@0: if ((w = GetCallbackWnd()) == NULL) truelight@0: return; truelight@0: truelight@0: e.place.pt = GetTileBelowCursor(); truelight@0: if (e.place.pt.x == -1) { truelight@0: _thd.selend.x = -1; truelight@0: return; truelight@0: } truelight@0: e.place.tile = TILE_FROM_XY(e.place.pt.x, e.place.pt.y); truelight@0: e.event = WE_PLACE_PRESIZE; truelight@0: w->wndproc(w, &e); truelight@0: } truelight@0: truelight@0: bool HandleDragDrop() truelight@0: { truelight@0: Window *w; truelight@0: WindowEvent e; truelight@0: truelight@0: if (_special_mouse_mode != WSM_DRAGDROP) truelight@0: return true; truelight@0: truelight@0: if (_left_button_down) truelight@0: return false; truelight@158: truelight@0: w = GetCallbackWnd(); truelight@0: truelight@0: ResetObjectToPlace(); truelight@0: truelight@0: if (w) { truelight@0: // send an event in client coordinates. truelight@0: e.event = WE_DRAGDROP; truelight@0: e.dragdrop.pt.x = _cursor.pos.x - w->left; truelight@0: e.dragdrop.pt.y = _cursor.pos.y - w->top; truelight@0: e.dragdrop.widget = GetWidgetFromPos(w, e.dragdrop.pt.x, e.dragdrop.pt.y); truelight@0: w->wndproc(w, &e); truelight@0: } truelight@0: return false; truelight@0: } truelight@0: truelight@0: bool HandlePopupMenu() truelight@0: { truelight@0: Window *w; truelight@0: WindowEvent e; truelight@0: truelight@0: if (!_popup_menu_active) truelight@0: return true; truelight@0: truelight@0: w = FindWindowById(WC_TOOLBAR_MENU, 0); truelight@0: if (w == NULL) { truelight@0: _popup_menu_active = false; truelight@0: return false; truelight@0: } truelight@0: truelight@0: if (_left_button_down) { truelight@0: e.event = WE_POPUPMENU_OVER; truelight@0: e.popupmenu.pt = _cursor.pos; truelight@0: w->wndproc(w, &e); truelight@0: } else { truelight@0: _popup_menu_active = false; truelight@0: e.event = WE_POPUPMENU_SELECT; truelight@0: e.popupmenu.pt = _cursor.pos; truelight@0: w->wndproc(w, &e); truelight@0: } truelight@0: truelight@0: return false; truelight@0: } truelight@0: truelight@158: bool HandleWindowDragging() truelight@0: { truelight@0: Window *w; truelight@0: // Get out immediately if no window is being dragged at all. truelight@0: if (!_dragging_window) truelight@0: return true; truelight@0: truelight@0: // Otherwise find the window... tron@350: for (w = _windows; w != _last_window; w++) { tron@350: if (w->flags4 & WF_DRAGGING) { tron@350: const Window *v; tron@350: int x; tron@350: int y; tron@350: int nx; tron@350: int ny; truelight@158: truelight@0: // Stop the dragging if the left mouse button was released truelight@0: if (!_left_button_down) { tron@350: w->flags4 &= ~WF_DRAGGING; truelight@0: break; truelight@0: } truelight@0: truelight@0: SetWindowDirty(w); truelight@0: tron@350: x = _cursor.pos.x + _drag_delta.x; tron@350: y = _cursor.pos.y + _drag_delta.y; tron@350: nx = x; tron@350: ny = y; tron@350: tron@350: if (_patches.window_snap_radius != 0) { tron@353: int hsnap = _patches.window_snap_radius; tron@353: int vsnap = _patches.window_snap_radius; tron@353: int delta; tron@350: tron@350: for (v = _windows; v != _last_window; ++v) { tron@350: if (v == w) continue; // Don't snap at yourself tron@350: tron@350: if (y + w->height > v->top && y < v->top + v->height) { tron@350: // Your left border <-> other right border tron@350: delta = abs(v->left + v->width - x); tron@350: if (delta <= hsnap) { tron@350: nx = v->left + v->width; tron@350: hsnap = delta; tron@350: } tron@350: tron@350: // Your right border <-> other left border tron@350: delta = abs(v->left - x - w->width); tron@350: if (delta <= hsnap) { tron@350: nx = v->left - w->width; tron@350: hsnap = delta; tron@350: } tron@350: } tron@350: tron@353: if (w->top + w->height >= v->top && w->top <= v->top + v->height) { tron@353: // Your left border <-> other left border tron@353: delta = abs(v->left - x); tron@353: if (delta <= hsnap) { tron@353: nx = v->left; tron@353: hsnap = delta; tron@353: } tron@353: tron@353: // Your right border <-> other right border tron@353: delta = abs(v->left + v->width - x - w->width); tron@353: if (delta <= hsnap) { tron@353: nx = v->left + v->width - w->width; tron@353: hsnap = delta; tron@353: } tron@353: } tron@353: tron@350: if (x + w->width > v->left && x < v->left + v->width) { tron@350: // Your top border <-> other bottom border tron@350: delta = abs(v->top + v->height - y); tron@350: if (delta <= vsnap) { tron@350: ny = v->top + v->height; tron@350: vsnap = delta; tron@350: } tron@350: tron@350: // Your bottom border <-> other top border tron@350: delta = abs(v->top - y - w->height); tron@350: if (delta <= vsnap) { tron@350: ny = v->top - w->height; tron@350: vsnap = delta; tron@350: } tron@350: } tron@353: tron@353: if (w->left + w->width >= v->left && w->left <= v->left + v->width) { tron@353: // Your top border <-> other top border tron@353: delta = abs(v->top - y); tron@353: if (delta <= vsnap) { tron@353: ny = v->top; tron@353: vsnap = delta; tron@353: } tron@353: tron@353: // Your bottom border <-> other bottom border tron@353: delta = abs(v->top + v->height - y - w->height); tron@353: if (delta <= vsnap) { tron@353: ny = v->top + v->height - w->height; tron@353: vsnap = delta; tron@353: } tron@353: } truelight@0: } truelight@0: } truelight@158: tron@350: // Make sure the window doesn't leave the screen tron@350: // 13 is the height of the title bar tron@350: nx = clamp(nx, 13 - w->width, _screen.width - 13); tron@350: ny = clamp(ny, 0, _screen.height - 13); tron@350: tron@350: if (w->viewport != NULL) { tron@350: w->viewport->left += nx - w->left; tron@350: w->viewport->top += ny - w->top; tron@350: } tron@350: w->left = nx; tron@350: w->top = ny; tron@350: truelight@0: SetWindowDirty(w); truelight@0: return false; truelight@0: } truelight@0: } truelight@0: truelight@0: _dragging_window = false; truelight@0: return false; truelight@0: } truelight@0: truelight@0: Window *StartWindowDrag(Window *w) truelight@0: { truelight@0: w->flags4 |= WF_DRAGGING; truelight@0: _dragging_window = true; tron@350: _drag_delta.x = w->left - _cursor.pos.x; tron@350: _drag_delta.y = w->top - _cursor.pos.y; truelight@0: w = BringWindowToFront(w); truelight@0: DeleteWindowById(WC_DROPDOWN_MENU, 0); truelight@0: return w; truelight@0: } truelight@0: truelight@0: Window *StartWindowSizing(Window *w) truelight@0: { truelight@0: w->flags4 |= WF_SIZING; truelight@0: _dragging_window = true; truelight@0: _cursorpos_drag_start = _cursor.pos; truelight@0: w = BringWindowToFront(w); truelight@0: DeleteWindowById(WC_DROPDOWN_MENU, 0); truelight@0: return w; truelight@0: } truelight@0: truelight@0: truelight@0: bool HandleScrollbarScrolling() truelight@0: { truelight@0: Window *w; truelight@0: int i; truelight@0: int pos; truelight@0: Scrollbar *sb; truelight@0: truelight@0: // Get out quickly if no item is being scrolled truelight@0: if (!_scrolling_scrollbar) truelight@0: return true; truelight@0: truelight@0: // Find the scrolling window truelight@0: for(w=_windows; w != _last_window; w++) { truelight@0: if (w->flags4 & WF_SCROLL_MIDDLE) { truelight@0: // Abort if no button is clicked any more. truelight@0: if (!_left_button_down) { truelight@0: w->flags4 &= ~WF_SCROLL_MIDDLE; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@158: } truelight@0: truelight@0: if (w->flags4 & WF_HSCROLL) { truelight@0: sb = &w->hscroll; truelight@0: i = _cursor.pos.x - _cursorpos_drag_start.x; truelight@0: } else { truelight@0: sb = &w->vscroll; truelight@0: i = _cursor.pos.y - _cursorpos_drag_start.y; truelight@0: } truelight@0: truelight@0: // Find the item we want to move to and make sure it's inside bounds. truelight@0: pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); truelight@0: if (pos != sb->pos) { truelight@0: sb->pos = pos; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: return false; truelight@158: } truelight@0: } truelight@158: truelight@0: _scrolling_scrollbar = false; truelight@0: return false; truelight@0: } truelight@0: truelight@158: bool HandleViewportScroll() truelight@0: { truelight@0: Window *w; truelight@0: ViewPort *vp; truelight@0: int dx,dy, x, y, sub; truelight@0: truelight@0: if (!_scrolling_viewport) truelight@0: return true; truelight@0: truelight@0: if (!_right_button_down) { truelight@0: stop_capt:; truelight@0: _cursor.fix_at = false; truelight@0: _scrolling_viewport = false; truelight@0: return true; truelight@0: } truelight@158: truelight@0: w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); truelight@0: if (w == NULL) goto stop_capt; truelight@0: truelight@0: if (w->window_class != WC_SMALLMAP) { truelight@0: vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); truelight@0: if (vp == NULL) truelight@0: goto stop_capt; truelight@0: truelight@0: WP(w,vp_d).scrollpos_x += _cursor.delta.x << vp->zoom; truelight@0: WP(w,vp_d).scrollpos_y += _cursor.delta.y << vp->zoom; truelight@0: _cursor.delta.x = _cursor.delta.y = 0; truelight@0: return false; truelight@0: } else { truelight@0: // scroll the smallmap ? truelight@158: truelight@0: _cursor.fix_at = true; truelight@158: truelight@0: dx = _cursor.delta.x; truelight@0: dy = _cursor.delta.y; truelight@0: truelight@0: x = WP(w,smallmap_d).scroll_x; truelight@0: y = WP(w,smallmap_d).scroll_y; truelight@0: truelight@0: sub = WP(w,smallmap_d).subscroll + dx; truelight@0: truelight@0: x -= (sub >> 2) << 4; truelight@0: y += (sub >> 2) << 4; truelight@0: sub &= 3; truelight@0: truelight@0: x += (dy >> 1) << 4; truelight@0: y += (dy >> 1) << 4; truelight@0: truelight@0: if (dy & 1) { truelight@0: x += 16; truelight@0: sub += 2; truelight@0: if (sub > 3) { truelight@0: sub -= 4; truelight@0: x -= 16; truelight@0: y += 16; truelight@0: } truelight@0: } truelight@0: truelight@0: if (x < 16) { x = 16; sub = 0; } truelight@0: if (x > (TILES_X-2)*16) { x = (TILES_X-2)*16; sub = 0; } truelight@0: if (y < -1120) { y = -1120; sub = 0; } truelight@0: if (y > (TILE_X_MAX-40) * 16) { y = (TILE_X_MAX-40) * 16; sub = 0; } truelight@0: truelight@0: WP(w,smallmap_d).scroll_x = x; truelight@0: WP(w,smallmap_d).scroll_y = y; truelight@0: WP(w,smallmap_d).subscroll = sub; truelight@0: truelight@0: _cursor.delta.x = _cursor.delta.y = 0; truelight@0: truelight@0: SetWindowDirty(w); truelight@0: return false; truelight@0: } truelight@0: } truelight@0: truelight@0: static Window *MaybeBringWindowToFront(Window *w) truelight@0: { truelight@0: Window *u; truelight@0: truelight@0: if (w->window_class == WC_MAIN_WINDOW || truelight@0: w->window_class == WC_MAIN_TOOLBAR || truelight@0: w->window_class == WC_STATUS_BAR || truelight@0: w->window_class == WC_NEWS_WINDOW || truelight@0: w->window_class == WC_TOOLTIPS || truelight@0: w->window_class == WC_DROPDOWN_MENU) truelight@0: return w; truelight@0: truelight@0: for(u=w; ++u != _last_window;) { truelight@0: if (u->window_class == WC_MAIN_WINDOW || u->window_class==WC_MAIN_TOOLBAR || u->window_class==WC_STATUS_BAR || truelight@0: u->window_class == WC_NEWS_WINDOW || u->window_class == WC_TOOLTIPS || u->window_class == WC_DROPDOWN_MENU) truelight@0: continue; truelight@0: truelight@0: if (w->left + w->width <= u->left || truelight@0: u->left + u->width <= w->left || truelight@0: w->top + w->height <= u->top || truelight@0: u->top + u->height <= w->top) truelight@0: continue; truelight@158: truelight@158: return BringWindowToFront(w); truelight@0: } truelight@0: truelight@0: return w; truelight@0: } truelight@0: truelight@0: static void HandleKeypress(uint32 key) truelight@0: { truelight@0: Window *w; truelight@0: WindowEvent we; truelight@158: truelight@0: // Setup event truelight@0: we.keypress.event = WE_KEYPRESS; truelight@0: we.keypress.ascii = key & 0xFF; truelight@0: we.keypress.keycode = key >> 16; truelight@0: we.keypress.cont = true; truelight@0: truelight@0: // Call the event, start with the uppermost window. truelight@0: for(w=_last_window; w != _windows;) { truelight@0: --w; truelight@0: w->wndproc(w, &we); truelight@0: if (!we.keypress.cont) truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: extern void UpdateTileSelection(); truelight@0: extern bool VpHandlePlaceSizingDrag(); truelight@0: truelight@0: void MouseLoop() truelight@0: { truelight@0: int x,y; truelight@0: Window *w; truelight@0: ViewPort *vp; truelight@0: int click; truelight@0: int mousewheel; truelight@0: truelight@0: _current_player = _local_player; truelight@0: truelight@0: // Handle pressed keys truelight@0: if (_pressed_key) { truelight@0: uint32 key = _pressed_key; _pressed_key = 0; truelight@0: HandleKeypress(key); truelight@0: } truelight@0: truelight@0: // Mouse event? truelight@0: click = 0; truelight@0: if (_left_button_down && !_left_button_clicked) { truelight@0: _left_button_clicked = true; truelight@0: click = 1; truelight@0: } else if (_right_button_clicked) { truelight@0: _right_button_clicked = false; truelight@0: click = 2; truelight@0: } truelight@0: truelight@0: mousewheel = 0; truelight@0: if (_cursor.wheel) { truelight@0: mousewheel = _cursor.wheel; truelight@0: _cursor.wheel = 0; truelight@0: } truelight@158: truelight@0: DecreaseWindowCounters(); truelight@0: HandlePlacePresize(); truelight@0: UpdateTileSelection(); truelight@0: if (!VpHandlePlaceSizingDrag()) truelight@0: return; truelight@0: truelight@0: if (!HandleDragDrop()) truelight@0: return; truelight@0: truelight@0: if (!HandlePopupMenu()) truelight@0: return; truelight@0: truelight@0: if (!HandleWindowDragging()) truelight@0: return; truelight@0: truelight@0: if (!HandleScrollbarScrolling()) truelight@0: return; truelight@0: truelight@0: if (!HandleViewportScroll()) truelight@0: return; truelight@158: truelight@0: x = _cursor.pos.x; truelight@0: y = _cursor.pos.y; truelight@0: truelight@0: truelight@0: if (click == 0 && mousewheel == 0) { truelight@0: if (_patches.autoscroll && _game_mode != GM_MENU) { truelight@0: w = FindWindowFromPt(x, y); truelight@0: if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL ) return; truelight@0: vp = IsPtInWindowViewport(w, x, y); truelight@0: if (vp) { truelight@0: x -= vp->left; truelight@0: y -= vp->top; truelight@0: //here allows scrolling in both x and y axis truelight@0: #define scrollspeed 3 truelight@0: if (x-15<0) { WP(w,vp_d).scrollpos_x += (x-15) * scrollspeed << vp->zoom; } truelight@0: else if (15-(vp->width-x) > 0) { WP(w,vp_d).scrollpos_x += (15-(vp->width-x))*scrollspeed << vp->zoom; } truelight@0: if (y-15<0) { WP(w,vp_d).scrollpos_y += (y-15)*scrollspeed << vp->zoom; } truelight@0: else if (15-(vp->height-y) > 0) { WP(w,vp_d).scrollpos_y += (15-(vp->height-y))*scrollspeed << vp->zoom; } truelight@158: #undef scrollspeed truelight@0: } truelight@0: } truelight@0: return; truelight@0: } truelight@0: truelight@0: w = FindWindowFromPt(x, y); truelight@0: if (w == NULL) truelight@0: return; truelight@0: w = MaybeBringWindowToFront(w); truelight@0: vp = IsPtInWindowViewport(w, x, y); truelight@0: if (vp != NULL) { truelight@0: if (_game_mode == GM_MENU) truelight@0: return; truelight@0: darkvater@178: // only allow zooming in-out in main window, or in viewports truelight@193: if ( mousewheel && !(w->flags4 & WF_DISABLE_VP_SCROLL) && darkvater@178: (w->window_class == WC_MAIN_WINDOW || w->window_class == WC_EXTRA_VIEW_PORT) ) { darkvater@152: ZoomInOrOutToCursorWindow(mousewheel < 0,w); truelight@0: } truelight@0: truelight@0: if (click == 1) { darkvater@70: DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); truelight@0: if (_thd.place_mode != 0 && darkvater@67: // query button and place sign button work in pause mode darkvater@67: !(_cursor.sprite == 0x2CF || _cursor.sprite == 0x2D2) && truelight@0: _pause != 0 && darkvater@67: !_cheats.build_in_pause.value) truelight@0: return; truelight@158: truelight@0: if (_thd.place_mode == 0) { truelight@0: HandleViewportClicked(vp, x, y); truelight@0: } else { truelight@0: PlaceObject(); truelight@0: } truelight@0: } else if (click == 2) { truelight@0: if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { truelight@0: _scrolling_viewport = true; truelight@0: _cursor.fix_at = true; truelight@0: } truelight@0: } truelight@0: } else { truelight@0: if (mousewheel) truelight@0: DispatchMouseWheelEvent(w, mousewheel); truelight@0: truelight@0: if (click == 1) truelight@0: DispatchLeftClickEvent(w, x - w->left, y - w->top); truelight@0: else if (click == 2) truelight@0: DispatchRightClickEvent(w, x - w->left, y - w->top); truelight@0: } truelight@0: } truelight@0: truelight@0: static int _we4_timer; truelight@0: truelight@0: extern uint32 _pixels_redrawn; truelight@0: truelight@0: void UpdateWindows() truelight@0: { truelight@0: Window *w; truelight@0: int t; truelight@0: truelight@0: truelight@0: if ((t=_we4_timer+1) >= 100) { truelight@0: for(w = _last_window; w != _windows;) { truelight@0: w--; truelight@0: CallWindowEventNP(w, WE_4); truelight@0: } truelight@0: t = 0; truelight@0: } truelight@0: _we4_timer = t; truelight@0: truelight@0: for(w = _last_window; w != _windows;) { truelight@0: w--; truelight@0: if (w->flags4 & WF_WHITE_BORDER_MASK) { truelight@0: w->flags4 -= WF_WHITE_BORDER_ONE; truelight@0: if (!(w->flags4 & WF_WHITE_BORDER_MASK)) { truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: DrawDirtyBlocks(); truelight@0: truelight@0: for(w = _windows; w!=_last_window; w++) { truelight@0: if (w->viewport != NULL) truelight@0: UpdateViewportPosition(w); truelight@0: } truelight@0: // Redraw mouse cursor in case it was hidden truelight@0: DrawMouseCursor(); truelight@158: } truelight@0: truelight@0: truelight@0: int GetMenuItemIndex(Window *w, int x, int y) truelight@0: { truelight@0: if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { truelight@0: y /= 10; truelight@0: truelight@0: if (y < WP(w,menu_d).item_count) truelight@0: return y; truelight@0: } truelight@0: return -1; truelight@0: } truelight@0: truelight@0: void InvalidateWindow(byte cls, WindowNumber number) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class==cls && w->window_number==number) truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: truelight@0: void InvalidateWidget(Window *w, byte widget_index) truelight@0: { truelight@0: const Widget *wi = &w->widget[widget_index]; truelight@0: // if (wi->left != -2) { truelight@0: SetDirtyBlocks( truelight@158: w->left + wi->left, truelight@0: w->top + wi->top, truelight@0: w->left + wi->right + 1, truelight@0: w->top + wi->bottom + 1); truelight@158: // } truelight@0: } truelight@0: truelight@0: void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class==cls && w->window_number==number) { truelight@0: InvalidateWidget(w, widget_index); truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: void InvalidateWindowClasses(byte cls) truelight@0: { truelight@0: Window *w; truelight@0: for(w=_windows; w!=_last_window; w++) { truelight@0: if (w->window_class==cls) truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: void CallWindowTickEvent() truelight@0: { truelight@0: Window *w; truelight@0: for(w=_last_window; w != _windows;) { truelight@0: --w; truelight@0: CallWindowEventNP(w, WE_TICK); truelight@0: } truelight@0: } truelight@0: truelight@0: void DeleteNonVitalWindows() truelight@0: { truelight@0: Window *w; truelight@0: for(w=_windows; w!=_last_window;) { truelight@0: if (w->window_class != WC_MAIN_WINDOW && truelight@0: w->window_class != WC_SELECT_GAME && truelight@0: w->window_class != WC_MAIN_TOOLBAR && truelight@0: w->window_class != WC_STATUS_BAR && truelight@0: w->window_class != WC_TOOLBAR_MENU && truelight@0: w->window_class != WC_TOOLTIPS) { truelight@0: DeleteWindow(w); truelight@0: w = _windows; truelight@0: } else { truelight@0: w++; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@158: int PositionMainToolbar(Window *w) darkvater@68: { darkvater@69: DEBUG(misc, 1) ("Repositioning Main Toolbar..."); darkvater@68: darkvater@68: if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) darkvater@68: w = FindWindowById(WC_MAIN_TOOLBAR, 0); darkvater@68: darkvater@68: switch (_patches.toolbar_pos) { darkvater@68: case 1: w->left = (_screen.width - w->width) >> 1; break; darkvater@68: case 2: w->left = _screen.width - w->width; break; darkvater@68: default: w->left = 0; darkvater@68: } darkvater@68: SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part darkvater@68: return w->left; darkvater@68: } darkvater@68: truelight@0: void RelocateAllWindows(int neww, int newh) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: for(w=_windows; w!= _last_window ;w++) { truelight@0: int left, top; truelight@158: truelight@0: if (w->window_class == WC_MAIN_WINDOW) { truelight@0: ViewPort *vp = w->viewport; truelight@0: vp->width = w->width = neww; truelight@0: vp->height = w->height = newh; truelight@0: vp->virtual_width = neww << vp->zoom; truelight@0: vp->virtual_height = newh << vp->zoom; truelight@0: continue; // don't modify top,left darkvater@152: } darkvater@152: dominik@126: IConsoleResize(); truelight@0: truelight@0: if (w->window_class == WC_MAIN_TOOLBAR) { truelight@0: top = w->top; darkvater@68: left = PositionMainToolbar(w); // changes toolbar orientation truelight@158: } else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){ truelight@0: top = (newh - w->height) >> 1; truelight@0: left = (neww - w->width) >> 1; truelight@0: } else if (w->window_class == WC_NEWS_WINDOW) { truelight@0: top = newh - w->height; truelight@0: left = (neww - w->width) >> 1; truelight@0: } else if (w->window_class == WC_STATUS_BAR) { truelight@0: top = newh - w->height; truelight@158: left = (neww - w->width) >> 1; truelight@0: } else { truelight@0: left = w->left; truelight@0: if (left + (w->width>>1) >= neww) left = neww - w->width; truelight@0: top = w->top; truelight@0: if (top + (w->height>>1) >= newh) top = newh - w->height; truelight@0: } truelight@0: truelight@0: if (w->viewport) { truelight@0: w->viewport->left += left - w->left; truelight@0: w->viewport->top += top - w->top; truelight@0: } truelight@0: truelight@0: w->left = left; truelight@0: w->top = top; truelight@0: } truelight@0: }