Esempio n. 1
0
Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) const {

	ERR_FAIL_COND_V(p_width <= 0, Vector2(0, get_height()));

	int l = p_string.length();
	if (l == 0)
		return Size2(p_width, get_height());

	float line_w = 0;
	float h = 0;
	float space_w = get_char_size(' ').width;
	Vector<String> lines = p_string.split("\n");
	for (int i = 0; i < lines.size(); i++) {
		h += get_height();
		String t = lines[i];
		line_w = 0;
		Vector<String> words = t.split(" ");
		for (int j = 0; j < words.size(); j++) {
			line_w += get_string_size(words[j]).x;
			if (line_w > p_width) {
				h += get_height();
				line_w = get_string_size(words[j]).x;
			} else {
				line_w += space_w;
			}
		}
	}

	return Size2(p_width, h);
}
Esempio n. 2
0
extern char* file_read_line(xString *const line , FILE* fp)
{
   char *result = NULL;
   
   string_clear(line);

   if ( NULL == fp )
         error(FATAL, "NULL file pointer");
   else{
      boolean re_readline;

      do {
         char *const pLastChar = get_string_value(line) + get_string_size (line) -2;
			fpos_t startOfLine;

			fgetpos (fp, &startOfLine);
			re_readline = FALSE;
			*pLastChar = '\0';
			result = fgets (get_string_value(line), (int) get_string_size(line), fp);
			if (result == NULL)
			{
				if (! feof(fp))
					error (FATAL | ERROR, "Failure on attempt to read file");
			}
			else if (*pLastChar != '\0'  &&
					 *pLastChar != '\n'  &&  *pLastChar != '\r')
			{
				/*  buffer overflow */
				re_readline = string_auto_resize(line);
				if (re_readline)
					fsetpos (fp, &startOfLine);
				else
					error (FATAL | ERROR, "input line too big; out of memory");
			}
			else
			{
				char* eol;
            line->length = strlen (line->buffer);

				/* canonicalize new line */
				eol = get_string_value(line) + get_string_length(line) - 1;
				if (*eol == '\r')
					*eol = '\n';
				else if (*(eol - 1) == '\r'  &&  *eol == '\n')
				{
					*(eol - 1) = '\n';
					*eol = '\0';
					--line->length;
				}
			}
      }while(re_readline);
   }
   return result;
}
Esempio n. 3
0
void Font::draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, float p_width, const String &p_text, const Color &p_modulate) const {

	float length = get_string_size(p_text).width;
	if (length >= p_width) {
		draw(p_canvas_item, p_pos, p_text, p_modulate, p_width);
		return;
	}

	float ofs = 0.f;
	switch (p_align) {
		case HALIGN_LEFT: {
			ofs = 0;
		} break;
		case HALIGN_CENTER: {
			ofs = Math::floor((p_width - length) / 2.0);
		} break;
		case HALIGN_RIGHT: {
			ofs = p_width - length;
		} break;
		default: {
			ERR_PRINT("Unknown halignment type");
		} break;
	}
	draw(p_canvas_item, p_pos + Point2(ofs, 0), p_text, p_modulate, p_width);
}
Esempio n. 4
0
static void window_text_input_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
	window_draw_widgets(w, dpi);

	int y = w->y + 25;

	int no_lines = 0;
	int font_height = 0;


	gfx_draw_string_centred(dpi, input_text_description, w->x + WW / 2, y, w->colours[1], &TextInputDescriptionArgs);

	y += 25;

	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224;
	RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0;

	char wrapped_string[512];
	safe_strcpy(wrapped_string, text_input, 512);

	// String length needs to add 12 either side of box
	// +13 for cursor when max length.
	gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height);

	gfx_fill_rect_inset(dpi, w->x + 10, y, w->x + WW - 10, y + 10 * (no_lines + 1) + 3, w->colours[1], 0x60);

	y += 1;

	char* wrap_pointer = wrapped_string;
	int char_count = 0;
	uint8 cur_drawn = 0;

	int cursorX, cursorY;
	for (int line = 0; line <= no_lines; line++) {
		gfx_draw_string(dpi, wrap_pointer, w->colours[1], w->x + 12, y);

		int string_length = get_string_size(wrap_pointer) - 1;

		if (!cur_drawn && (gTextInput.selection_offset <= (size_t)(char_count + string_length))) {
			// Make a copy of the string for measuring the width.
			char temp_string[512] = { 0 };
			memcpy(temp_string, wrap_pointer, gTextInput.selection_offset - char_count);
			cursorX = w->x + 13 + gfx_get_string_width(temp_string);
			cursorY = y;

			int width = 6;
			if ((uint32)gTextInput.selection_offset < strlen(text_input)){
				// Make a new 1 character wide string for measuring the width
				// of the character that the cursor is under.
				temp_string[1] = '\0';
				temp_string[0] = text_input[gTextInput.selection_offset];
				width = max(gfx_get_string_width(temp_string) - 2, 4);
			}

			if (w->frame_no > 15){
				uint8 colour = ColourMapA[w->colours[1]].mid_light;
				gfx_fill_rect(dpi, cursorX, y + 9, cursorX + width, y + 9, colour + 5);
			}

			cur_drawn++;
		}

		wrap_pointer += string_length + 1;

		if (text_input[char_count + string_length] == ' ')char_count++;
		char_count += string_length;

		y += 10;
	}

	if (!cur_drawn) {
		cursorX = gLastDrawStringX;
		cursorY = y - 10;
	}

	// IME composition
	if (gTextInputCompositionActive) {
		int compositionWidth = gfx_get_string_width(gTextInputComposition);
		int x = cursorX - (compositionWidth / 2);
		int y = cursorY + 13;
		int w = compositionWidth;
		int h = 10;

		gfx_fill_rect(dpi, x - 1, y - 1, x + w + 1, y + h + 1, 12);
		gfx_fill_rect(dpi, x, y, x + w, y + h, 0);
		gfx_draw_string(dpi, gTextInputComposition, 12, x, y);
	}
}
Esempio n. 5
0
int node_smart_ptr::data_size()
{
  return get_string_size(BASE_COMPONENT_INDEX+3);
}
Esempio n. 6
0
static void window_text_input_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
	window_draw_widgets(w, dpi);

	sint32 y = w->y + 25;

	sint32 no_lines = 0;
	sint32 font_height = 0;


	gfx_draw_string_centred(dpi, input_text_description, w->x + WW / 2, y, w->colours[1], &TextInputDescriptionArgs);

	y += 25;

	gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
	gCurrentFontFlags = 0;

	char wrapped_string[512];
	safe_strcpy(wrapped_string, text_input, 512);

	// String length needs to add 12 either side of box
	// +13 for cursor when max length.
	gfx_wrap_string(wrapped_string, WW - (24 + 13), &no_lines, &font_height);

	gfx_fill_rect_inset(dpi, w->x + 10, y, w->x + WW - 10, y + 10 * (no_lines + 1) + 3, w->colours[1], INSET_RECT_F_60);

	y += 1;

	char* wrap_pointer = wrapped_string;
	size_t char_count = 0;
	uint8 cur_drawn = 0;

	sint32 cursorX = 0, cursorY = 0;
	for (sint32 line = 0; line <= no_lines; line++) {
		gfx_draw_string(dpi, wrap_pointer, w->colours[1], w->x + 12, y);

		size_t string_length = get_string_size(wrap_pointer) - 1;

		if (!cur_drawn && (gTextInput.selection_offset <= char_count + string_length)) {
			// Make a copy of the string for measuring the width.
			char temp_string[512] = { 0 };
			memcpy(temp_string, wrap_pointer, gTextInput.selection_offset - char_count);
			cursorX = w->x + 13 + gfx_get_string_width(temp_string);
			cursorY = y;

			sint32 width = 6;
			if (gTextInput.selection_offset < strlen(text_input)){
				// Make a 1 utf8-character wide string for measuring the width
				// of the currently selected character.
				utf8 tmp[5] = { 0 }; // This is easier than setting temp_string[0..5]
				uint32 codepoint = utf8_get_next(text_input + gTextInput.selection_offset, NULL);
				utf8_write_codepoint(tmp, codepoint);
				width = max(gfx_get_string_width(tmp) - 2, 4);
			}

			if (w->frame_no > 15){
				uint8 colour = ColourMapA[w->colours[1]].mid_light;
				gfx_fill_rect(dpi, cursorX, y + 9, cursorX + width, y + 9, colour + 5);
			}

			cur_drawn++;
		}

		wrap_pointer += string_length + 1;

		if (text_input[char_count + string_length] == ' ')char_count++;
		char_count += string_length;

		y += 10;
	}

	if (!cur_drawn) {
		cursorX = gLastDrawStringX;
		cursorY = y - 10;
	}

	// IME composition
	if (gTextInputCompositionActive) {
		draw_ime_composition(dpi, cursorX, cursorY);
	}
}
Esempio n. 7
0
int stylesheet_smart_ptr::hardcopy_data_size()
{
   return get_string_size(BASE_COMPONENT_INDEX+2);
}
Esempio n. 8
0
int stylesheet_smart_ptr::online_data_size()
{
   return get_string_size(BASE_COMPONENT_INDEX+1);
}
Esempio n. 9
0
static void widget_text_box_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex)
{
    sint32 no_lines = 0;
    sint32 font_height = 0;
    char wrapped_string[TEXT_INPUT_SIZE];

    // Get the widget
    rct_widget *widget = &w->widgets[widgetIndex];

    // Resolve the absolute ltrb
    sint32 l = w->x + widget->left;
    sint32 t = w->y + widget->top;
    sint32 r = w->x + widget->right;
    sint32 b = w->y + widget->bottom;

    // Get the colour
    uint8 colour = w->colours[widget->colour];

    bool active = w->classification == gCurrentTextBox.window.classification &&
        w->number == gCurrentTextBox.window.number &&
        widgetIndex == gCurrentTextBox.widget_index;

    //gfx_fill_rect_inset(dpi, l, t, r, b, colour, 0x20 | (!active ? 0x40 : 0x00));
    gfx_fill_rect_inset(dpi, l, t, r, b, colour, INSET_RECT_F_60);

    gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
    gCurrentFontFlags = 0;

    if (!active || gTextInput == NULL) {

        if (w->widgets[widgetIndex].text != 0) {
            safe_strcpy(wrapped_string, w->widgets[widgetIndex].string, 512);
            gfx_wrap_string(wrapped_string, r - l - 5, &no_lines, &font_height);
            gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);
        }
        return;
    }


    safe_strcpy(wrapped_string, gTextBoxInput, TEXT_INPUT_SIZE);

    // String length needs to add 12 either side of box
    // +13 for cursor when max length.
    gfx_wrap_string(wrapped_string, r - l - 5 - 6, &no_lines, &font_height);


    gfx_draw_string(dpi, wrapped_string, w->colours[1], l + 2, t);


    size_t string_length = get_string_size(wrapped_string) - 1;

    // Make a copy of the string for measuring the width.
    char temp_string[TEXT_INPUT_SIZE] = { 0 };
    memcpy(temp_string, wrapped_string, min(string_length, gTextInput->SelectionStart));
    sint32 cur_x = l + gfx_get_string_width(temp_string) + 3;

    sint32 width = 6;
    if ((uint32)gTextInput->SelectionStart < strlen(gTextBoxInput)){
        // Make a new 1 character wide string for measuring the width
        // of the character that the cursor is under.
        temp_string[1] = '\0';
        temp_string[0] = gTextBoxInput[gTextInput->SelectionStart];
        width = max(gfx_get_string_width(temp_string) - 2, 4);
    }

    if (gTextBoxFrameNo <= 15){
        colour = ColourMapA[w->colours[1]].mid_light;
        gfx_fill_rect(dpi, cur_x, t + 9, cur_x + width, t + 9, colour + 5);
    }
}