mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 07:14:31 +01:00
CppCheck fixes
This commit is contained in:
@@ -66,7 +66,7 @@ public:
|
||||
std::vector<UIThemeWindowEntry> Entries;
|
||||
uint8 Flags;
|
||||
|
||||
UITheme(const utf8 * name);
|
||||
explicit UITheme(const utf8 * name);
|
||||
UITheme(const UITheme & copy);
|
||||
~UITheme();
|
||||
|
||||
@@ -394,7 +394,7 @@ bool UITheme::WriteToFile(const utf8 * path) const
|
||||
Json::WriteToFile(path, jsonTheme, JSON_INDENT(4) | JSON_PRESERVE_ORDER);
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (const Exception & ex)
|
||||
{
|
||||
log_error("Unable to save %s: %s", path, ex.GetMessage());
|
||||
result = false;
|
||||
@@ -445,10 +445,10 @@ UITheme * UITheme::FromJson(const json_t * json)
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (const Exception &)
|
||||
{
|
||||
delete result;
|
||||
throw ex;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ UITheme * UITheme::FromFile(const utf8 * path)
|
||||
json = Json::ReadFromFile(path);
|
||||
result = UITheme::FromJson(json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (const Exception &)
|
||||
{
|
||||
log_error("Unable to read theme: %s", path);
|
||||
result = nullptr;
|
||||
|
||||
@@ -194,7 +194,7 @@ static void widget_frame_draw(rct_drawpixelinfo *dpi, rct_window *w, int widgetI
|
||||
int b = w->y + widget->bottom;
|
||||
|
||||
//
|
||||
uint8 press = (w->flags & WF_10 ? INSET_RECT_FLAG_FILL_MID_LIGHT : 0);
|
||||
uint8 press = ((w->flags & WF_10) ? INSET_RECT_FLAG_FILL_MID_LIGHT : 0);
|
||||
|
||||
// Get the colour
|
||||
uint8 colour = w->colours[widget->colour];
|
||||
@@ -730,11 +730,11 @@ static void widget_scroll_draw(rct_drawpixelinfo *dpi, rct_window *w, int widget
|
||||
|
||||
// Horizontal scrollbar
|
||||
if (scroll->flags & HSCROLLBAR_VISIBLE)
|
||||
widget_hscrollbar_draw(dpi, scroll, l, b - 10, (scroll->flags & VSCROLLBAR_VISIBLE ? r - 11 : r), b, colour);
|
||||
widget_hscrollbar_draw(dpi, scroll, l, b - 10, ((scroll->flags & VSCROLLBAR_VISIBLE) ? r - 11 : r), b, colour);
|
||||
|
||||
// Vertical scrollbar
|
||||
if (scroll->flags & VSCROLLBAR_VISIBLE)
|
||||
widget_vscrollbar_draw(dpi, scroll, r - 10, t, r, (scroll->flags & HSCROLLBAR_VISIBLE ? b - 11 : b), colour);
|
||||
widget_vscrollbar_draw(dpi, scroll, r - 10, t, r, ((scroll->flags & HSCROLLBAR_VISIBLE) ? b - 11 : b), colour);
|
||||
|
||||
// Contents
|
||||
if (scroll->flags & HSCROLLBAR_VISIBLE)
|
||||
@@ -780,17 +780,17 @@ static void widget_hscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
|
||||
gfx_fill_rect(dpi, l + 10, t + 8, r - 10, t + 8, ColourMapA[colour].lighter);
|
||||
|
||||
// Left button
|
||||
gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, (scroll->flags & HSCROLLBAR_LEFT_PRESSED ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, ((scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_draw_string(dpi, (char*)BlackLeftArrowString, COLOUR_BLACK, l + 1, t);
|
||||
|
||||
// Thumb
|
||||
gfx_fill_rect_inset(dpi,
|
||||
max(l + 10, l + scroll->h_thumb_left - 1), t,
|
||||
min(r - 10, l + scroll->h_thumb_right - 1), b,
|
||||
colour, (scroll->flags & HSCROLLBAR_THUMB_PRESSED ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
colour, ((scroll->flags & HSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
|
||||
// Right button
|
||||
gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, (scroll->flags & HSCROLLBAR_RIGHT_PRESSED ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, ((scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_draw_string(dpi, (char*)BlackRightArrowString, COLOUR_BLACK, r - 6, t);
|
||||
}
|
||||
|
||||
@@ -806,17 +806,17 @@ static void widget_vscrollbar_draw(rct_drawpixelinfo *dpi, rct_scroll *scroll, i
|
||||
gfx_fill_rect(dpi, l + 8, t + 10, l + 8, b - 10, ColourMapA[colour].lighter);
|
||||
|
||||
// Up button
|
||||
gfx_fill_rect_inset(dpi, l, t, r, t + 9, colour, (scroll->flags & VSCROLLBAR_UP_PRESSED ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_fill_rect_inset(dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1);
|
||||
|
||||
// Thumb
|
||||
gfx_fill_rect_inset(dpi,
|
||||
l, max(t + 10, t + scroll->v_thumb_top - 1),
|
||||
r, min(b - 10, t + scroll->v_thumb_bottom - 1),
|
||||
colour, (scroll->flags & VSCROLLBAR_THUMB_PRESSED ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
colour, ((scroll->flags & VSCROLLBAR_THUMB_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
|
||||
// Down button
|
||||
gfx_fill_rect_inset(dpi, l, b - 9, r, b, colour, (scroll->flags & VSCROLLBAR_DOWN_PRESSED ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_fill_rect_inset(dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0));
|
||||
gfx_draw_string(dpi, (char*)BlackDownArrowString, COLOUR_BLACK, l + 1, b - 9);
|
||||
}
|
||||
|
||||
@@ -943,13 +943,13 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int x, int y, int
|
||||
{
|
||||
//horizon scrollbar
|
||||
int rightOffset = 0;
|
||||
int iteratorLeft = widget->left + w->x;
|
||||
int iteratorRight = widget->right + w->x;
|
||||
int iteratorLeft = widget->left + w->x + 10;
|
||||
int iteratorRight = widget->right + w->x - 10;
|
||||
if (w->scrolls[*scroll_id].flags & VSCROLLBAR_VISIBLE)
|
||||
{
|
||||
rightOffset = 11;
|
||||
}
|
||||
if (x <= (iteratorLeft += 10))
|
||||
if (x <= iteratorLeft)
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT;
|
||||
}
|
||||
@@ -957,7 +957,7 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int x, int y, int
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_NONE;
|
||||
}
|
||||
else if (x >= (iteratorRight -= 10))
|
||||
else if (x >= iteratorRight)
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT;
|
||||
}
|
||||
@@ -978,21 +978,21 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int x, int y, int
|
||||
{
|
||||
//vertical scrollbar
|
||||
int bottomOffset = 0;
|
||||
int iteratorTop = widget->top + w->y;
|
||||
int iteratorTop = widget->top + w->y + 10;
|
||||
int iteratorBottom = widget->bottom + w->y;
|
||||
if (w->scrolls[*scroll_id].flags & HSCROLLBAR_VISIBLE)
|
||||
{
|
||||
bottomOffset = 11;
|
||||
}
|
||||
if (y <= (iteratorTop += 10))
|
||||
if (y <= iteratorTop)
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP;
|
||||
}
|
||||
else if (y >= (iteratorBottom -= bottomOffset))
|
||||
else if (y >= (iteratorBottom - bottomOffset))
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_NONE;
|
||||
}
|
||||
else if (y >= (iteratorBottom -= 10))
|
||||
else if (y >= (iteratorBottom - 10))
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM;
|
||||
}
|
||||
@@ -1017,14 +1017,14 @@ void widget_scroll_get_part(rct_window *w, rct_widget *widget, int x, int y, int
|
||||
*output_y = y - widget->top;
|
||||
*output_x -= w->x;
|
||||
*output_y -= w->y;
|
||||
if (--*output_x < 0 || --*output_y < 0)
|
||||
if (*output_x <= 0 || *output_y <= 0)
|
||||
{
|
||||
*output_scroll_area = SCROLL_PART_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*output_x += w->scrolls[*scroll_id].h_left;
|
||||
*output_y += w->scrolls[*scroll_id].v_top;
|
||||
*output_x += w->scrolls[*scroll_id].h_left - 1;
|
||||
*output_y += w->scrolls[*scroll_id].v_top - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -735,10 +735,12 @@ void window_close(rct_window* window)
|
||||
*/
|
||||
void window_close_by_class(rct_windowclass cls)
|
||||
{
|
||||
for (rct_window *w = g_window_list; w < RCT2_NEW_WINDOW; w++) {
|
||||
for (rct_window *w = g_window_list; w < RCT2_NEW_WINDOW;) {
|
||||
if (w->classification == cls) {
|
||||
window_close(w);
|
||||
w = g_window_list - 1;
|
||||
w = g_window_list;
|
||||
} else {
|
||||
w++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -751,10 +753,12 @@ void window_close_by_class(rct_windowclass cls)
|
||||
*/
|
||||
void window_close_by_number(rct_windowclass cls, rct_windownumber number)
|
||||
{
|
||||
for (rct_window* w = g_window_list; w < RCT2_NEW_WINDOW; w++) {
|
||||
for (rct_window* w = g_window_list; w < RCT2_NEW_WINDOW;) {
|
||||
if (w->classification == cls && w->number == number) {
|
||||
window_close(w);
|
||||
w = g_window_list - 1;
|
||||
w = g_window_list;
|
||||
} else {
|
||||
w++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -883,16 +887,13 @@ rct_window *window_find_from_point(int x, int y)
|
||||
*/
|
||||
int window_find_widget_from_point(rct_window *w, int x, int y)
|
||||
{
|
||||
rct_widget *widget;
|
||||
int i, widget_index;
|
||||
|
||||
// Invalidate the window
|
||||
window_event_invalidate_call(w);
|
||||
|
||||
// Find the widget at point x, y
|
||||
widget_index = -1;
|
||||
for (i = 0;; i++) {
|
||||
widget = &w->widgets[i];
|
||||
int widget_index = -1;
|
||||
for (int i = 0;; i++) {
|
||||
rct_widget *widget = &w->widgets[i];
|
||||
if (widget->type == WWT_LAST) {
|
||||
break;
|
||||
} else if (widget->type != WWT_EMPTY) {
|
||||
@@ -1129,19 +1130,17 @@ int window_get_scroll_data_index(rct_window *w, int widget_index)
|
||||
*/
|
||||
rct_window *window_bring_to_front(rct_window *w)
|
||||
{
|
||||
int i;
|
||||
rct_window* v, t;
|
||||
|
||||
if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))
|
||||
return w;
|
||||
|
||||
rct_window *v;
|
||||
for (v = RCT2_LAST_WINDOW; v >= g_window_list; v--)
|
||||
if (!(v->flags & WF_STICK_TO_FRONT))
|
||||
break;
|
||||
|
||||
if (v >= g_window_list && w != v) {
|
||||
do {
|
||||
t = *w;
|
||||
rct_window t = *w;
|
||||
*w = *(w + 1);
|
||||
*(w + 1) = t;
|
||||
w++;
|
||||
@@ -1151,7 +1150,7 @@ rct_window *window_bring_to_front(rct_window *w)
|
||||
}
|
||||
|
||||
if (w->x + w->width < 20) {
|
||||
i = 20 - w->x;
|
||||
int i = 20 - w->x;
|
||||
w->x += i;
|
||||
if (w->viewport != NULL)
|
||||
w->viewport->x += i;
|
||||
@@ -1843,8 +1842,6 @@ int tool_set(rct_window *w, int widgetIndex, int tool)
|
||||
*/
|
||||
void tool_cancel()
|
||||
{
|
||||
rct_window *w;
|
||||
|
||||
if (gInputFlags & INPUT_FLAG_TOOL_ACTIVE) {
|
||||
gInputFlags &= ~INPUT_FLAG_TOOL_ACTIVE;
|
||||
|
||||
@@ -1863,7 +1860,7 @@ void tool_cancel()
|
||||
);
|
||||
|
||||
// Abort tool event
|
||||
w = window_find_by_number(
|
||||
rct_window *w = window_find_by_number(
|
||||
gCurrentToolWidget.window_classification,
|
||||
gCurrentToolWidget.window_number
|
||||
);
|
||||
@@ -2518,12 +2515,14 @@ void window_update_textbox()
|
||||
bool window_is_visible(rct_window* w)
|
||||
{
|
||||
// w->visibility is used to prevent repeat calculations within an iteration by caching the result
|
||||
if (w == NULL)
|
||||
return false;
|
||||
|
||||
if (w->visibility == VC_VISIBLE) return true;
|
||||
if (w->visibility == VC_COVERED) return false;
|
||||
|
||||
// only consider viewports, consider the main window always visible
|
||||
if (w == NULL || w->viewport == NULL || w->classification == WC_MAIN_WINDOW)
|
||||
if (w->viewport == NULL || w->classification == WC_MAIN_WINDOW)
|
||||
{
|
||||
// default to previous behaviour
|
||||
w->visibility = VC_VISIBLE;
|
||||
|
||||
Reference in New Issue
Block a user