1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
* Copyright (c) 1997 - 2001 Hansjrg Malthaner
*
* This file is part of the Simutrans project under the artistic licence.
* (see licence.txt)
*/
#include <string.h>
#include "gui_textarea.h"
#include "../../simgraph.h"
#include "../../simdebug.h"
#include "../../simcolor.h"
gui_textarea_t::gui_textarea_t(const char *text)
{
setze_text(text);
recalc_size();
}
void
gui_textarea_t::setze_text(const char *text)
{
if(text) {
this->text = text;
} else {
text = "";
}
}
// recalcs the current size;
// usually not needed to be called explicitely
void gui_textarea_t::recalc_size()
{
// we cannot use: display_multiline_text(pos.x+offset.x, pos.y+offset.y+10, text, COL_BLACK);
// since we also want to dynamically change the size of the component
int new_lines=0;
int x_size = 1;
if (text!=NULL && *text!= '\0') {
const char *buf=text;
const char *next;
do {
next = strchr(buf, '\n');
const long len = next != NULL ? next - buf : -1;
int px_len = display_calc_proportional_string_len_width(buf, len);
if(px_len>x_size) {
x_size = px_len;
}
buf = next + 1;
new_lines += LINESPACE;
} while (next != NULL);
}
DBG_MESSAGE("gui_textarea_t::recalc_size()","reset size to %i,%i",x_size+10,new_lines);
setze_groesse(koord(x_size+10,new_lines));
}
/**
* Zeichnet die Komponente
* @author Hj. Malthaner
*/
void gui_textarea_t::zeichnen(koord offset)
{
// we cannot use: display_multiline_text(pos.x+offset.x, pos.y+offset.y+10, text, COL_BLACK);
// since we also want to dynamically change the size of the component
int new_lines=0;
// keep previous maximum width
int x_size = gib_groesse().x-10;
if (text!=NULL && *text!= '\0') {
const char *buf=text;
const char *next;
const sint16 x = pos.x+offset.x;
sint16 y = pos.y+offset.y+10;
do {
next = strchr(buf, '\n');
if(pos.y+new_lines>=0) {
const long len = next != NULL ? next - buf : -1;
int px_len = display_text_proportional_len_clip(x, y + new_lines, buf, ALIGN_LEFT | DT_DIRTY | DT_CLIP, COL_BLACK, len);
if(px_len>x_size) {
x_size = px_len;
}
}
buf = next + 1;
new_lines += LINESPACE;
} while (next != NULL);
}
koord gr(max(x_size+10,gib_groesse().x),new_lines);
if(gr!=gib_groesse()) {
setze_groesse(gr);
}
}
|