(svn r17740) -Codechange: Extract financial expenses drawing routines.

pull/155/head
alberth 15 years ago
parent 79a0aca3bc
commit 2145e02fde

@ -114,84 +114,114 @@ enum CompanyFinancesWindowWidgets {
CFW_REPAY_LOAN, ///< Decrease loan CFW_REPAY_LOAN, ///< Decrease loan
}; };
static void DrawCompanyEconomyStats(const Company *c, bool small, const Widget *widget) /** Draw the expenses categories.
* @param r Available space for drawing.
* @note The environment must provide padding at the left and right of \a r.
*/
static int DrawCategories(const Rect &r)
{ {
int type = _settings_client.gui.expenses_layout; int y = r.top + WD_FRAMERECT_TOP;
int y;
const Money (*tbl)[EXPENSES_END];
StringID str;
if (!small) { // normal sized economics window DrawString(r.left, r.right, y, STR_FINANCES_EXPENDITURE_INCOME_TITLE, TC_FROMSTRING, SA_CENTER, true);
const Widget *w = &widget[CFW_EXPS_CATEGORY]; y += 10 + 2;
/* draw categories */
DrawString(w->left, w->right, 15, STR_FINANCES_EXPENDITURE_INCOME_TITLE, TC_FROMSTRING, SA_CENTER, true); int type = _settings_client.gui.expenses_layout;
for (int i = 0; i < _expenses_list_types[type].length; i++) {
y = 27; const ExpensesType et = _expenses_list_types[type].et[i];
for (int i = 0; i < _expenses_list_types[type].length; i++) { if (et == INVALID_EXPENSES) {
ExpensesType et = _expenses_list_types[type].et[i]; y += 2;
if (et == INVALID_EXPENSES) { DrawString(r.left, r.right, y, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
y += 2; y += 20;
DrawString(w->left + 2, w->right - 2, y, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT); } else {
y += 20; DrawString(r.left, r.right, y, STR_FINANCES_SECTION_CONSTRUCTION + et);
} else { y += 10;
DrawString(w->left + 2, w->right - 2, y, STR_FINANCES_SECTION_CONSTRUCTION + et);
y += 10;
}
} }
}
DrawString(w->left + 2, w->right - 2, y + 2, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT); DrawString(r.left, r.right, y + 2, STR_FINANCES_TOTAL_CAPTION, TC_FROMSTRING, SA_RIGHT);
return y;
}
/* draw the price columns */ /** Draw an amount of money.
int year = _cur_year - 2; * @param amount Amount of money to draw,
int j = 3; * @param left Left coordinate of the space to draw in.
w++; * @param right Right coordinate of the space to draw in.
tbl = c->yearly_expenses + 2; * @param top Top coordinate of the space to draw in.
*/
static void DrawPrice(Money amount, int left, int right, int top)
{
StringID str = STR_FINANCES_NEGATIVE_INCOME;
if (amount < 0) {
amount = -amount;
str++;
}
SetDParam(0, amount);
DrawString(left, right, top, str, TC_FROMSTRING, SA_RIGHT);
}
do { /** Draw a column with prices.
if (year >= c->inaugurated_year) { * @param r Available space for drawing.
SetDParam(0, year); * @param year Year being drawn.
DrawString(w->left, w->right, 15, STR_FINANCES_YEAR, TC_FROMSTRING, SA_RIGHT, true); * @param tbl Pointer to table of amounts for \a year.
* @note The environment must provide padding at the left and right of \a r.
*/
static void DrawYearColumn(const Rect &r, int year, const Money (*tbl)[EXPENSES_END])
{
int y = r.top + WD_FRAMERECT_TOP;
Money sum = 0; SetDParam(0, year);
Money subtotal = 0; DrawString(r.left, r.right, y, STR_FINANCES_YEAR, TC_FROMSTRING, SA_RIGHT, true);
y += 10 + 2;
int y = 27; Money sum = 0;
Money subtotal = 0;
int type = _settings_client.gui.expenses_layout;
for (int i = 0; i < _expenses_list_types[type].length; i++) {
const ExpensesType et = _expenses_list_types[type].et[i];
if (et == INVALID_EXPENSES) {
Money cost = subtotal;
subtotal = 0;
GfxFillRect(r.left, y, r.right, y, 215);
y += 2;
DrawPrice(cost, r.left, r.right, y + 2);
y += 20;
} else {
Money cost = (*tbl)[et];
subtotal += cost;
sum += cost;
if (cost != 0) DrawPrice(cost, r.left, r.right, y + 2);
y += 10;
}
}
for (int i = 0; i < _expenses_list_types[type].length; i++) { GfxFillRect(r.left, y, r.right, y, 215);
ExpensesType et = _expenses_list_types[type].et[i]; y += 2;
Money cost; DrawPrice(sum, r.left, r.right, y);
}
if (et == INVALID_EXPENSES) { static void DrawCompanyEconomyStats(const Company *c, bool small, const Widget *widget)
GfxFillRect(w->left, y, w->right, y, 215); {
cost = subtotal; int y;
subtotal = 0;
y += 2;
} else {
cost = (*tbl)[et];
subtotal += cost;
sum += cost;
}
if (cost != 0 || et == INVALID_EXPENSES) { if (!small) { // normal sized economics window
str = STR_FINANCES_NEGATIVE_INCOME; const Widget *w = &widget[CFW_EXPS_CATEGORY];
if (cost < 0) { cost = -cost; str++; } const Rect r = {w->left + WD_FRAMERECT_LEFT, 14, w->right - WD_FRAMERECT_RIGHT, w->bottom};
SetDParam(0, cost); y = DrawCategories(r);
DrawString(w->left, w->right, y, str, TC_FROMSTRING, SA_RIGHT);
}
y += (et == INVALID_EXPENSES) ? 20 : 10;
}
str = STR_FINANCES_NEGATIVE_INCOME; /* draw the price columns */
if (sum < 0) { sum = -sum; str++; } int year = _cur_year - 2;
SetDParam(0, sum); w++;
DrawString(w->left, w->right, y + 2, str, TC_FROMSTRING, SA_RIGHT); const Money (*tbl)[EXPENSES_END] = c->yearly_expenses + 2;
GfxFillRect(w->left, y, w->right, y, 215); for (int j = 0; j < 3; j++) {
if (year >= c->inaugurated_year) {
const Rect r = {w->left, 14, w->right, w->bottom};
DrawYearColumn(r, year, tbl);
w++; w++;
} }
year++; year++;
tbl--; tbl--;
} while (--j != 0); }
y += 14; y += 14;

Loading…
Cancel
Save