1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 15:23:01 +01:00

Move Widget.cpp to libopenrct2ui

This commit is contained in:
Ted John
2018-06-11 00:04:41 +01:00
parent a4d6a45e78
commit 04da3be824
4 changed files with 179 additions and 182 deletions

View File

@@ -16,15 +16,14 @@
#include <algorithm>
#include <cmath>
#include "../drawing/Drawing.h"
#include "../Input.h"
#include "../sprites.h"
#include "../localisation/Localisation.h"
#include "../util/Util.h"
#include "../Context.h"
#include <openrct2/Context.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/Input.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include "Widget.h"
#include "Window.h"
#include "Window_internal.h"
static void widget_frame_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
static void widget_resize_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
@@ -45,71 +44,6 @@ static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, s
static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, sint32 l, sint32 t, sint32 r, sint32 b, sint32 colour);
static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex);
/**
*
* rct2: 0x006EAF26
*/
void widget_scroll_update_thumbs(rct_window *w, rct_widgetindex widget_index)
{
rct_widget *widget = &w->widgets[widget_index];
rct_scroll* scroll = &w->scrolls[window_get_scroll_data_index(w, widget_index)];
if (scroll->flags & HSCROLLBAR_VISIBLE) {
sint32 view_size = widget->right - widget->left - 21;
if (scroll->flags & VSCROLLBAR_VISIBLE)
view_size -= 11;
sint32 x = scroll->h_left * view_size;
if (scroll->h_right != 0)
x /= scroll->h_right;
scroll->h_thumb_left = x + 11;
x = widget->right - widget->left - 2;
if (scroll->flags & VSCROLLBAR_VISIBLE)
x -= 11;
x += scroll->h_left;
if (scroll->h_right != 0)
x = (x * view_size) / scroll->h_right;
x += 11;
view_size += 10;
scroll->h_thumb_right = std::min(x, view_size);
if(scroll->h_thumb_right - scroll->h_thumb_left < 20) {
double barPosition = (scroll->h_thumb_right * 1.0) / view_size;
scroll->h_thumb_left = (uint16)std::lround(scroll->h_thumb_left - (20 * barPosition));
scroll->h_thumb_right = (uint16)std::lround(scroll->h_thumb_right + (20 * (1 - barPosition)));
}
}
if (scroll->flags & VSCROLLBAR_VISIBLE) {
sint32 view_size = widget->bottom - widget->top - 21;
if (scroll->flags & HSCROLLBAR_VISIBLE)
view_size -= 11;
sint32 y = scroll->v_top * view_size;
if (scroll->v_bottom != 0)
y /= scroll->v_bottom;
scroll->v_thumb_top = y + 11;
y = widget->bottom - widget->top - 2;
if (scroll->flags & HSCROLLBAR_VISIBLE)
y -= 11;
y += scroll->v_top;
if (scroll->v_bottom != 0)
y = (y * view_size) / scroll->v_bottom;
y += 11;
view_size += 10;
scroll->v_thumb_bottom = std::min(y, view_size);
if(scroll->v_thumb_bottom - scroll->v_thumb_top < 20) {
double barPosition = (scroll->v_thumb_bottom * 1.0) / view_size;
scroll->v_thumb_top = (uint16)std::lround(scroll->v_thumb_top - (20 * barPosition));
scroll->v_thumb_bottom = (uint16)std::lround(scroll->v_thumb_bottom + (20 * (1 - barPosition)));
}
}
}
/**
*
* rct2: 0x006EB2A8

View File

@@ -515,3 +515,112 @@ void window_all_wheel_input()
}
}
}
/**
* Initialises scroll widgets to their virtual size.
* rct2: 0x006EAEB8
*
* @param window The window (esi).
*/
void window_init_scroll_widgets(rct_window *w)
{
rct_widget* widget;
rct_scroll* scroll;
sint32 widget_index, scroll_index;
sint32 width, height;
widget_index = 0;
scroll_index = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) {
if (widget->type != WWT_SCROLL) {
widget_index++;
continue;
}
scroll = &w->scrolls[scroll_index];
scroll->flags = 0;
width = 0;
height = 0;
window_get_scroll_size(w, scroll_index, &width, &height);
scroll->h_left = 0;
scroll->h_right = width + 1;
scroll->v_top = 0;
scroll->v_bottom = height + 1;
if (widget->content & SCROLL_HORIZONTAL)
scroll->flags |= HSCROLLBAR_VISIBLE;
if (widget->content & SCROLL_VERTICAL)
scroll->flags |= VSCROLLBAR_VISIBLE;
widget_scroll_update_thumbs(w, widget_index);
widget_index++;
scroll_index++;
}
}
/**
*
* rct2: 0x006EB15C
*
* @param window (esi)
* @param dpi (edi)
*/
void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi)
{
rct_widget *widget;
rct_widgetindex widgetIndex;
if ((w->flags & WF_TRANSPARENT) && !(w->flags & WF_NO_BACKGROUND))
gfx_filter_rect(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, PALETTE_51);
//todo: some code missing here? Between 006EB18C and 006EB260
widgetIndex = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) {
// Check if widget is outside the draw region
if (w->x + widget->left < dpi->x + dpi->width && w->x + widget->right >= dpi->x)
if (w->y + widget->top < dpi->y + dpi->height && w->y + widget->bottom >= dpi->y)
widget_draw(dpi, w, widgetIndex);
widgetIndex++;
}
//todo: something missing here too? Between 006EC32B and 006EC369
if (w->flags & WF_WHITE_BORDER_MASK) {
gfx_fill_rect_inset(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, COLOUR_WHITE, INSET_RECT_FLAG_FILL_NONE);
}
}
/**
*
* rct2: 0x006EA776
*/
static void window_invalidate_pressed_image_buttons(rct_window *w)
{
rct_widgetindex widgetIndex;
rct_widget *widget;
widgetIndex = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++) {
if (widget->type != WWT_IMGBTN)
continue;
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
gfx_set_dirty_blocks(w->x, w->y, w->x + w->width, w->y + w->height);
}
}
/**
*
* rct2: 0x006EA73F
*/
void invalidate_all_windows_after_input()
{
for (rct_window *w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
window_update_scroll_widgets(w);
window_invalidate_pressed_image_buttons(w);
window_event_resize_call(w);
}
}

View File

@@ -28,7 +28,6 @@
#include "Input.h"
#include "interface/Screenshot.h"
#include "interface/Viewport.h"
#include "interface/Widget.h"
#include "interface/Window.h"
#include "localisation/Localisation.h"
#include "management/Finance.h"

View File

@@ -531,49 +531,6 @@ void widget_invalidate_by_number(rct_windowclass cls, rct_windownumber number, r
widget_invalidate(w, widgetIndex);
}
/**
* Initialises scroll widgets to their virtual size.
* rct2: 0x006EAEB8
*
* @param window The window (esi).
*/
void window_init_scroll_widgets(rct_window *w)
{
rct_widget* widget;
rct_scroll* scroll;
sint32 widget_index, scroll_index;
sint32 width, height;
widget_index = 0;
scroll_index = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) {
if (widget->type != WWT_SCROLL) {
widget_index++;
continue;
}
scroll = &w->scrolls[scroll_index];
scroll->flags = 0;
width = 0;
height = 0;
window_get_scroll_size(w, scroll_index, &width, &height);
scroll->h_left = 0;
scroll->h_right = width + 1;
scroll->v_top = 0;
scroll->v_bottom = height + 1;
if (widget->content & SCROLL_HORIZONTAL)
scroll->flags |= HSCROLLBAR_VISIBLE;
if (widget->content & SCROLL_VERTICAL)
scroll->flags |= VSCROLLBAR_VISIBLE;
widget_scroll_update_thumbs(w, widget_index);
widget_index++;
scroll_index++;
}
}
/**
*
* rct2: 0x006EAE4E
@@ -1231,40 +1188,6 @@ static void window_draw_single(rct_drawpixelinfo *dpi, rct_window *w, sint32 lef
window_event_paint_call(w, dpi);
}
/**
*
* rct2: 0x006EB15C
*
* @param window (esi)
* @param dpi (edi)
*/
void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi)
{
rct_widget *widget;
rct_widgetindex widgetIndex;
if ((w->flags & WF_TRANSPARENT) && !(w->flags & WF_NO_BACKGROUND))
gfx_filter_rect(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, PALETTE_51);
//todo: some code missing here? Between 006EB18C and 006EB260
widgetIndex = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++) {
// Check if widget is outside the draw region
if (w->x + widget->left < dpi->x + dpi->width && w->x + widget->right >= dpi->x)
if (w->y + widget->top < dpi->y + dpi->height && w->y + widget->bottom >= dpi->y)
widget_draw(dpi, w, widgetIndex);
widgetIndex++;
}
//todo: something missing here too? Between 006EC32B and 006EC369
if (w->flags & WF_WHITE_BORDER_MASK) {
gfx_fill_rect_inset(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, COLOUR_WHITE, INSET_RECT_FLAG_FILL_NONE);
}
}
/**
*
* rct2: 0x00685BE1
@@ -1749,38 +1672,6 @@ void window_close_construction_windows()
window_close_by_class(WC_TRACK_DESIGN_PLACE);
}
/**
*
* rct2: 0x006EA776
*/
static void window_invalidate_pressed_image_buttons(rct_window *w)
{
rct_widgetindex widgetIndex;
rct_widget *widget;
widgetIndex = 0;
for (widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++) {
if (widget->type != WWT_IMGBTN)
continue;
if (widget_is_pressed(w, widgetIndex) || widget_is_active_tool(w, widgetIndex))
gfx_set_dirty_blocks(w->x, w->y, w->x + w->width, w->y + w->height);
}
}
/**
*
* rct2: 0x006EA73F
*/
void invalidate_all_windows_after_input()
{
for (rct_window *w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
window_update_scroll_widgets(w);
window_invalidate_pressed_image_buttons(w);
window_event_resize_call(w);
}
}
/**
* Update zoom based volume attenuation for ride music and clear music list.
* rct2: 0x006BC348
@@ -2228,3 +2119,67 @@ rct_windowclass window_get_classification(rct_window * window)
return window->classification;
}
/**
*
* rct2: 0x006EAF26
*/
void widget_scroll_update_thumbs(rct_window *w, rct_widgetindex widget_index)
{
rct_widget *widget = &w->widgets[widget_index];
rct_scroll* scroll = &w->scrolls[window_get_scroll_data_index(w, widget_index)];
if (scroll->flags & HSCROLLBAR_VISIBLE) {
sint32 view_size = widget->right - widget->left - 21;
if (scroll->flags & VSCROLLBAR_VISIBLE)
view_size -= 11;
sint32 x = scroll->h_left * view_size;
if (scroll->h_right != 0)
x /= scroll->h_right;
scroll->h_thumb_left = x + 11;
x = widget->right - widget->left - 2;
if (scroll->flags & VSCROLLBAR_VISIBLE)
x -= 11;
x += scroll->h_left;
if (scroll->h_right != 0)
x = (x * view_size) / scroll->h_right;
x += 11;
view_size += 10;
scroll->h_thumb_right = std::min(x, view_size);
if(scroll->h_thumb_right - scroll->h_thumb_left < 20) {
double barPosition = (scroll->h_thumb_right * 1.0) / view_size;
scroll->h_thumb_left = (uint16)std::lround(scroll->h_thumb_left - (20 * barPosition));
scroll->h_thumb_right = (uint16)std::lround(scroll->h_thumb_right + (20 * (1 - barPosition)));
}
}
if (scroll->flags & VSCROLLBAR_VISIBLE) {
sint32 view_size = widget->bottom - widget->top - 21;
if (scroll->flags & HSCROLLBAR_VISIBLE)
view_size -= 11;
sint32 y = scroll->v_top * view_size;
if (scroll->v_bottom != 0)
y /= scroll->v_bottom;
scroll->v_thumb_top = y + 11;
y = widget->bottom - widget->top - 2;
if (scroll->flags & HSCROLLBAR_VISIBLE)
y -= 11;
y += scroll->v_top;
if (scroll->v_bottom != 0)
y = (y * view_size) / scroll->v_bottom;
y += 11;
view_size += 10;
scroll->v_thumb_bottom = std::min(y, view_size);
if(scroll->v_thumb_bottom - scroll->v_thumb_top < 20) {
double barPosition = (scroll->v_thumb_bottom * 1.0) / view_size;
scroll->v_thumb_top = (uint16)std::lround(scroll->v_thumb_top - (20 * barPosition));
scroll->v_thumb_bottom = (uint16)std::lround(scroll->v_thumb_bottom + (20 * (1 - barPosition)));
}
}
}