(svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
--- a/src/build_vehicle_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/build_vehicle_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -1010,8 +1010,8 @@
SetupWindowStrings(w, type);
w->ResizeButtons(BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
- w->resize.width = w->width;
- w->resize.height = w->height;
+ w->resize.width = w->Width();
+ w->resize.height = w->Height();
GenerateBuildList(w); // generate the list, since we need it in the next line
/* Select the first engine in the list as default when opening the window */
--- a/src/console.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/console.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -68,25 +68,25 @@
switch (e->event) {
case WE_PAINT: {
int i = iconsole_scroll;
- int max = (w->height / ICON_LINE_HEIGHT) - 1;
+ int max = (w->Height() / ICON_LINE_HEIGHT) - 1;
int delta = 0;
- GfxFillRect(w->left, w->top, w->width, w->height - 1, 0);
+ GfxFillRect(w->Left(), w->Top(), w->Width(), w->Height() - 1, 0);
while ((i > 0) && (i > iconsole_scroll - max) && (_iconsole_buffer[i] != NULL)) {
DoDrawString(_iconsole_buffer[i], 5,
- w->height - (iconsole_scroll + 2 - i) * ICON_LINE_HEIGHT, _iconsole_cbuffer[i]);
+ w->Top() - (iconsole_scroll + 2 - i) * ICON_LINE_HEIGHT, _iconsole_cbuffer[i]);
i--;
}
/* If the text is longer than the window, don't show the starting ']' */
- delta = w->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
+ delta = w->Width() - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
if (delta > 0) {
- DoDrawString("]", 5, w->height - ICON_LINE_HEIGHT, _icolour_cmd);
+ DoDrawString("]", 5, w->Height() - ICON_LINE_HEIGHT, _icolour_cmd);
delta = 0;
}
- DoDrawString(_iconsole_cmdline.buf, 10 + delta, w->height - ICON_LINE_HEIGHT, _icolour_cmd);
+ DoDrawString(_iconsole_cmdline.buf, 10 + delta, w->Height() - ICON_LINE_HEIGHT, _icolour_cmd);
if (_iconsole_cmdline.caret)
- DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, w->height - ICON_LINE_HEIGHT, 12);
+ DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, w->Height() - ICON_LINE_HEIGHT, 12);
break;
}
case WE_MOUSELOOP:
@@ -108,18 +108,18 @@
w->SetDirty();
break;
case WKC_SHIFT | WKC_PAGEUP:
- if (iconsole_scroll - (w->height / ICON_LINE_HEIGHT) - 1 < 0) {
+ if (iconsole_scroll - (w->Height() / ICON_LINE_HEIGHT) - 1 < 0) {
iconsole_scroll = 0;
} else {
- iconsole_scroll -= (w->height / ICON_LINE_HEIGHT) - 1;
+ iconsole_scroll -= (w->Height() / ICON_LINE_HEIGHT) - 1;
}
w->SetDirty();
break;
case WKC_SHIFT | WKC_PAGEDOWN:
- if (iconsole_scroll + (w->height / ICON_LINE_HEIGHT) - 1 > ICON_BUFFER) {
+ if (iconsole_scroll + (w->Height() / ICON_LINE_HEIGHT) - 1 > ICON_BUFFER) {
iconsole_scroll = ICON_BUFFER;
} else {
- iconsole_scroll += (w->height / ICON_LINE_HEIGHT) - 1;
+ iconsole_scroll += (w->Height() / ICON_LINE_HEIGHT) - 1;
}
w->SetDirty();
break;
@@ -282,12 +282,10 @@
{
switch (_iconsole_mode) {
case ICONSOLE_OPENED:
- w->height = _screen.height / 3;
- w->width = _screen.width;
+ w->SetSize(Point(_screen.width, _screen.height / 3));
break;
case ICONSOLE_FULL:
- w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
- w->width = _screen.width;
+ w->SetSize(Point(_screen.width, _screen.height - ICON_BOTTOM_BORDERWIDTH));
break;
default: return;
}
@@ -300,8 +298,7 @@
switch (_iconsole_mode) {
case ICONSOLE_CLOSED: {
BaseWindow *w = BaseWindow::Allocate(&_iconsole_window_desc);
- w->height = _screen.height / 3;
- w->width = _screen.width;
+ w->SetSize(Point(_screen.width, _screen.height / 3));
_iconsole_mode = ICONSOLE_OPENED;
SETBIT(_no_scroll, SCROLL_CON); // override cursor arrows; the gamefield will not scroll
} break;
--- a/src/depot_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/depot_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -723,8 +723,8 @@
}
/* Set the minimum window size to the current window size */
- w->resize.width = w->width;
- w->resize.height = w->height;
+ w->resize.width = w->Width();
+ w->resize.height = w->Height();
SetupStringsForDepotWindow(w, type);
--- a/src/economy.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/economy.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -478,55 +478,55 @@
switch (WP(w,news_d).ni->string_id & 0xF0) {
case NB_BTROUBLE:
- DrawStringCentered(w->width>>1, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0);
+ DrawStringCentered(w->Width() / 2, 1, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE, 0);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
+ ((w->Width() - 101) >> 1) + 98,
90,
STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED,
- w->width - 101);
+ w->Width() - 101);
break;
case NB_BMERGER: {
int32 price;
- DrawStringCentered(w->width>>1, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0);
+ DrawStringCentered(w->Width() / 2, 1, STR_7059_TRANSPORT_COMPANY_MERGER, 0);
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2);
SetDParam(2, p->name_1);
SetDParam(3, p->name_2);
price = WP(w,news_d).ni->params[2];
SetDParam(4, price);
DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
+ ((w->Width() - 101) >> 1) + 98,
90,
price==0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR,
- w->width - 101);
+ w->Width() - 101);
break;
}
case NB_BBANKRUPT:
- DrawStringCentered(w->width>>1, 1, STR_705C_BANKRUPT, 0);
+ DrawStringCentered(w->Width() / 2, 1, STR_705C_BANKRUPT, 0);
COPY_IN_DPARAM(0,WP(w,news_d).ni->params, 2);
DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
+ ((w->Width() - 101) >> 1) + 98,
90,
STR_705D_HAS_BEEN_CLOSED_DOWN_BY,
- w->width - 101);
+ w->Width() - 101);
break;
case NB_BNEWCOMPANY:
- DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0);
+ DrawStringCentered(w->Width() / 2, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
COPY_IN_DPARAM(2,WP(w,news_d).ni->params, 2);
DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
+ ((w->Width() - 101) >> 1) + 98,
90,
STR_705F_STARTS_CONSTRUCTION_NEAR,
- w->width - 101);
+ w->Width() - 101);
break;
default:
--- a/src/engine_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/engine_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -79,14 +79,14 @@
SetDParam(0, GetEngineCategoryName(engine));
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
- DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10);
+ DrawStringCentered(w->Width() >> 1, 80, GetCustomEngineName(engine), 0x10);
(dei = _draw_engine_list,engine < NUM_TRAIN_ENGINES) ||
(dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) ||
(dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) ||
(dei++, true);
- width = w->width;
+ width = w->Width();
dei->engine_proc(width >> 1, 100, engine, 0);
dei->info_proc(engine, width >> 1, 130, width - 52);
break;
@@ -142,22 +142,23 @@
void DrawNewsNewTrainAvail(BaseWindow *w)
{
+ int width = w->Width();
EngineID engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
SetDParam(0, GetEngineCategoryName(engine));
- DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2);
+ DrawStringMultiCenter(width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, width - 2);
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
+ GfxFillRect(25, 56, width - 25, w->Height() - 2, 10);
SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2);
+ DrawStringMultiCenter(width >> 1, 57, STR_885A, width - 2);
- DrawTrainEngine(w->width >> 1, 88, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52);
+ DrawTrainEngine(width >> 1, 88, engine, 0);
+ GfxFillRect(25, 56, width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+ DrawTrainEngineInfo(engine, width >> 1, 129, width - 52);
}
StringID GetNewsStringNewTrainAvail(const NewsItem *ni)
@@ -183,21 +184,22 @@
void DrawNewsNewAircraftAvail(BaseWindow *w)
{
+ int width = w->Width();
EngineID engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
- DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2);
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
+ DrawStringMultiCenter(width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, width - 2);
+ GfxFillRect(25, 56, width - 25, w->Height() - 2, 10);
SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2);
+ DrawStringMultiCenter(width >> 1, 57, STR_A02D, width - 2);
- DrawAircraftEngine(w->width >> 1, 93, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 110, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52);
+ DrawAircraftEngine(width >> 1, 93, engine, 0);
+ GfxFillRect(25, 56, width - 56, 110, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+ DrawAircraftEngineInfo(engine, width >> 1, 131, width - 52);
}
StringID GetNewsStringNewAircraftAvail(const NewsItem *ni)
@@ -223,20 +225,21 @@
void DrawNewsNewRoadVehAvail(BaseWindow *w)
{
+ int width = w->Width();
EngineID engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
- DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2);
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
+ DrawStringMultiCenter(width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, width - 2);
+ GfxFillRect(25, 56, width - 25, w->Height() - 2, 10);
SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2);
+ DrawStringMultiCenter(width >> 1, 57, STR_9029, width - 2);
- DrawRoadVehEngine(w->width >> 1, 88, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52);
+ DrawRoadVehEngine(width >> 1, 88, engine, 0);
+ GfxFillRect(25, 56, width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+ DrawRoadVehEngineInfo(engine, width >> 1, 129, width - 52);
}
StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni)
@@ -260,21 +263,22 @@
void DrawNewsNewShipAvail(BaseWindow *w)
{
+ int width = w->Width();
EngineID engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
- DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2);
- GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
+ DrawStringMultiCenter(width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, width - 2);
+ GfxFillRect(25, 56, width - 25, w->Height() - 2, 10);
SetDParam(0, GetCustomEngineName(engine));
- DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2);
+ DrawStringMultiCenter(width >> 1, 57, STR_982D, width - 2);
- DrawShipEngine(w->width >> 1, 93, engine, 0);
- GfxFillRect(25, 56, w->width - 56, 110, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
- DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52);
+ DrawShipEngine(width >> 1, 93, engine, 0);
+ GfxFillRect(25, 56, width - 56, 110, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE));
+ DrawShipEngineInfo(engine, width >> 1, 131, width - 52);
}
StringID GetNewsStringNewShipAvail(const NewsItem *ni)
--- a/src/genworld_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/genworld_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -778,8 +778,8 @@
w->DrawWidgets();
/* Draw the % complete with a bar and a text */
- DrawFrameRect(19, 20, (w->width - 18), 37, 14, FR_BORDERONLY);
- DrawFrameRect(20, 21, (int)((w->width - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE);
+ DrawFrameRect(19, 20, (w->Width() - 18), 37, 14, FR_BORDERONLY);
+ DrawFrameRect(20, 21, (int)((w->Width() - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE);
SetDParam(0, _tp.percent);
DrawStringCentered(90, 25, STR_PROGRESS, 0);
--- a/src/industry_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/industry_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -36,7 +36,7 @@
int ind_type = _build_industry_types[_opt_ptr->landscape][WP(w,def_d).data_1];
SetDParam(0, (_price.build_industry >> 5) * GetIndustrySpec(ind_type)->cost_multiplier);
- DrawStringCentered(85, w->height - 21, STR_482F_COST, 0);
+ DrawStringCentered(85, w->Height() - 21, STR_482F_COST, 0);
}
break;
@@ -687,7 +687,7 @@
if (w != NULL) {
w->vscroll.cap = 16;
- w->resize.height = w->height - 6 * 10; // minimum 10 items
+ w->resize.height = w->Height() - 6 * 10; // minimum 10 items
w->resize.step_height = 10;
w->SetDirty();
}
--- a/src/main_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/main_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -426,7 +426,7 @@
static void MenuWndProc(BaseWindow *w, WindowEvent *e)
{
switch (e->event) {
- case WE_CREATE: w->widget[0].right = w->width - 1; break;
+ case WE_CREATE: w->widget[0].right = w->Width() - 1; break;
case WE_PAINT: {
int x, y;
@@ -444,7 +444,7 @@
for (; count != 0; count--, string++, sel--) {
byte color = HASBIT(dis, 0) ? 14 : (sel == 0) ? 12 : 16;
- if (sel == 0) GfxFillRect(x, y, x + w->width - 3, y + 9, 0);
+ if (sel == 0) GfxFillRect(x, y, x + w->Width() - 3, y + 9, 0);
if (HASBIT(chk, 0)) DrawString(x + 2, y, STR_CHECKMARK, color);
DrawString(x + 2, y, string, color);
@@ -469,7 +469,7 @@
if (index < 0) {
BaseWindow *w2 = BaseWindow::FindById(WC_MAIN_TOOLBAR,0);
- if (w2->GetWidgetFromPos(e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button)
+ if (w2->GetWidgetFromPos(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;
}
@@ -533,7 +533,7 @@
WP(w,menu_d).item_count = num;
w->SetDirty();
num = num * 10 + 2;
- w->height = num;
+ w->SetHeight(num);
w->widget[0].bottom = w->widget[0].top + num - 1;
w->SetDirty();
}
@@ -611,7 +611,7 @@
if (index < 0) {
BaseWindow *w2 = BaseWindow::FindById(WC_MAIN_TOOLBAR,0);
- if (w2->GetWidgetFromPos(e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button)
+ if (w2->GetWidgetFromPos(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;
}
@@ -705,7 +705,7 @@
* we clicked on and w->left the toolbar window itself. So meaning that
* the default position is aligned with the left side of the clicked button */
width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140);
- x = w->left + clamp(x, 0, w->width - width); // or alternatively '_screen.width - width'
+ x = w->Left() + clamp(x, 0, w->Width() - width); // or alternatively '_screen.width - width'
w = BaseWindow::Allocate(x, 22, width, item_count * 10 + 2, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
w->widget[0].bottom = item_count * 10 + 1;
@@ -727,7 +727,7 @@
static BaseWindow *PopupMainPlayerToolbMenu(BaseWindow *w, int x, int main_button, int gray)
{
- x += w->left;
+ x += w->Left();
w->LowerWidget(main_button);
w->InvalidateWidget(main_button);
@@ -1805,8 +1805,8 @@
switch (e->event) {
case WE_PAINT:
// Draw brown-red toolbar bg.
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
+ GfxFillRect(0, 0, w->Width() - 1, w->Height() - 1, 0xB2);
+ GfxFillRect(0, 0, w->Width() - 1, w->Height() - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
/* If spectator, disable all construction buttons
* ie : Build road, rail, ships, airports and landscaping
@@ -2018,8 +2018,8 @@
w->SetWidgetDisabledState(7, _patches_newgame.starting_year >= MAX_YEAR);
// Draw brown-red toolbar bg.
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
- GfxFillRect(0, 0, w->width-1, w->height-1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
+ GfxFillRect(0, 0, w->Width() - 1, w->Height() - 1, 0xB2);
+ GfxFillRect(0, 0, w->Width() - 1, w->Height() - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT));
w->DrawWidgets();
--- a/src/misc/rect.hpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/misc/rect.hpp Tue Feb 27 13:26:47 2007 +0000
@@ -36,6 +36,11 @@
return *this;
}
+ bool operator ==(const PointRaw &other) const
+ {
+ return PointRaw::x == other.x && PointRaw::y == other.y;
+ }
+
PointT operator -() const
{
return PointT(-PointRaw::x, -PointRaw::y);
@@ -77,6 +82,16 @@
DoMove(-offset);
return *this;
}
+
+ PointT operator *(T coef) const
+ {
+ return PointT(PointRaw::x * coef, PointRaw::y * coef);
+ }
+
+ PointT operator /(T coef) const
+ {
+ return PointT(PointRaw::x / coef, PointRaw::y / coef);
+ }
};
@@ -136,6 +151,16 @@
return bottom_right;
}
+ PointT<T> Size() const
+ {
+ return (bottom_right - top_left + PointT<T>(1, 1));
+ }
+
+ PointT<T> CenterPt() const
+ {
+ return (top_left + bottom_right) / 2;
+ }
+
void SetLeft(T val)
{
top_left.x = val;
@@ -176,6 +201,11 @@
bottom_right = pt;
}
+ void SetSize(const PointRaw &pt)
+ {
+ bottom_right = top_left + pt - PointT<T>(1, 1);
+ }
+
bool PtInRect(const PointRaw &pt) const
{
return (top_left.x <= pt.x && pt.x <= bottom_right.x && top_left.y <= pt.y && pt.y <= bottom_right.y);
--- a/src/misc_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/misc_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -249,7 +249,7 @@
switch (e->event) {
case WE_CREATE: /* Set up window counter and start position of scroller */
WP(w, scroller_d).counter = 0;
- WP(w, scroller_d).height = w->height - 40;
+ WP(w, scroller_d).height = w->Height() - 40;
break;
case WE_PAINT: {
uint i;
@@ -262,17 +262,17 @@
// Show all scrolling credits
for (i = 0; i < lengthof(credits); i++) {
- if (y >= 50 && y < (w->height - 40)) {
+ if (y >= 50 && y < (w->Height() - 40)) {
DoDrawString(credits[i], 10, y, 0x10);
}
y += 10;
}
// If the last text has scrolled start anew from the start
- if (y < 50) WP(w, scroller_d).height = w->height - 40;
+ if (y < 50) WP(w, scroller_d).height = w->Height() - 40;
- DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16);
- DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
+ DoDrawStringCentered(210, w->Height() - 25, "Website: http://www.openttd.org", 16);
+ DrawStringCentered(210, w->Height() - 15, STR_00BA_COPYRIGHT_OPENTTD, 0);
} break;
case WE_MOUSELOOP: /* Timer to scroll the text and adjust the new top */
if (WP(w, scroller_d).counter++ % 3 == 0) {
@@ -649,13 +649,13 @@
switch (e->event) {
case WE_PAINT: {
uint arg;
- GfxFillRect(0, 0, w->width - 1, w->height - 1, 0);
- GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44);
+ GfxFillRect(0, 0, w->Width() - 1, w->Height() - 1, 0);
+ GfxFillRect(1, 1, w->Width() - 2, w->Height() - 2, 0x44);
for (arg = 0; arg < WP(w, tooltips_d).paramcount; arg++) {
SetDParam(arg, WP(w, tooltips_d).params[arg]);
}
- DrawStringMultiCenter((w->width >> 1), (w->height >> 1) - 5, WP(w, tooltips_d).string_id, 197);
+ DrawStringMultiCenter((w->Width() >> 1), (w->Height() >> 1) - 5, WP(w, tooltips_d).string_id, 197);
break;
}
@@ -1208,7 +1208,7 @@
w->DrawWidgets();
COPY_IN_DPARAM(0, q->params, lengthof(q->params));
- DrawStringMultiCenter(w->width / 2, (w->height / 2) - 10, q->message, w->width);
+ DrawStringMultiCenter(w->Width() / 2, (w->Height() / 2) - 10, q->message, w->Width());
break;
case WE_CLICK:
@@ -1280,8 +1280,9 @@
if (parent == NULL) parent = BaseWindow::FindById(WC_MAIN_WINDOW, 0);
w->parent = parent;
- w->left = parent->left + (parent->width / 2) - (w->width / 2);
- w->top = parent->top + (parent->height / 2) - (w->height / 2);
+ /* Center window to the center of parent */
+ w->SetTopLeft(parent->TopLeft() + (parent->Size() - w->Size()) / 2);
+
/* Create a backup of the variadic arguments to strings because it will be
* overridden pretty often. We will copy these back for drawing */
@@ -1433,7 +1434,7 @@
SetVScrollCount(w, _fios_num);
w->DrawWidgets();
- DrawFiosTexts(w->width);
+ DrawFiosTexts(w->Width());
if (_savegame_sort_dirty) {
_savegame_sort_dirty = false;
@@ -1451,7 +1452,7 @@
for (pos = w->vscroll.pos; pos < _fios_num; pos++) {
const FiosItem *item = _fios_list + pos;
- DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18);
+ DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->Width() - 18);
y += 10;
if (y >= w->vscroll.cap * 10 + w->widget[7].top + 1) break;
}
@@ -1644,7 +1645,7 @@
w->vscroll.cap = 24;
w->resize.step_width = 2;
w->resize.step_height = 10;
- w->resize.height = w->height - 14 * 10; // Minimum of 10 items
+ w->resize.height = w->Height() - 14 * 10; // Minimum of 10 items
w->LowerWidget(7);
WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
--- a/src/network/network_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/network/network_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -1139,11 +1139,11 @@
num *= CLNWND_ROWSIZE;
// If height is changed
- if (w->height != CLNWND_OFFSET + num + 1) {
+ if (w->Height() != CLNWND_OFFSET + num + 1) {
// XXX - magic unfortunately; (num + 2) has to be one bigger than heigh (num + 1)
w->SetDirty();
w->widget[2].bottom = w->widget[2].top + num + 2;
- w->height = CLNWND_OFFSET + num + 1;
+ w->SetHeight(CLNWND_OFFSET + num + 1);
w->SetDirty();
return false;
}
@@ -1269,9 +1269,9 @@
case WE_POPUPMENU_SELECT: {
// We selected an action
- int index = (e->we.popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
+ int index = (e->we.popupmenu.pt.y - w->Top()) / CLNWND_ROWSIZE;
- if (index >= 0 && e->we.popupmenu.pt.y >= w->top)
+ if (index >= 0 && e->we.popupmenu.pt.y >= w->Top())
HandleClientListPopupClick(index, WP(w,menu_d).main_button);
DeleteWindowById(WC_TOOLBAR_MENU, 0);
@@ -1279,7 +1279,7 @@
case WE_POPUPMENU_OVER: {
// Our mouse hoovers over an action? Select it!
- int index = (e->we.popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
+ int index = (e->we.popupmenu.pt.y - w->Top()) / CLNWND_ROWSIZE;
if (index == -1 || index == WP(w,menu_d).sel_index) return;
@@ -1332,7 +1332,7 @@
case WE_CLICK:
// Show the popup with option
if (_selected_clientlist_item != 255) {
- PopupClientList(w, _selected_clientlist_item, e->we.click.pt.x + w->left, e->we.click.pt.y + w->top);
+ PopupClientList(w, _selected_clientlist_item, e->we.click.pt.x + w->Left(), e->we.click.pt.y + w->Top());
}
break;
@@ -1419,7 +1419,7 @@
}
/* Draw nice progress bar :) */
- DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE);
+ DrawFrameRect(20, 18, (int)((w->Width() - 20) * progress / 100), 28, 10, FR_NONE);
} break;
case WE_CLICK:
@@ -1620,7 +1620,7 @@
{
switch (e->event) {
case WE_CREATE:
- SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0);
+ SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->Height(), 0);
SETBIT(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
break;
--- a/src/newgrf_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/newgrf_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -120,8 +120,8 @@
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
/* Draw selection background */
- if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156);
- DoDrawStringTruncated(text, 4, y, h ? 0xC : 0x6, w->width - 18);
+ if (h) GfxFillRect(3, y, w->Width() - 15, y + 9, 156);
+ DoDrawStringTruncated(text, 4, y, h ? 0xC : 0x6, w->Width() - 18);
y += 10;
}
n++;
--- a/src/news_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/news_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -96,9 +96,9 @@
void DrawNewsBorder(const BaseWindow *w)
{
int left = 0;
- int right = w->width - 1;
+ int right = w->Width() - 1;
int top = 0;
- int bottom = w->height - 1;
+ int bottom = w->Height() - 1;
GfxFillRect(left, top, right, bottom, 0xF);
@@ -115,7 +115,7 @@
switch (e->event) {
case WE_CREATE: { /* If chatbar is open at creation time, we need to go above it */
const BaseWindow *w1 = BaseWindow::FindById(WC_SEND_NETWORK_MSG, 0);
- w->message.msg = (w1 != NULL) ? w1->height : 0;
+ w->message.msg = (w1 != NULL) ? w1->Height() : 0;
} break;
case WE_PAINT: {
@@ -144,13 +144,13 @@
/* Shade the viewport into gray, or color*/
vp = w->viewport;
- GfxFillRect(vp->left - w->left, vp->top - w->top,
- vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1,
+ GfxFillRect(vp->left - w->Left(), vp->top - w->Top(),
+ vp->left - w->Left() + vp->width - 1, vp->top - w->Top() + vp->height - 1,
(ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE)
);
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
- DrawStringMultiCenter(w->width / 2, 20, ni->string_id, 428);
+ DrawStringMultiCenter(w->Width() / 2, 20, ni->string_id, 428);
}
break;
}
@@ -168,7 +168,7 @@
} else {
w->DrawViewport();
COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
- DrawStringMultiCenter(w->width / 2, w->height - 16, ni->string_id, 276);
+ DrawStringMultiCenter(w->Width() / 2, w->Height() - 16, ni->string_id, 276);
}
break;
}
@@ -212,17 +212,16 @@
break;
case WE_TICK: { /* Scroll up newsmessages from the bottom in steps of 4 pixels */
- int diff;
- int y = max(w->top - 4, _screen.height - w->height - 12 - w->message.msg);
- if (y == w->top) return;
+ int y = max(w->Top() - 4, _screen.height - w->Height() - 12 - w->message.msg);
+ if (y == w->Top()) return;
if (w->viewport != NULL)
- w->viewport->top += y - w->top;
+ w->viewport->top += y - w->Top();
- diff = delta(w->top, y);
- w->top = y;
+ int16 diff = delta(w->Top(), (int16)y);
+ w->SetTop(y);
- SetDirtyBlocks(w->left, w->top - diff, w->left + w->width, w->top + w->height);
+ SetDirtyBlocks(w->Left(), w->Top() - diff, w->Left() + w->Width(), w->Top() + w->Height());
} break;
}
}
@@ -649,7 +648,7 @@
SetDParam(0, ni->date);
DrawString(4, y, STR_SHORT_DATE, 12);
- DrawNewsString(82, y, 12, ni, w->width - 95);
+ DrawNewsString(82, y, 12, ni, w->Width() - 95);
y += 12;
}
break;
@@ -704,7 +703,7 @@
w->vscroll.cap = 10;
w->vscroll.count = _total_news;
w->resize.step_height = 12;
- w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
+ w->resize.height = w->Height() - 12 * 6; // minimum of 4 items in the list, each item 12 high
w->resize.step_width = 1;
w->resize.width = 200; // can't make window any smaller than 200 pixel
w->SetDirty();
--- a/src/player_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/player_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -395,8 +395,8 @@
break;
}
}
- w->height = 49 + livery_height[WP(w, livery_d).livery_class] * 14;
- w->widget[13].bottom = w->height - 1;
+ w->SetHeight(49 + livery_height[WP(w, livery_d).livery_class] * 14);
+ w->widget[13].bottom = w->Height() - 1;
w->widget[13].data = livery_height[WP(w, livery_d).livery_class] << 8 | 1;
MarkWholeScreenDirty();
break;
@@ -949,10 +949,9 @@
{
uint i;
// resize window to "full-screen"
- w->width = _screen.width;
- w->height = _screen.height;
- w->widget[0].right = w->width - 1;
- w->widget[0].bottom = w->height - 1;
+ w->SetSize(Point(_screen.width, _screen.height));
+ w->widget[0].right = _screen.width - 1;
+ w->widget[0].bottom = _screen.height - 1;
w->DrawWidgets();
--- a/src/signs_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/signs_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -145,6 +145,6 @@
if (w != NULL) {
w->vscroll.cap = 12;
w->resize.step_height = 10;
- w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
+ w->resize.height = w->Height() - 10 * 7; // minimum if 5 in the list
}
}
--- a/src/smallmap_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/smallmap_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -813,7 +813,7 @@
/* draw the legend */
tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)];
x = 4;
- y_org = w->height - 44 - 11;
+ y_org = w->Height() - 44 - 11;
y = y_org;
for (;;) {
GfxFillRect(x, y + 1, x + 8, y + 5, 0);
@@ -831,7 +831,7 @@
}
}
- if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11))
+ if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->Width() - 28 + 22, w->Height() - 64 - 11))
return;
DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns);
@@ -854,8 +854,8 @@
_left_button_clicked = false;
pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0);
- WP(w2, vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1);
- WP(w2, vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1);
+ WP(w2, vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->Left() + 2) << 4) - (w2->viewport->virtual_width >> 1);
+ WP(w2, vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->Top() - 16) << 4) - (w2->viewport->virtual_height >> 1);
w->SetDirty();
} break;
--- a/src/station_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/station_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -561,7 +561,7 @@
w->caption_color = (byte)w->window_number;
w->vscroll.cap = 12;
w->resize.step_height = 10;
- w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
+ w->resize.height = w->Height() - 10 * 7; // minimum if 5 in the list
}
}
@@ -744,10 +744,10 @@
/* toggle height/widget set */
if (w->IsOfPrototype(_station_view_expanded_widgets)) {
w->AssignWidget(_station_view_widgets);
- w->height = 110;
+ w->SetHeight(110);
} else {
w->AssignWidget(_station_view_expanded_widgets);
- w->height = 210;
+ w->SetHeight(210);
}
w->SetDirty();
--- a/src/terraform_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/terraform_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -286,7 +286,7 @@
/* Align the terraform toolbar under the main toolbar and put the linked
* toolbar to left of it
*/
- w->top = 22;
- link->left = w->left - link->width;
+ w->SetTop(22);
+ link->SetLeft(w->Left() - link->Width());
}
}
--- a/src/town_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/town_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -457,7 +457,7 @@
if (++n == w->vscroll.cap) break; // max number of towns in 1 window
}
SetDParam(0, GetWorldPopulation());
- DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, 0);
+ DrawString(3, w->Height() - 12 + 2, STR_TOWN_POPULATION, 0);
}
} break;
@@ -520,6 +520,6 @@
if (w != NULL) {
w->vscroll.cap = 16;
w->resize.step_height = 10;
- w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
+ w->resize.height = w->Height() - 10 * 6; // minimum of 10 items in the list, each item 10 high
}
}
--- a/src/train_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/train_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -612,7 +612,7 @@
w->widget[4].data = (w->vscroll.cap << 8) + 1;
w->resize.step_height = 14;
- w->resize.height = w->height - 14 * 2; /* Minimum of 4 wagons in the display */
+ w->resize.height = w->Height() - 14 * 2; /* Minimum of 4 wagons in the display */
WP(w,traindetails_d).tab = 0;
}
--- a/src/vehicle_gui.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/vehicle_gui.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -1266,8 +1266,8 @@
if (w != NULL) {
/* Set the minimum window size to the current window size */
- w->resize.width = w->width;
- w->resize.height = w->height;
+ w->resize.width = w->Width();
+ w->resize.height = w->Height();
}
}
--- a/src/viewport.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/viewport.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -153,8 +153,8 @@
}
SETBIT(_active_viewports, bit);
- vp->left = x + w->left;
- vp->top = y + w->top;
+ vp->left = x + w->Left();
+ vp->top = y + w->Top();
vp->width = width;
vp->height = height;
@@ -193,32 +193,32 @@
for (WindowList::Iterator wit = vit; wit != BaseWindow::s_list.m_list.end(); wit++) {
const BaseWindow *w = (*wit).w;
- if (left + width > w->left &&
- w->left + w->width > left &&
- top + height > w->top &&
- w->top + w->height > top) {
-
- if (left < w->left) {
- DoSetViewportPosition(wit, left, top, w->left - left, height);
- DoSetViewportPosition(wit, left + (w->left - left), top, width - (w->left - left), height);
+ if (left + width > w->Left() &&
+ w->Left() + w->Width() > left &&
+ top + height > w->Top() &&
+ w->Top() + w->Height() > top) {
+
+ if (left < w->Left()) {
+ DoSetViewportPosition(wit, left, top, w->Left() - left, height);
+ DoSetViewportPosition(wit, left + (w->Left() - left), top, width - (w->Left() - left), height);
return;
}
- if (left + width > w->left + w->width) {
- DoSetViewportPosition(wit, left, top, (w->left + w->width - left), height);
- DoSetViewportPosition(wit, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height);
+ if (left + width > w->Left() + w->Width()) {
+ DoSetViewportPosition(wit, left, top, (w->Left() + w->Width() - left), height);
+ DoSetViewportPosition(wit, left + (w->Left() + w->Width() - left), top, width - (w->Left() + w->Width() - left) , height);
return;
}
- if (top < w->top) {
- DoSetViewportPosition(wit, left, top, width, (w->top - top));
- DoSetViewportPosition(wit, left, top + (w->top - top), width, height - (w->top - top));
+ if (top < w->Top()) {
+ DoSetViewportPosition(wit, left, top, width, (w->Top() - top));
+ DoSetViewportPosition(wit, left, top + (w->Top() - top), width, height - (w->Top() - top));
return;
}
- if (top + height > w->top + w->height) {
- DoSetViewportPosition(wit, left, top, width, (w->top + w->height - top));
- DoSetViewportPosition(wit, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top));
+ if (top + height > w->Top() + w->Height()) {
+ DoSetViewportPosition(wit, left, top, width, (w->Top() + w->Height() - top));
+ DoSetViewportPosition(wit, left, top + (w->Top() + w->Height() - top), width , height - (w->Top() + w->Height() - top));
return;
}
@@ -1336,13 +1336,13 @@
{
DrawPixelInfo *dpi = _cur_dpi;
- dpi->left += left;
- dpi->top += top;
+ dpi->left += Left();
+ dpi->top += Top();
ViewportDraw(viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
- dpi->left -= left;
- dpi->top -= top;
+ dpi->left -= Left();
+ dpi->top -= Top();
}
void UpdateViewportPosition(BaseWindow *w)
--- a/src/widget.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/widget.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -464,7 +464,7 @@
if (flash_timeout > 0) {
//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
- DrawFrameRect(0, 0, width-1, height-1, 0xF, FR_BORDERONLY);
+ DrawFrameRect(0, 0, Width() - 1, Height() - 1, 0xF, FR_BORDERONLY);
}
}
@@ -480,10 +480,10 @@
byte item, counter;
int y;
- if (w->GetWidgetFromPos(_cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
+ if (w->GetWidgetFromPos(_cursor.pos.x - w->Left(), _cursor.pos.y - w->Top()) < 0)
return -1;
- y = _cursor.pos.y - w->top - 2 + w->vscroll.pos * 10;
+ y = _cursor.pos.y - w->Top() - 2 + w->vscroll.pos * 10;
if (y < 0)
return - 1;
@@ -534,8 +534,8 @@
int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
- GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
- GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
+ GfxFillRect(x + 1, y + 3, x + w->Width() - 5, y + 3, c1);
+ GfxFillRect(x + 1, y + 4, x + w->Width() - 5, y + 4, c2);
}
}
y += 10;
@@ -628,20 +628,20 @@
}
/* The preferred position is just below the dropdown calling widget */
- menu_top = top + wi->bottom + 2;
+ menu_top = Top() + wi->bottom + 2;
menu_height = i * 10 + 4;
w2 = BaseWindow::FindById(WC_STATUS_BAR, 0);
- screen_bottom = w2 == NULL ? _screen.height : w2->top;
+ screen_bottom = w2 == NULL ? _screen.height : w2->Top();
/* Check if the dropdown will fully fit below the widget */
if (menu_top + menu_height >= screen_bottom) {
w2 = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
- screen_top = w2 == NULL ? 0 : w2->top + w2->height;
+ screen_top = w2 == NULL ? 0 : w2->Top() + w2->Height();
/* If not, check if it will fit above the widget */
- if (top + wi->top - menu_height - 1 > screen_top) {
- menu_top = top + wi->top - menu_height - 1;
+ if (Top() + wi->top - menu_height - 1 > screen_top) {
+ menu_top = Top() + wi->top - menu_height - 1;
} else {
/* ... and lastly if it won't, enable the scroll bar and fit the
* list in below the widget */
@@ -652,7 +652,7 @@
}
w1 = BaseWindow::Allocate(
- left + wi[-1].left + 1,
+ Left() + wi[-1].left + 1,
menu_top,
wi->right - wi[-1].left + 1,
menu_height,
--- a/src/widget/widget_base.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/widget/widget_base.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -56,6 +56,11 @@
return m_rect.BottomRight();
}
+Point16 Widget::Size() const
+{
+ return m_rect.Size();
+}
+
const Rect16& Widget::GetRect() const
{
return m_rect;
@@ -102,6 +107,11 @@
m_rect.SetBottomRight(pt);
}
+void Widget::SetSize(const Point16 &pt)
+{
+ m_rect.SetSize(pt);
+}
+
void Widget::SetRect(const Rect16 &rect)
{
m_rect = rect;
--- a/src/window.cpp Mon Feb 19 20:37:33 2007 +0000
+++ b/src/window.cpp Tue Feb 27 13:26:47 2007 +0000
@@ -90,7 +90,7 @@
static bool MatchXY(WindowList::Iterator it, int x, int y)
{
BaseWindow *w = (*it).w;
- return IS_INSIDE_1D(x, w->left, w->width) && IS_INSIDE_1D(y, w->top, w->height);
+ return IS_INSIDE_1D(x, w->Left(), w->Width()) && IS_INSIDE_1D(y, w->Top(), w->Height());
}
/** Do a search for a window at specific coordinates. For this we start
@@ -102,6 +102,100 @@
}
+int16 BaseWindow::Left() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return m_wnd_pos.x;
+}
+
+int16 BaseWindow::Top() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return m_wnd_pos.y;
+}
+
+int16 BaseWindow::Right() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return m_wnd_pos.x + super::Right();
+}
+
+int16 BaseWindow::Bottom() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return m_wnd_pos.y + super::Bottom();
+}
+
+const Point16& BaseWindow::TopLeft() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return m_wnd_pos;
+}
+
+Point16 BaseWindow::BottomRight() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return m_wnd_pos + super::BottomRight();
+}
+
+Rect16 BaseWindow::GetRect() const
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ return super::GetRect() + m_wnd_pos;
+}
+
+
+void BaseWindow::SetLeft(int16 val)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ m_wnd_pos.x = val;
+}
+
+void BaseWindow::SetTop(int16 val)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ m_wnd_pos.y = val;
+}
+
+void BaseWindow::SetRight(int16 val)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ assert(val >= m_wnd_pos.x);
+ super::SetRight(val - m_wnd_pos.x);
+}
+
+void BaseWindow::SetBottom(int16 val)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ assert(val >= m_wnd_pos.y);
+ super::SetBottom(val - m_wnd_pos.y);
+}
+
+void BaseWindow::SetTopLeft(const Point16 &pt)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ m_wnd_pos = pt;
+}
+
+void BaseWindow::SetBottomRight(const Point16 &pt)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ super::SetBottomRight(pt - m_wnd_pos);
+}
+
+void BaseWindow::SetSize(const Point16 &pt)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ super::SetSize(pt);
+}
+
+void BaseWindow::SetRect(const Rect16 &rect)
+{
+ assert(super::TopLeft() == Point16(0, 0));
+ m_wnd_pos = rect.top_left;
+ super::SetBottomRight(rect.Size());
+}
+
/*virtual*/ bool BaseWindow::Create(const WindowDesc *desc, WindowNumber num)
@@ -109,15 +203,13 @@
window_class = desc->cls;
flash_timeout = 3; // just opened windows have a white border
caption_color = 0xFF;
- left = desc->left;
- top = desc->top;
- width = desc->width;
- height = desc->height;
+ SetTopLeft(Point16(desc->left, desc->top));
+ SetSize(Point16(desc->width, desc->height));
wndproc = desc->proc;
desc_flags = desc->flags;
AssignWidget(desc->widgets);
- resize.width = width;
- resize.height = height;
+ resize.width = Width();
+ resize.height = Height();
resize.step_width = 1;
resize.step_height = 1;
window_number = num;
@@ -175,21 +267,21 @@
* it to an automatic place */
if (desc->parent_cls != WC_MAIN_WINDOW &&
(w = BaseWindow::FindById(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) {
- pt.x = w->left + 10;
+ pt.x = w->Left() + 10;
if (pt.x > _screen.width + 10 - desc->width) {
pt.x = (_screen.width + 10 - desc->width) - 20;
}
- pt.y = w->top + 10;
+ pt.y = w->Top() + 10;
} else {
switch (desc->left) {
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
w = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
- pt.x = (w->left + w->width) - desc->width;
+ pt.x = (w->Left() + w->Width()) - desc->width;
} break;
case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */
- pt.x = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0)->left;
+ pt.x = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0)->Left();
break;
case WDP_AUTO: /* Find a good automatic position for the window */
pt = GetAutoPlacePosition(desc->width, desc->height);
@@ -278,7 +370,7 @@
void BaseWindow::SetDirty() const
{
if (this == NULL) return;
- SetDirtyBlocks(left, top, left + width, top + height);
+ SetDirtyBlocks(Left(), Top(), Left() + Width(), Top() + Height());
}
/*virtual*/ void BaseWindow::FinalRelease()
@@ -439,8 +531,8 @@
flags4 |= WF_DRAGGING;
_dragging_window = true;
- _drag_delta.x = left - _cursor.pos.x;
- _drag_delta.y = top - _cursor.pos.y;
+ _drag_delta.x = Left() - _cursor.pos.x;
+ _drag_delta.y = Top() - _cursor.pos.y;
BringToFront();
DeleteWindowById(WC_DROPDOWN_MENU, 0);
@@ -479,66 +571,66 @@
FOR_ALL_WINDOWS(v) {
if (v == this) continue; // Don't snap at yourself
- if (y + height > v->top && y < v->top + v->height) {
+ if (y + Height() > v->Top() && y < v->Top() + v->Height()) {
// Your left border <-> other right border
- delta = abs(v->left + v->width - x);
+ delta = abs(v->Left() + v->Width() - x);
if (delta <= hsnap) {
- nx = v->left + v->width;
+ nx = v->Left() + v->Width();
hsnap = delta;
}
// Your right border <-> other left border
- delta = abs(v->left - x - width);
+ delta = abs(v->Left() - x - Width());
if (delta <= hsnap) {
- nx = v->left - width;
+ nx = v->Left() - Width();
hsnap = delta;
}
}
- if (top + height >= v->top && top <= v->top + v->height) {
+ if (Top() + Height() >= v->Top() && Top() <= v->Top() + v->Height()) {
// Your left border <-> other left border
- delta = abs(v->left - x);
+ delta = abs(v->Left() - x);
if (delta <= hsnap) {
- nx = v->left;
+ nx = v->Left();
hsnap = delta;
}
// Your right border <-> other right border
- delta = abs(v->left + v->width - x - width);
+ delta = abs(v->Left() + v->Width() - x - Width());
if (delta <= hsnap) {
- nx = v->left + v->width - width;
+ nx = v->Left() + v->Width() - Width();
hsnap = delta;
}
}
- if (x + width > v->left && x < v->left + v->width) {
+ if (x + Width() > v->Left() && x < v->Left() + v->Width()) {
// Your top border <-> other bottom border
- delta = abs(v->top + v->height - y);
+ delta = abs(v->Top() + v->Height() - y);
if (delta <= vsnap) {
- ny = v->top + v->height;
+ ny = v->Top() + v->Height();
vsnap = delta;
}
// Your bottom border <-> other top border
- delta = abs(v->top - y - height);
+ delta = abs(v->Top() - y - Height());
if (delta <= vsnap) {
- ny = v->top - height;
+ ny = v->Top() - Height();
vsnap = delta;
}
}
- if (left + width >= v->left && left <= v->left + v->width) {
+ if (Left() + Width() >= v->Left() && Left() <= v->Left() + v->Width()) {
// Your top border <-> other top border
- delta = abs(v->top - y);
+ delta = abs(v->Top() - y);
if (delta <= vsnap) {
- ny = v->top;
+ ny = v->Top();
vsnap = delta;
}
// Your bottom border <-> other bottom border
- delta = abs(v->top + v->height - y - height);
+ delta = abs(v->Top() + v->Height() - y - Height());
if (delta <= vsnap) {
- ny = v->top + v->height - height;
+ ny = v->Top() + v->Height() - Height();
vsnap = delta;
}
}
@@ -553,19 +645,19 @@
// Make sure the title bar isn't hidden by behind the main tool bar
v = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
if (v != NULL) {
- int v_bottom = v->top + v->height;
- int v_right = v->left + v->width;
- if (ny + t->top >= v->top && ny + t->top < v_bottom) {
- if ((v->left < 13 && nx + t->left < v->left) ||
+ int v_bottom = v->Top() + v->Height();
+ int v_right = v->Left() + v->Width();
+ if (ny + t->top >= v->Top() && ny + t->top < v_bottom) {
+ if ((v->Left() < 13 && nx + t->left < v->Left()) ||
(v_right > _screen.width - 13 && nx + t->right > v_right)) {
ny = v_bottom;
} else {
- if (nx + t->left > v->left - 13 &&
+ if (nx + t->left > v->Left() - 13 &&
nx + t->right < v_right + 13) {
- if (top >= v_bottom) {
+ if (Top() >= v_bottom) {
ny = v_bottom;
- } else if (left < nx) {
- nx = v->left - 13 - t->left;
+ } else if (Left() < nx) {
+ nx = v->Left() - 13 - t->left;
} else {
nx = v_right + 13 - t->right;
}
@@ -575,11 +667,10 @@
}
if (viewport != NULL) {
- viewport->left += nx - left;
- viewport->top += ny - top;
+ viewport->left += nx - Left();
+ viewport->top += ny - Top();
}
- left = nx;
- top = ny;
+ SetTopLeft(Point16(nx, ny));
SetDirty();
return false;
@@ -621,10 +712,10 @@
if (resize.step_height > 1) y -= y % (int)resize.step_height;
/* Check if we don't go below the minimum set size */
- if ((int)width + x < (int)resize.width)
- x = resize.width - width;
- if ((int)height + y < (int)resize.height)
- y = resize.height - height;
+ if (Width() + x < (int)resize.width)
+ x = resize.width - Width();
+ if (Height() + y < (int)resize.height)
+ y = resize.height - Height();
/* BaseWindow already on size */
if (x == 0 && y == 0) return false;
@@ -638,8 +729,8 @@
this->Resize(x, y);
e.event = WE_RESIZE;
- e.we.sizing.size.x = x + width;
- e.we.sizing.size.y = y + height;
+ e.we.sizing.size.x = x + Width();
+ e.we.sizing.size.y = y + Height();
e.we.sizing.diff.x = x;
e.we.sizing.diff.y = y;
wndproc(this, &e);
@@ -791,29 +882,29 @@
const BaseWindow *v = (*vit).w;
int x;
- if (right > v->left &&
- bottom > v->top &&
- left < v->left + v->width &&
- top < v->top + v->height) {
- if (left < (x=v->left)) {
+ if (right > v->Left() &&
+ bottom > v->Top() &&
+ left < v->Left() + v->Width() &&
+ top < v->Top() + v->Height()) {
+ if (left < (x = v->Left())) {
DrawOverlappedWindow(wit, left, top, x, bottom);
DrawOverlappedWindow(wit, x, top, right, bottom);
return;
}
- if (right > (x=v->left + v->width)) {
+ if (right > (x=v->Left() + v->Width())) {
DrawOverlappedWindow(wit, left, top, x, bottom);
DrawOverlappedWindow(wit, x, top, right, bottom);
return;
}
- if (top < (x=v->top)) {
+ if (top < (x=v->Top())) {
DrawOverlappedWindow(wit, left, top, right, x);
DrawOverlappedWindow(wit, left, x, right, bottom);
return;
}
- if (bottom > (x=v->top + v->height)) {
+ if (bottom > (x=v->Top() + v->Height())) {
DrawOverlappedWindow(wit, left, top, right, x);
DrawOverlappedWindow(wit, left, x, right, bottom);
return;
@@ -827,8 +918,8 @@
DrawPixelInfo *dp = _cur_dpi;
dp->width = right - left;
dp->height = bottom - top;
- dp->left = left - w->left;
- dp->top = top - w->top;
+ dp->left = left - w->Left();
+ dp->top = top - w->Top();
dp->pitch = _screen.pitch;
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
dp->zoom = 0;
@@ -843,10 +934,10 @@
const BaseWindow *w = NULL;
FOR_ALL_WINDOWS(w) {
- if (right > w->left &&
- bottom > w->top &&
- left < w->left + w->width &&
- top < w->top + w->height) {
+ if (right > w->Left() &&
+ bottom > w->Top() &&
+ left < w->Left() + w->Width() &&
+ top < w->Top() + w->Height()) {
DrawOverlappedWindow(it, left, top, right, bottom);
}
}
@@ -1070,10 +1161,10 @@
FOR_ALL_WINDOWS(w) {
if (w->window_class == WC_MAIN_WINDOW) continue;
- if (right > w->left &&
- w->left + w->width > left &&
- bottom > w->top &&
- w->top + w->height > top) {
+ if (right > w->Left() &&
+ w->Left() + w->Width() > left &&
+ bottom > w->Top() &&
+ w->Top() + w->Height() > top) {
return false;
}
}
@@ -1098,10 +1189,10 @@
FOR_ALL_WINDOWS(w) {
if (w->window_class == WC_MAIN_WINDOW) continue;
- if (left + width > w->left &&
- w->left + w->width > left &&
- top + height > w->top &&
- w->top + w->height > top) {
+ if (left + width > w->Left() &&
+ w->Left() + w->Width() > left &&
+ top + height > w->Top() &&
+ w->Top() + w->Height() > top) {
return false;
}
}
@@ -1122,23 +1213,23 @@
FOR_ALL_WINDOWS(w) {
if (w->window_class == WC_MAIN_WINDOW) continue;
- if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos;
- if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left() + w->Width() + 2, w->Top())) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left() - width - 2, w->Top())) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left(), w->Top() + w->Height() + 2)) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left(), w->Top() - height - 2)) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left() + w->Width() + 2, w->Top() + w->Height() - height)) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left() - width - 2, w->Top() + w->Height() - height)) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left() + w->Width() - width, w->Top() + w->Height() + 2)) goto ok_pos;
+ if (IsGoodAutoPlace1(w->Left() + w->Width() - width, w->Top() - height - 2)) goto ok_pos;
}
FOR_ALL_WINDOWS(w) {
if (w->window_class == WC_MAIN_WINDOW) continue;
- if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos;
- if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos;
- if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos;
- if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos;
+ if (IsGoodAutoPlace2(w->Left() + w->Width() + 2, w->Top())) goto ok_pos;
+ if (IsGoodAutoPlace2(w->Left() - width - 2, w->Top())) goto ok_pos;
+ if (IsGoodAutoPlace2(w->Left(), w->Top() + w->Height() + 2)) goto ok_pos;
+ if (IsGoodAutoPlace2(w->Left(), w->Top() - height - 2)) goto ok_pos;
}
{
@@ -1146,7 +1237,7 @@
restart:;
FOR_ALL_WINDOWS(w) {
- if (w->left == left && w->top == top) {
+ if (w->Left() == left && w->Top() == top) {
left += 5;
top += 5;
goto restart;
@@ -1275,8 +1366,8 @@
if (w != NULL) {
// send an event in client coordinates.
e.event = WE_DRAGDROP;
- e.we.dragdrop.pt.x = _cursor.pos.x - w->left;
- e.we.dragdrop.pt.y = _cursor.pos.y - w->top;
+ e.we.dragdrop.pt.x = _cursor.pos.x - w->Left();
+ e.we.dragdrop.pt.y = _cursor.pos.y - w->Top();
e.we.dragdrop.widget = w->GetWidgetFromPos(e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
w->wndproc(w, &e);
}
@@ -1336,8 +1427,8 @@
if (w != NULL) {
// send an event in client coordinates.
e.event = WE_MOUSEOVER;
- e.we.mouseover.pt.x = _cursor.pos.x - w->left;
- e.we.mouseover.pt.y = _cursor.pos.y - w->top;
+ e.we.mouseover.pt.x = _cursor.pos.x - w->Left();
+ e.we.mouseover.pt.y = _cursor.pos.y - w->Top();
if (w->widget != NULL) {
e.we.mouseover.widget = w->GetWidgetFromPos(e.we.mouseover.pt.x, e.we.mouseover.pt.y);
}
@@ -1391,8 +1482,8 @@
}
/* We resized at least 1 widget, so let's resize the window totally */
- if (resize_width) width += x;
- if (resize_height) height += y;
+ if (resize_width) SetWidth(Width() + x);
+ if (resize_height) SetHeight(Height() + y);
SetDirty();
}
@@ -1512,10 +1603,10 @@
}
/* BaseWindow sizes don't interfere, leave z-order alone */
- if (w->left + w->width <= u->left ||
- u->left + u->width <= w->left ||
- w->top + w->height <= u->top ||
- u->top + u->height <= w->top) {
+ if (w->Left() + w->Width() <= u->Left() ||
+ u->Left() + u->Width() <= w->Left() ||
+ w->Top() + w->Height() <= u->Top() ||
+ u->Top() + u->Height() <= w->Top()) {
continue;
}
@@ -1715,7 +1806,7 @@
w->wndproc(w, &e);
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
- if (vp == NULL) w->DispatchMouseWheelEvent(w->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
+ if (vp == NULL) w->DispatchMouseWheelEvent(w->GetWidgetFromPos(x - w->Left(), y - w->Top()), mousewheel);
}
if (vp != NULL) {
@@ -1747,8 +1838,8 @@
}
} else {
switch (click) {
- case 1: w->DispatchLeftClickEvent(x - w->left, y - w->top); break;
- case 2: w->DispatchRightClickEvent(x - w->left, y - w->top); break;
+ case 1: w->DispatchLeftClickEvent (x - w->Left(), y - w->Top()); break;
+ case 2: w->DispatchRightClickEvent(x - w->Left(), y - w->Top()); break;
}
}
}
@@ -1828,7 +1919,7 @@
int BaseWindow::GetMenuItemIndex(int x, int y) const
{
- if ((x -= left) >= 0 && x < width && (y -= top + 1) >= 0) {
+ if ((x -= Left()) >= 0 && x < Width() && (y -= Top() + 1) >= 0) {
y /= 10;
if (y < WP(this, const menu_d).item_count &&
@@ -1855,7 +1946,7 @@
/* Don't redraw the window if the widget is invisible or of no-type */
if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return;
- SetDirtyBlocks(left + wi->left, top + wi->top, left + wi->right + 1, top + wi->bottom + 1);
+ SetDirtyBlocks(Left() + wi->left, Top() + wi->top, Left() + wi->right + 1, Top() + wi->bottom + 1);
}
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
@@ -1969,12 +2060,12 @@
}
switch (_patches.toolbar_pos) {
- case 1: w->left = (_screen.width - w->width) / 2; break;
- case 2: w->left = _screen.width - w->width; break;
- default: w->left = 0;
+ case 1: w->SetLeft((_screen.width - w->Width()) / 2); break;
+ case 2: w->SetLeft(_screen.width - w->Width()); break;
+ default: w->SetLeft(0);
}
- SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part
- return w->left;
+ SetDirtyBlocks(0, 0, _screen.width, w->Height()); // invalidate the whole top part
+ return w->Left();
}
void RelocateAllWindows(int neww, int newh)
@@ -1985,8 +2076,9 @@
if (w->window_class == WC_MAIN_WINDOW) {
ViewPort *vp = w->viewport;
- vp->width = w->width = neww;
- vp->height = w->height = newh;
+ w->SetSize(Point(neww, newh));
+ vp->width = neww;
+ vp->height = newh;
vp->virtual_width = neww << vp->zoom;
vp->virtual_height = newh << vp->zoom;
continue; // don't modify top,left
@@ -1996,30 +2088,30 @@
* in a 'backup'-desc that the window should always be centred. */
switch (w->window_class) {
case WC_MAIN_TOOLBAR:
- top = w->top;
+ top = w->Top();
left = PositionMainToolbar(w); // changes toolbar orientation
break;
case WC_SELECT_GAME:
case WC_GAME_OPTIONS:
case WC_NETWORK_WINDOW:
- top = (newh - w->height) >> 1;
- left = (neww - w->width) >> 1;
+ top = (newh - w->Height()) >> 1;
+ left = (neww - w->Width()) >> 1;
break;
case WC_NEWS_WINDOW:
- top = newh - w->height;
- left = (neww - w->width) >> 1;
+ top = newh - w->Height();
+ left = (neww - w->Width()) >> 1;
break;
case WC_STATUS_BAR:
- top = newh - w->height;
- left = (neww - w->width) >> 1;
+ top = newh - w->Height();
+ left = (neww - w->Width()) >> 1;
break;
case WC_SEND_NETWORK_MSG:
top = (newh - 26); // 26 = height of status bar + height of chat bar
- left = (neww - w->width) >> 1;
+ left = (neww - w->Width()) >> 1;
break;
case WC_CONSOLE:
@@ -2027,19 +2119,18 @@
continue;
default:
- left = w->left;
- if (left + (w->width >> 1) >= neww) left = neww - w->width;
- top = w->top;
- if (top + (w->height >> 1) >= newh) top = newh - w->height;
+ left = w->Left();
+ if (left + (w->Width() >> 1) >= neww) left = neww - w->Width();
+ top = w->Top();
+ if (top + (w->Height() >> 1) >= newh) top = newh - w->Height();
break;
}
if (w->viewport != NULL) {
- w->viewport->left += left - w->left;
- w->viewport->top += top - w->top;
+ w->viewport->left += left - w->Left();
+ w->viewport->top += top - w->Top();
}
- w->left = left;
- w->top = top;
+ w->SetTopLeft(Point(left, top));
}
}
--- a/src/window.h Mon Feb 19 20:37:33 2007 +0000
+++ b/src/window.h Tue Feb 27 13:26:47 2007 +0000
@@ -363,6 +363,7 @@
int16 Height() const;
const Point16& TopLeft() const;
const Point16& BottomRight() const;
+ Point16 Size() const;
const Rect16& GetRect() const;
void SetLeft(int16 val);
@@ -373,6 +374,7 @@
void SetHeight(int16 val);
void SetTopLeft(const Point16 &pt);
void SetBottomRight(const Point16 &pt);
+ void SetSize(const Point16 &pt);
void SetRect(const Rect16 &rect);
WidgetId GetId() const;
@@ -493,6 +495,8 @@
struct BaseWindow : public CompositeWidget {
public:
+ typedef CompositeWidget super;
+
static WindowList s_list;
ZeroInitBegin m_zero_init_area; ///< following members get cleared by constructor
@@ -501,9 +505,10 @@
WindowClass window_class;
WindowNumber window_number;
- int left, top;
- int width, height;
+protected:
+ Point16 m_wnd_pos;
+public:
Scrollbar hscroll, vscroll, vscroll2;
ResizeInfo resize;
@@ -530,6 +535,23 @@
Create(desc, num);
}
+ int16 Left() const;
+ int16 Top() const;
+ int16 Right() const;
+ int16 Bottom() const;
+ const Point16& TopLeft() const;
+ Point16 BottomRight() const;
+ Rect16 GetRect() const;
+
+ void SetLeft(int16 val);
+ void SetTop(int16 val);
+ void SetRight(int16 val);
+ void SetBottom(int16 val);
+ void SetTopLeft(const Point16 &pt);
+ void SetBottomRight(const Point16 &pt);
+ void SetSize(const Point16 &pt);
+ void SetRect(const Rect16 &rect);
+
virtual bool Create(const WindowDesc *desc, WindowNumber num = 0);
static BaseWindow* Allocate(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const OldWidget *widget);