From c00ce644585beb5348565a25c03373ad5b68d8a8 Mon Sep 17 00:00:00 2001 From: alberth Date: Thu, 16 Jul 2009 10:26:13 +0000 Subject: (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function. --- src/widget.cpp | 26 +++++++++++++------------- src/widget_type.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/widget.cpp b/src/widget.cpp index 1f5a8b9e5..b3585a844 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -330,43 +330,43 @@ static inline void DrawInset(const Rect &r, Colours colour, StringID str) * @param r Rectangle of the matrix background. * @param colour Colour of the background. * @param clicked Matrix is rendered lowered. - * @param data Data of the widget. + * @param data Data of the widget, number of rows and columns of the widget. */ static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data) { DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE); - int c = GB(data, 0, 8); - int amt1 = (r.right - r.left + 1) / c; + int num_columns = GB(data, 0, 8); // Lower 8 bits of the widget data: Number of columns in the matrix. + int column_width = (r.right - r.left + 1) / num_columns; // Width of a single column in the matrix. - int d = GB(data, 8, 8); - int amt2 = (r.bottom - r.top + 1) / d; + int num_rows = GB(data, 8, 8); // Upper 8 bits of the widget data: Number of rows in the matrix. + int row_height = (r.bottom - r.top + 1) / num_rows; // Height of a single row in the matrix. int col = _colour_gradient[colour & 0xF][6]; int x = r.left; - for (int ctr = c; ctr > 1; ctr--) { - x += amt1; + for (int ctr = num_columns; ctr > 1; ctr--) { + x += column_width; GfxFillRect(x, r.top + 1, x, r.bottom - 1, col); } x = r.top; - for (int ctr = d; ctr > 1; ctr--) { - x += amt2; + for (int ctr = num_rows; ctr > 1; ctr--) { + x += row_height; GfxFillRect(r.left + 1, x, r.right - 1, x, col); } col = _colour_gradient[colour & 0xF][4]; x = r.left - 1; - for (int ctr = c; ctr > 1; ctr--) { - x += amt1; + for (int ctr = num_columns; ctr > 1; ctr--) { + x += column_width; GfxFillRect(x, r.top + 1, x, r.bottom - 1, col); } x = r.top - 1; - for (int ctr = d; ctr > 1; ctr--) { - x += amt2; + for (int ctr = num_rows; ctr > 1; ctr--) { + x += row_height; GfxFillRect(r.left + 1, x, r.right - 1, x, col); } } diff --git a/src/widget_type.h b/src/widget_type.h index beef4421d..8a496d9a8 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -81,7 +81,7 @@ enum WidgetType { WWT_TEXTBTN_2, ///< Button with diff text when clicked WWT_LABEL, ///< Centered label WWT_TEXT, ///< Pure simple text - WWT_MATRIX, ///< List of items underneath each other + WWT_MATRIX, ///< Grid of rows and columns. Lower 8 bit of the widget data are the number of columns, upper 8 bit are the number of rows. WWT_SCROLLBAR, ///< Vertical scrollbar WWT_FRAME, ///< Frame WWT_CAPTION, ///< Window caption (window title between closebox and stickybox) -- cgit v1.2.3-54-g00ecf