From 81f2bfed359cb87f0eeeec2eda109b21331c9c69 Mon Sep 17 00:00:00 2001 From: ddevrien Date: Sun, 11 May 2014 10:51:05 +0200 Subject: [PATCH 1/8] Implemented checkbox widget draw function --- src/widget.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/widget.c b/src/widget.c index c476beed44..c2d386e705 100644 --- a/src/widget.c +++ b/src/widget.c @@ -37,6 +37,7 @@ static void widget_text_inset(rct_drawpixelinfo *dpi, rct_window *w, int widgetI static void widget_text_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_groupbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_caption_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); +static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_scroll_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex); static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, int l, int t, int r, int b, int colour); @@ -154,6 +155,8 @@ void widget_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex) widget_scroll_draw(dpi, w, widgetIndex); break; case WWT_CHECKBOX: + widget_checkbox_draw(dpi, w, widgetIndex); + break; case WWT_24: break; case WWT_25: @@ -711,6 +714,46 @@ static void widget_closebox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widg gfx_draw_string_centred_clipped(dpi, widget->image, (void*)0x013CE952, colour, l, t, widget->right - widget->left - 2); } +/** +* +* rct2: 0x006EBAD9 +*/ +static void widget_checkbox_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetIndex) +{ + rct_widget* widget; + int l, t, b; + uint8 colour; + + // Get the widget + widget = &w->widgets[widgetIndex]; + + // Resolve the absolute ltb + l = w->x + widget->left; + t = w->y + widget->top; + b = w->y + widget->bottom; + + // Get the colour + colour = w->colours[widget->colour]; + + // checkbox + gfx_fill_rect_inset(dpi, l, t, l + 9, b - 1, colour, 0x60); + + // fill it when checkbox is pressed + if (widget_is_pressed(w, widgetIndex)) { + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; + gfx_draw_string(dpi, (char*)0x009DED72, colour & 0x7F, l, t); + } + + // draw the text + if (widget->image == -1) + return; + + if (widget_is_disabled(w, widgetIndex)) { + colour |= 0x40; + } + gfx_draw_string_left(dpi, widget->image, (char*)0x013CE952, colour, l + 14, t); +} + /** * * rct2: 0x006EBD96 From 705af9377b19c234c2405f0d4d897647919c716e Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 13:06:28 +0200 Subject: [PATCH 2/8] Start decompiling gfx_fill_rect Section starting 0x00678C83 complete and works, but needs better comments/names --- src/gfx.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 3 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 8f663827f5..cf534af2f7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -119,14 +119,177 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c * rct2: 0x00678AD4 * dpi (edi) * left (ax) - * top (cx) + * top (cx) ? * right (bx) - * bottom (dx) + * bottom (dx) ? * colour (ebp) */ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) { - RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); + + int left_, right_, top_, bottom_; + rct_drawpixelinfo* dpi_; + left_ = left; + right_ = right; + top_ = top; + bottom_ = bottom; + dpi_ = dpi; + + if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || + (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) + return; + + colour |= RCT2_GLOBAL(0x009ABD9C, uint32); + + if (!(colour & 0x1000000)) { + if (!(colour & 0x8000000)) { + left_ = left - dpi->x; + if (left_ < 0) + left_ = 0; + + right_ = right - dpi->x; + right_++; + if (right_ > dpi->width) + right_ = dpi->width; + + right_ -= left_; + + top_ = top - dpi->y; + if (top_ < 0) + top_ = 0; + + bottom_ = bottom - dpi->y; + bottom_++; + + if (bottom_ > dpi->height) + bottom_ = dpi->height; + + bottom_ -= top_; + + if (!(colour & 0x2000000)) { + if (!(colour & 0x4000000)) { + char* edi; + edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + + // Take the last byte of colour and repeat it 4 times? + uint32 ax; + ax = colour & 0xffff; + ax = (ax & 0xff) << 8; + ax = ax << 8; + ax = (ax & 0xff00) >> 8; + ax = ax << 8; + ax = (ax & 0xff00) >> 8; + + int length; + length = dpi->width + dpi->pitch - right_; + + for (int dx = bottom_; dx > 0; --dx) { + uint32 ecx; + ecx = right_; + ecx = ecx/2; + if (ecx % 2 != 0) { + *edi = ax & 0xff; + edi++; + } + ecx = ecx/2; + if (ecx % 2 != 0) { + *edi = ax & 0xffff; + edi += 2; + } + memset(edi, ax, ecx); + + edi += length; + + } + return; + + } else { + // 00678B8A 00678E38 + char* esi; + esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; + + int eax, ebp; + eax = colour; + ebp = dpi->width + dpi->pitch - right_; + + RCT2_GLOBAL(0x00EDF810, uint32) = ebp; + RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; + RCT2_GLOBAL(0x00EDF814, uint32) = right_; + + top_ = (top + dpi_->y) & 0xf; + right_ = (right + dpi_->x) &0xf; + + dpi_ = esi; + + esi = eax >> 0x1C; + esi = RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? + + for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { + // push ebx + // push ecx + ebp = *(esi + top_*2); + + // mov bp, [esi+top_*2]; + int ecx; + ecx = RCT2_GLOBAL(0x00EDF814, uint32); + + for (int i = ecx; i >=0; --i) { + if (!(ebp & (1 << right_))) + dpi_->bits = left_ & 0xFF; + + right_++; + right_ = right_ & 0xF; + dpi_++; + } + // pop ecx + // pop ebx + top_++; + top_ = top_ &0xf; + dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); + } + return; + } + + } else { + // 00678B7E 00678C83 + if (dpi_->pad_0E < 1) { + // Location in screen buffer? + uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; + + // Find colour in colour table? + uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + + int length = (dpi_->width + dpi_->pitch) - right_; + + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < bottom_; ++i) { + uint8 al; + al = 0; + for (int j = 0; j < right_; ++j) { + al = *edi; + *edi = *((uint8*)(&g1_element->offset[al])); + edi++; + } + edi += length; + } + } else if (dpi_->pad_0E > 1) { + // 00678C8A 00678D57 + } else if (dpi_->pad_0E == 1) { + // 00678C88 00678CEE + + } + + } + } else { + // 00678B3A 00678EC9 + + } + } else { + // 00678B2E 00678BE5 + } + + // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } /** From 6f1421117be088eb7571b9044297aca0b10cc50c Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 15:56:59 +0200 Subject: [PATCH 3/8] Some tidying up. Scrollbars don't work --- src/gfx.c | 56 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index cf534af2f7..3354d45c07 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -168,41 +168,34 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot if (!(colour & 0x2000000)) { if (!(colour & 0x4000000)) { - char* edi; + uint8* edi; edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - // Take the last byte of colour and repeat it 4 times? - uint32 ax; - ax = colour & 0xffff; - ax = (ax & 0xff) << 8; - ax = ax << 8; - ax = (ax & 0xff00) >> 8; - ax = ax << 8; - ax = (ax & 0xff00) >> 8; + uint8 col = colour & 0xFF; int length; length = dpi->width + dpi->pitch - right_; - for (int dx = bottom_; dx > 0; --dx) { - uint32 ecx; - ecx = right_; - ecx = ecx/2; - if (ecx % 2 != 0) { - *edi = ax & 0xff; - edi++; - } - ecx = ecx/2; - if (ecx % 2 != 0) { - *edi = ax & 0xffff; - edi += 2; - } - memset(edi, ax, ecx); - - edi += length; - - } - return; - + for (int i = 0; i < bottom_; ++i) { + uint32 ecx; + ecx = right_; + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + } + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + *edi = col; + edi++; + // *((uint16*)edi) = ax & 0xffff; + // edi += 2; + } + memset(edi, col, ecx*4); + edi += length; + } } else { // 00678B8A 00678E38 char* esi; @@ -264,11 +257,8 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot // Fill the rectangle with the colours from the colour table for (int i = 0; i < bottom_; ++i) { - uint8 al; - al = 0; for (int j = 0; j < right_; ++j) { - al = *edi; - *edi = *((uint8*)(&g1_element->offset[al])); + *edi = *((uint8*)(&g1_element->offset[*edi])); edi++; } edi += length; From ce0df832988354cbf00365f4d702374c22646aa8 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 17:48:33 +0200 Subject: [PATCH 4/8] Formatting --- src/gfx.c | 243 +++++++++++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 121 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 3354d45c07..b5bd3c67ad 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -127,157 +127,158 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) { - int left_, right_, top_, bottom_; - rct_drawpixelinfo* dpi_; - left_ = left; - right_ = right; - top_ = top; - bottom_ = bottom; - dpi_ = dpi; + int left_, right_, top_, bottom_; + rct_drawpixelinfo* dpi_; + left_ = left; + right_ = right; + top_ = top; + bottom_ = bottom; + dpi_ = dpi; - if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || - (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) - return; + if ((left > right) || (top > bottom) || (dpi->x > right) || (left >= (dpi->x + dpi->width)) || + (bottom < dpi->y) || (top >= (dpi->y + dpi->height))) + return; - colour |= RCT2_GLOBAL(0x009ABD9C, uint32); + colour |= RCT2_GLOBAL(0x009ABD9C, uint32); - if (!(colour & 0x1000000)) { - if (!(colour & 0x8000000)) { - left_ = left - dpi->x; - if (left_ < 0) - left_ = 0; + if (!(colour & 0x1000000)) { + if (!(colour & 0x8000000)) { + left_ = left - dpi->x; + if (left_ < 0) + left_ = 0; - right_ = right - dpi->x; - right_++; - if (right_ > dpi->width) - right_ = dpi->width; + right_ = right - dpi->x; + right_++; + if (right_ > dpi->width) + right_ = dpi->width; - right_ -= left_; + right_ -= left_; - top_ = top - dpi->y; - if (top_ < 0) - top_ = 0; + top_ = top - dpi->y; + if (top_ < 0) + top_ = 0; - bottom_ = bottom - dpi->y; - bottom_++; + bottom_ = bottom - dpi->y; + bottom_++; - if (bottom_ > dpi->height) - bottom_ = dpi->height; + if (bottom_ > dpi->height) + bottom_ = dpi->height; - bottom_ -= top_; + bottom_ -= top_; - if (!(colour & 0x2000000)) { - if (!(colour & 0x4000000)) { - uint8* edi; - edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + if (!(colour & 0x2000000)) { + if (!(colour & 0x4000000)) { + uint8* edi; + edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - uint8 col = colour & 0xFF; + uint8 col = colour & 0xFF; - int length; - length = dpi->width + dpi->pitch - right_; + int length; + length = dpi->width + dpi->pitch - right_; - for (int i = 0; i < bottom_; ++i) { - uint32 ecx; - ecx = right_; - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - } - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - *edi = col; - edi++; - // *((uint16*)edi) = ax & 0xffff; - // edi += 2; - } - memset(edi, col, ecx*4); - edi += length; - } - } else { - // 00678B8A 00678E38 - char* esi; - esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; + for (int i = 0; i < bottom_; ++i) { + uint32 ecx; + ecx = right_; + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + } + ecx = ecx / 2; + if (ecx % 2 != 0) { + *edi = col; + edi++; + *edi = col; + edi++; + // *((uint16*)edi) = ax & 0xffff; + // edi += 2; + } + memset(edi, col, ecx*4); + edi += length; + } + } else { + // 00678B8A 00678E38 + char* esi; + esi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits;; - int eax, ebp; - eax = colour; - ebp = dpi->width + dpi->pitch - right_; + int eax, ebp; + eax = colour; + ebp = dpi->width + dpi->pitch - right_; - RCT2_GLOBAL(0x00EDF810, uint32) = ebp; - RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; - RCT2_GLOBAL(0x00EDF814, uint32) = right_; + RCT2_GLOBAL(0x00EDF810, uint32) = ebp; + RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; + RCT2_GLOBAL(0x00EDF814, uint32) = right_; - top_ = (top + dpi_->y) & 0xf; - right_ = (right + dpi_->x) &0xf; + top_ = (top + dpi_->y) & 0xf; + right_ = (right + dpi_->x) &0xf; - dpi_ = esi; + dpi_ = esi; - esi = eax >> 0x1C; - esi = RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? + esi = eax >> 0x1C; + esi = RCT2_GLOBAL(0x0097FEFC,uint32)[esi]; // or possibly uint8)[esi*4] ? - for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { - // push ebx - // push ecx - ebp = *(esi + top_*2); + for (; RCT2_GLOBAL(0x009ABDB2, uint16) > 0; RCT2_GLOBAL(0x009ABDB2, uint16)--) { + // push ebx + // push ecx + ebp = *(esi + top_*2); - // mov bp, [esi+top_*2]; - int ecx; - ecx = RCT2_GLOBAL(0x00EDF814, uint32); + // mov bp, [esi+top_*2]; + int ecx; + ecx = RCT2_GLOBAL(0x00EDF814, uint32); - for (int i = ecx; i >=0; --i) { - if (!(ebp & (1 << right_))) - dpi_->bits = left_ & 0xFF; + for (int i = ecx; i >=0; --i) { + if (!(ebp & (1 << right_))) + dpi_->bits = left_ & 0xFF; - right_++; - right_ = right_ & 0xF; - dpi_++; - } - // pop ecx - // pop ebx - top_++; - top_ = top_ &0xf; - dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); - } - return; - } + right_++; + right_ = right_ & 0xF; + dpi_++; + } + // pop ecx + // pop ebx + top_++; + top_ = top_ &0xf; + dpi_ += RCT2_GLOBAL(0x00EDF810, uint32); + } + return; + } - } else { - // 00678B7E 00678C83 - if (dpi_->pad_0E < 1) { - // Location in screen buffer? - uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; + } else { + // 00678B7E 00678C83 + if (dpi_->pad_0E < 1) { + // Location in screen buffer? + uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; - // Find colour in colour table? - uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; - rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); + // Find colour in colour table? + uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; + rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); - int length = (dpi_->width + dpi_->pitch) - right_; + int length = (dpi_->width + dpi_->pitch) - right_; - // Fill the rectangle with the colours from the colour table - for (int i = 0; i < bottom_; ++i) { - for (int j = 0; j < right_; ++j) { - *edi = *((uint8*)(&g1_element->offset[*edi])); - edi++; - } - edi += length; - } - } else if (dpi_->pad_0E > 1) { - // 00678C8A 00678D57 - } else if (dpi_->pad_0E == 1) { - // 00678C88 00678CEE - - } + // Fill the rectangle with the colours from the colour table + for (int i = 0; i < bottom_; ++i) { + for (int j = 0; j < right_; ++j) { + *edi = *((uint8*)(&g1_element->offset[*edi])); + edi++; + } + edi += length; + } + } else if (dpi_->pad_0E > 1) { + // 00678C8A 00678D57 + right_ = right; + } else if (dpi_->pad_0E == 1) { + // 00678C88 00678CEE + right = right; + } - } - } else { - // 00678B3A 00678EC9 - + } + } else { + // 00678B3A 00678EC9 + right_ = right; } } else { // 00678B2E 00678BE5 - } + } // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); } From ba6263d2bd46dd8a6885190fa5afbb84adb24635 Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 17:49:13 +0200 Subject: [PATCH 5/8] Cross-hatching branch --- src/gfx.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/gfx.c b/src/gfx.c index b5bd3c67ad..feec6685af 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -278,6 +278,63 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } } else { // 00678B2E 00678BE5 + // Cross hatching + uint16 si; + si = 0; + + left_ = left_ - dpi->x; + if (left_ < 0) { + si = si ^ left_; + left_ = 0; + } + + right_ = right_ - dpi->x; + right_++; + + if (right_ > dpi->width) + right_ = dpi-> width; + + right_ = right_ - left_; + + top_ = top - dpi->y; + if (top_ < 0) { + si = si ^ top_; + top_ = 0; + } + + bottom_ = bottom - dpi->y; + bottom_++; + + if (bottom_ > dpi->height) + bottom_ = dpi->height; + + bottom_ -= top_; + + uint8* edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + + uint8 col = colour & 0xFF; + + int length = dpi->width + dpi->pitch - right_; + + for (int i = 0; i < bottom_; ++i) { + uint32 ecx; + ecx = si; + // Rotate right + ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); + ecx = (ecx & 0xFFFF0000) | right_; + + while (ecx > 0 && ecx != 0xFFFFFFFF) { + ecx = ecx ^ 0x80000000; + if ((int)ecx < 0) { + *edi = col; + } + edi++; + ecx--; + } + si = si ^ 1; + edi += length; + + } } // RCT2_CALLPROC_X(0x00678AD4, left, right, top, bottom, 0, dpi, colour); From 1e8f80fa5c439a3a0c8f44cf88e59b346007645a Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 18:41:18 +0200 Subject: [PATCH 6/8] Bug fix - memset doesn't increase pointer --- src/gfx.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index feec6685af..57b91881c9 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -177,24 +177,8 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot length = dpi->width + dpi->pitch - right_; for (int i = 0; i < bottom_; ++i) { - uint32 ecx; - ecx = right_; - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - } - ecx = ecx / 2; - if (ecx % 2 != 0) { - *edi = col; - edi++; - *edi = col; - edi++; - // *((uint16*)edi) = ax & 0xffff; - // edi += 2; - } - memset(edi, col, ecx*4); - edi += length; + memset(edi, col, right_); + edi += length + right_; } } else { // 00678B8A 00678E38 From 7f4e21f334c467c55a947856c94963e6c7b8109f Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 21:31:31 +0200 Subject: [PATCH 7/8] Bug fix: cross-hatch loop was wrong Also rename and tidy up a bunch of variables --- src/gfx.c | 57 +++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 57b91881c9..ce6aaac213 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -168,17 +168,13 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot if (!(colour & 0x2000000)) { if (!(colour & 0x4000000)) { - uint8* edi; - edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; + uint8* pixel = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - uint8 col = colour & 0xFF; - - int length; - length = dpi->width + dpi->pitch - right_; + int length = dpi->width + dpi->pitch - right_; for (int i = 0; i < bottom_; ++i) { - memset(edi, col, right_); - edi += length + right_; + memset(pixel, (colour & 0xFF), right_); + pixel += length + right_; } } else { // 00678B8A 00678E38 @@ -193,7 +189,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot RCT2_GLOBAL(0x009ABDB2, uint16) = bottom_; RCT2_GLOBAL(0x00EDF814, uint32) = right_; - top_ = (top + dpi_->y) & 0xf; + top_ = (top + dpi->y) & 0xf; right_ = (right + dpi_->x) &0xf; dpi_ = esi; @@ -229,28 +225,28 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } else { // 00678B7E 00678C83 - if (dpi_->pad_0E < 1) { + if (dpi->pad_0E < 1) { // Location in screen buffer? - uint8* edi = top_ * (dpi_->width + dpi_->pitch) + left_ + dpi_->bits; + uint8* pixel = top_ * (dpi->width + dpi->pitch) + left_ + dpi->bits; // Find colour in colour table? uint32 eax = RCT2_ADDRESS(0x0097FCBC, uint32)[(colour & 0xFF)]; rct_g1_element* g1_element = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[eax]); - int length = (dpi_->width + dpi_->pitch) - right_; + int length = (dpi->width + dpi->pitch) - right_; // Fill the rectangle with the colours from the colour table for (int i = 0; i < bottom_; ++i) { for (int j = 0; j < right_; ++j) { - *edi = *((uint8*)(&g1_element->offset[*edi])); - edi++; + *pixel = *((uint8*)(&g1_element->offset[*pixel])); + pixel++; } - edi += length; + pixel += length; } - } else if (dpi_->pad_0E > 1) { + } else if (dpi->pad_0E > 1) { // 00678C8A 00678D57 right_ = right; - } else if (dpi_->pad_0E == 1) { + } else if (dpi->pad_0E == 1) { // 00678C88 00678CEE right = right; } @@ -263,12 +259,11 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot } else { // 00678B2E 00678BE5 // Cross hatching - uint16 si; - si = 0; + uint16 pattern = 0; left_ = left_ - dpi->x; if (left_ < 0) { - si = si ^ left_; + pattern = pattern ^ left_; left_ = 0; } @@ -282,7 +277,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot top_ = top - dpi->y; if (top_ < 0) { - si = si ^ top_; + pattern = pattern ^ top_; top_ = 0; } @@ -294,29 +289,25 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot bottom_ -= top_; - uint8* edi = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; - - uint8 col = colour & 0xFF; + uint8* pixel = (top_ * (dpi->width + dpi->pitch)) + left_ + dpi->bits; int length = dpi->width + dpi->pitch - right_; for (int i = 0; i < bottom_; ++i) { - uint32 ecx; - ecx = si; + uint32 ecx = pattern; // Rotate right ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); ecx = (ecx & 0xFFFF0000) | right_; - - while (ecx > 0 && ecx != 0xFFFFFFFF) { + // Fill every other pixel with the colour + for (; (ecx & 0xFFFF) > 0; ecx--) { ecx = ecx ^ 0x80000000; if ((int)ecx < 0) { - *edi = col; + *pixel = colour & 0xFF; } - edi++; - ecx--; + pixel++; } - si = si ^ 1; - edi += length; + pattern = pattern ^ 1; + pixel += length; } } From ea83381e4cfe282a991d74830a289fb7ef231e2d Mon Sep 17 00:00:00 2001 From: ZedThree Date: Sun, 11 May 2014 22:19:01 +0200 Subject: [PATCH 8/8] Add author --- src/gfx.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index ce6aaac213..e4c229c955 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Ted John + * Copyright (c) 2014 Ted John, Peter Hill * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. @@ -119,9 +119,9 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c * rct2: 0x00678AD4 * dpi (edi) * left (ax) - * top (cx) ? + * top (cx) * right (bx) - * bottom (dx) ? + * bottom (dx) * colour (ebp) */ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour) @@ -293,8 +293,9 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot int length = dpi->width + dpi->pitch - right_; + uint32 ecx; for (int i = 0; i < bottom_; ++i) { - uint32 ecx = pattern; + ecx = pattern; // Rotate right ecx = (ecx >> 1) | (ecx << (sizeof(ecx) * CHAR_BIT - 1)); ecx = (ecx & 0xFFFF0000) | right_;