Esempio n. 1
0
// This method is the same as gfx_draw_string_left_wrapped.
// But this adjusts the initial Y coordinate depending of the number of lines.
int32_t chat_history_draw_string(rct_drawpixelinfo* dpi, void* args, int32_t x, int32_t y, int32_t width)
{
    int32_t fontSpriteBase, lineHeight, lineY, numLines;

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;

    gfx_draw_string(dpi, (char*)"", TEXT_COLOUR_255, dpi->x, dpi->y);
    char* buffer = gCommonStringFormatBuffer;
    format_string(buffer, 256, STR_STRING, args);

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
    gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase);
    lineHeight = font_get_line_height(fontSpriteBase);

    gCurrentFontFlags = 0;

    int32_t expectedY = y - (numLines * lineHeight);
    if (expectedY < 50)
    {
        return (numLines * lineHeight); // Skip drawing, return total height.
    }

    lineY = y;
    for (int32_t line = 0; line <= numLines; ++line)
    {
        gfx_draw_string(dpi, buffer, TEXT_COLOUR_254, x, lineY - (numLines * lineHeight));
        buffer = get_string_end(buffer) + 1;
        lineY += lineHeight;
    }
    return lineY - y;
}
Esempio n. 2
0
void window_tooltip_show(rct_string_id id, int x, int y)
{
	rct_window *w;
	int width, height;

	w = window_find_by_class(WC_ERROR);
	if (w != NULL)
		return;

	RCT2_GLOBAL(0x0142006C, sint32) = -1;
	char* buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char);

	format_string(buffer, id, (void*)0x013CE952);
	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = FONT_SPRITE_BASE_MEDIUM;

	int tooltip_text_width;
	tooltip_text_width = gfx_get_string_width_new_lined(buffer);
	buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char);
	tooltip_text_width = min(tooltip_text_width, 196);

	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = FONT_SPRITE_BASE_MEDIUM;

	int numLines, fontSpriteBase;
	tooltip_text_width = gfx_wrap_string(buffer, tooltip_text_width + 1, &numLines, &fontSpriteBase);

	RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TEXT_HEIGHT, sint16) = numLines;
	width = tooltip_text_width + 3;
	height = ((numLines + 1) * font_get_line_height(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16))) + 4;
	window_tooltip_widgets[WIDX_BACKGROUND].right = width;
	window_tooltip_widgets[WIDX_BACKGROUND].bottom = height;

	memcpy(gTooltip_text_buffer, buffer, 512);

	x = clamp(0, x - (width / 2), RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) - width);

	int max_y = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - height;
	y += 26; // Normally, we'd display the tooltip 26 lower
	if (y > max_y)
		// If y is too large, the tooltip could be forced below the cursor if we'd just clamped y,
		// so we'll subtract a bit more
		y -= height + 40;
	y = clamp(22, y, max_y);

	w = window_create(
		x,
		y,
		width,
		height,
		&window_tooltip_events,
		WC_TOOLTIP,
		WF_TRANSPARENT | WF_STICK_TO_FRONT
		);
	w->widgets = window_tooltip_widgets;

	RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_NOT_SHOWN_TICKS, uint16) = 0;
}
Esempio n. 3
0
void window_tooltip_show(rct_string_id id, int32_t x, int32_t y)
{
    rct_window* w;
    int32_t width, height;

    w = window_find_by_class(WC_ERROR);
    if (w != nullptr)
        return;

    char* buffer = gCommonStringFormatBuffer;

    format_string(buffer, sizeof(gCommonStringFormatBuffer), id, gCommonFormatArgs);
    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;

    int32_t tooltip_text_width;
    tooltip_text_width = gfx_get_string_width_new_lined(buffer);
    buffer = gCommonStringFormatBuffer;
    tooltip_text_width = std::min(tooltip_text_width, 196);

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;

    int32_t numLines, fontSpriteBase;
    tooltip_text_width = gfx_wrap_string(buffer, tooltip_text_width + 1, &numLines, &fontSpriteBase);

    _tooltipNumLines = numLines;
    width = tooltip_text_width + 3;
    height = ((numLines + 1) * font_get_line_height(gCurrentFontSpriteBase)) + 4;
    window_tooltip_widgets[WIDX_BACKGROUND].right = width;
    window_tooltip_widgets[WIDX_BACKGROUND].bottom = height;

    std::memcpy(_tooltipText, buffer, sizeof(_tooltipText));

    int32_t screenWidth = context_get_width();
    int32_t screenHeight = context_get_height();
    x = std::clamp(x - (width / 2), 0, screenWidth - width);

    // TODO The cursor size will be relative to the window DPI.
    //      The amount to offset the y should be adjusted.

    int32_t max_y = screenHeight - height;
    y += 26; // Normally, we'd display the tooltip 26 lower
    if (y > max_y)
        // If y is too large, the tooltip could be forced below the cursor if we'd just clamped y,
        // so we'll subtract a bit more
        y -= height + 40;
    y = std::clamp(y, 22, max_y);

    w = window_create(x, y, width, height, &window_tooltip_events, WC_TOOLTIP, WF_TRANSPARENT | WF_STICK_TO_FRONT);
    w->widgets = window_tooltip_widgets;

    reset_tooltip_not_shown();
}
Esempio n. 4
0
static rct_xy16 window_multiplayer_information_get_size()
{
	if (!_windowInformationSizeDirty) {
		return _windowInformationSize;
	}

	sint32 width = 450;
	sint32 height = 110;
	sint32 numLines, fontSpriteBase;

	gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
	utf8 * buffer = _strdup(network_get_server_description());
	gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase);
	free(buffer);

	sint32 lineHeight = font_get_line_height(fontSpriteBase);
	height += (numLines + 1) * lineHeight;

	_windowInformationSizeDirty = false;
	_windowInformationSize = (rct_xy16){ width, height };
	return _windowInformationSize;
}
Esempio n. 5
0
// Wrap string without drawing, useful to get the height of a wrapped string.
// Almost the same as gfx_draw_string_left_wrapped
sint32 chat_string_wrapped_get_height(void *args, sint32 width)
{
    sint32 fontSpriteBase, lineHeight, lineY, numLines;

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;

    char *buffer = gCommonStringFormatBuffer;
    format_string(buffer, 256, STR_STRING, args);

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
    gfx_wrap_string(buffer, width, &numLines, &fontSpriteBase);
    lineHeight = font_get_line_height(fontSpriteBase);

    gCurrentFontFlags = 0;

    lineY = 0;
    for (sint32 line = 0; line <= numLines; ++line) {
        buffer = get_string_end(buffer) + 1;
        lineY += lineHeight;
    }

    return lineY;
}
Esempio n. 6
0
static LocationXY16 window_multiplayer_information_get_size()
{
    if (!_windowInformationSizeDirty) {
        return _windowInformationSize;
    }

    sint32 width = 450;
    sint32 height = 60;
    sint32 minNumLines = 5;
    sint32 descNumLines, fontSpriteBase;

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
    utf8 * buffer = _strdup(network_get_server_description());
    gfx_wrap_string(buffer, width, &descNumLines, &fontSpriteBase);
    free(buffer);

    sint32 lineHeight = font_get_line_height(fontSpriteBase);
    height += (minNumLines + descNumLines) * lineHeight;

    _windowInformationSizeDirty = false;
    _windowInformationSize = { (sint16)width, (sint16)height };
    return _windowInformationSize;
}
Esempio n. 7
0
/**
 *
 *  rct2: 0x0066E4EE
 */
static void window_news_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, sint32 scrollIndex)
{
    sint32 lineHeight = font_get_line_height(gCurrentFontSpriteBase);
    sint32 itemHeight = window_news_get_item_height();
    sint32 i, x, y, yy, press;

    y = 0;
    for (i = 11; i < 61; i++)
    {
        NewsItem * const newsItem = news_item_get(i);
        if (news_item_is_empty(i))
            break;
        if (y >= dpi->y + dpi->height)
            break;
        if (y + itemHeight < dpi->y)
        {
            y += itemHeight;
            continue;
        }

        // Background
        gfx_fill_rect_inset(dpi, -1, y, 383, y + itemHeight - 1, w->colours[1], (INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_GREY));

        // Date text
        set_format_arg(0, rct_string_id, DateDayNames[newsItem->Day - 1]);
        set_format_arg(2, rct_string_id, DateGameMonthNames[date_get_month(newsItem->MonthYear)]);
        gfx_draw_string_left(dpi, STR_NEWS_DATE_FORMAT, gCommonFormatArgs, COLOUR_WHITE, 2, y);

        // Item text
        utf8 *text = newsItem->Text;
        gfx_draw_string_left_wrapped(dpi, &text, 2, y + lineHeight, 325, STR_BOTTOM_TOOLBAR_NEWS_TEXT, COLOUR_BRIGHT_GREEN);

        // Subject button
        if ((news_type_properties[newsItem->Type] & NEWS_TYPE_HAS_SUBJECT) && !(newsItem->Flags & NEWS_FLAG_HAS_BUTTON))
        {
            x = 328;
            yy = y + lineHeight + 4;

            press = 0;
            if (w->news.var_480 != -1) {
                const uint8 idx = 11 + w->news.var_480;
                news_item_is_valid_idx(idx);
                if (i == idx && w->news.var_482 == 1)
                    press = INSET_RECT_FLAG_BORDER_INSET;
            }
            gfx_fill_rect_inset(dpi, x, yy, x + 23, yy + 23, w->colours[2], press);

            switch (newsItem->Type) {
            case NEWS_ITEM_RIDE:
                gfx_draw_sprite(dpi, SPR_RIDE, x, yy, 0);
                break;
            case NEWS_ITEM_PEEP:
            case NEWS_ITEM_PEEP_ON_RIDE:
            {
                rct_drawpixelinfo cliped_dpi;
                if (!clip_drawpixelinfo(&cliped_dpi, dpi, x + 1, yy + 1, 22, 22)) {
                    break;
                }

                rct_peep* peep = GET_PEEP(newsItem->Assoc);
                sint32 clip_x = 10, clip_y = 19;

                // If normal peep set sprite to normal (no food)
                // If staff set sprite to staff sprite
                sint32 sprite_type = 0;
                if (peep->type == PEEP_TYPE_STAFF){
                    sprite_type = peep->sprite_type;
                    if (peep->staff_type == STAFF_TYPE_ENTERTAINER){
                        clip_y += 3;
                    }
                }

                uint32 image_id = g_peep_animation_entries[sprite_type].sprite_animation->base_image;
                image_id += 0xA0000001;
                image_id |= (peep->tshirt_colour << 19) | (peep->trousers_colour << 24);

                gfx_draw_sprite(&cliped_dpi, image_id, clip_x, clip_y, 0);
                break;
            }
            case NEWS_ITEM_MONEY:
                gfx_draw_sprite(dpi, SPR_FINANCE, x, yy, 0);
                break;
            case NEWS_ITEM_RESEARCH:
                gfx_draw_sprite(dpi, newsItem->Assoc < 0x10000 ? SPR_NEW_SCENERY : SPR_NEW_RIDE, x, yy, 0);
                break;
            case NEWS_ITEM_PEEPS:
                gfx_draw_sprite(dpi, SPR_GUESTS, x, yy, 0);
                break;
            case NEWS_ITEM_AWARD:
                gfx_draw_sprite(dpi, SPR_AWARD, x, yy, 0);
                break;
            case NEWS_ITEM_GRAPH:
                gfx_draw_sprite(dpi, SPR_GRAPH, x, yy, 0);
                break;
            }
        }

        // Location button
        if ((news_type_properties[newsItem->Type] & NEWS_TYPE_HAS_LOCATION) && !(newsItem->Flags & NEWS_FLAG_HAS_BUTTON))
        {
            x = 352;
            yy = y + lineHeight + 4;

            press = 0;
            if (w->news.var_480 != -1) {
                const uint8 idx = 11 + w->news.var_480;
                news_item_is_valid_idx(idx);
                if (i == idx && w->news.var_482 == 2)
                    press = 0x20;
            }
            gfx_fill_rect_inset(dpi, x, yy, x + 23, yy + 23, w->colours[2], press);
            gfx_draw_sprite(dpi, SPR_LOCATE, x, yy, 0);
        }

        y += itemHeight;
    }
}
Esempio n. 8
0
static sint32 window_news_get_item_height()
{
    return 4 * font_get_line_height(gCurrentFontSpriteBase) + 2;
}
Esempio n. 9
0
sint32 font_get_line_height_small(sint32 fontSpriteBase)
{
    return font_get_line_height(fontSpriteBase) / 2;
}