SCI: renamed gfx_text_handle_t -> TextHandle; changed some string code to use Common::String

svn-id: r40162
This commit is contained in:
Max Horn 2009-04-27 14:21:39 +00:00
parent b5e9d79e15
commit 6322478508
5 changed files with 60 additions and 58 deletions

View file

@ -267,13 +267,13 @@ public:
struct GfxText : public GfxWidget { struct GfxText : public GfxWidget {
int _font; int _font;
int lines_nr, lineheight, lastline_width; int lines_nr, lineheight, lastline_width;
char *text; Common::String _text;
gfx_alignment_t halign, valign; gfx_alignment_t halign, valign;
gfx_color_t _color1, _color2, _bgcolor; gfx_color_t _color1, _color2, _bgcolor;
int _textFlags; int _textFlags;
int width; /**< Real text width */ int width; /**< Real text width */
int height; /**< Real text height */ int height; /**< Real text height */
gfx_text_handle_t *_textHandle; TextHandle *_textHandle;
public: public:
GfxText(GfxState *state, rect_t area, int font, const char *text, gfx_alignment_t halign, GfxText(GfxState *state, rect_t area, int font, const char *text, gfx_alignment_t halign,

View file

@ -559,7 +559,7 @@ int wait_specific_key(int key) {
int message(char *msg) { int message(char *msg) {
gfx_text_handle_t *handle; TextHandle *handle;
rect_t text_rect = gfx_rect(0, 150, 320, 50); rect_t text_rect = gfx_rect(0, 150, 320, 50);
@ -926,7 +926,7 @@ void test_e(void) {
void test_wrap(int width, char *text) { void test_wrap(int width, char *text) {
rect_t rect = gfx_rect(0, 0, width, 120); rect_t rect = gfx_rect(0, 0, width, 120);
gfx_text_handle_t *handle = gfxop_new_text(state, 0, TextHandle *handle = gfxop_new_text(state, 0,
text, text,
width, ALIGN_LEFT, ALIGN_TOP, white, white, transparent, 0); width, ALIGN_LEFT, ALIGN_TOP, white, white, transparent, 0);
@ -939,7 +939,7 @@ void test_wrap(int width, char *text) {
void test_f(void) { void test_f(void) {
int i; int i;
int x, y; int x, y;
gfx_text_handle_t *handle; TextHandle *handle;
MESSAGE("-- Test F: Full font test --"); MESSAGE("-- Test F: Full font test --");
waitkey(); waitkey();

View file

@ -822,9 +822,6 @@ GfxDynView::GfxDynView(GfxState *state, Common::Point pos_, int z_, int view_, i
//*** Text *** //*** Text ***
GfxText::~GfxText() { GfxText::~GfxText() {
free(text);
text = NULL;
if (_textHandle) { if (_textHandle) {
GfxState *state = _visual ? _visual->_gfxState : NULL; GfxState *state = _visual ? _visual->_gfxState : NULL;
if (!state) { if (!state) {
@ -841,7 +838,7 @@ int GfxText::draw(const Common::Point &pos) {
DRAW_ASSERT(this, GFXW_TEXT); DRAW_ASSERT(this, GFXW_TEXT);
if (_textHandle == 0) { if (_textHandle == 0) {
_textHandle = gfxop_new_text(_visual->_gfxState, _font, text, _bounds.width, _textHandle = gfxop_new_text(_visual->_gfxState, _font, _text, _bounds.width,
halign, valign, _color1, _color2, _bgcolor, _textFlags); halign, valign, _color1, _color2, _bgcolor, _textFlags);
} }
@ -851,7 +848,7 @@ int GfxText::draw(const Common::Point &pos) {
void GfxText::print(int indentation) const { void GfxText::print(int indentation) const {
printIntern(indentation); printIntern(indentation);
sciprintf("TEXT:'%s'", text); sciprintf("TEXT:'%s'", _text.c_str());
} }
static int _gfxwop_text_equals(GfxWidget *widget, GfxWidget *other) { static int _gfxwop_text_equals(GfxWidget *widget, GfxWidget *other) {
@ -888,7 +885,7 @@ static int _gfxwop_text_should_replace(GfxWidget *widget, GfxWidget *other) {
otext = (GfxText *)other; otext = (GfxText *)other;
return strcmp(wtext->text, otext->text); return wtext->_text != otext->_text;
} }
static int _gfxwop_text_compare_to(GfxWidget *widget, GfxWidget *other) { static int _gfxwop_text_compare_to(GfxWidget *widget, GfxWidget *other) {
@ -907,13 +904,13 @@ GfxText *gfxw_new_text(GfxState *state, rect_t area, int font, const char *text,
return new GfxText(state, area, font, text, halign, valign, color1, color2, bgcolor, text_flags); return new GfxText(state, area, font, text, halign, valign, color1, color2, bgcolor, text_flags);
} }
GfxText::GfxText(GfxState *state, rect_t area, int font, const char *text_, gfx_alignment_t halign_, GfxText::GfxText(GfxState *state, rect_t area, int font, const char *text, gfx_alignment_t halign_,
gfx_alignment_t valign_, gfx_color_t color1_, gfx_color_t color2_, gfx_color_t bgcolor_, int text_flags_) gfx_alignment_t valign_, gfx_color_t color1_, gfx_color_t color2_, gfx_color_t bgcolor_, int text_flags_)
: GfxWidget(GFXW_TEXT) { : GfxWidget(GFXW_TEXT) {
_widgetPriority = _gfxw_color_get_priority(color1_); _widgetPriority = _gfxw_color_get_priority(color1_);
_font = font; _font = font;
text = (char *)sci_malloc(strlen(text_) + 1); _text = text;
halign = halign_; halign = halign_;
valign = valign_; valign = valign_;
_color1 = color1_; _color1 = color1_;
@ -922,8 +919,6 @@ GfxText::GfxText(GfxState *state, rect_t area, int font, const char *text_, gfx_
_textFlags = text_flags_; _textFlags = text_flags_;
_textHandle = NULL; _textHandle = NULL;
strcpy(text, text_);
gfxop_get_text_params(state, font, text, area.width, &width, &height, _textFlags, gfxop_get_text_params(state, font, text, area.width, &width, &height, _textFlags,
&lines_nr, &lineheight, &lastline_width); &lines_nr, &lineheight, &lastline_width);

View file

@ -1906,9 +1906,9 @@ int gfxop_get_text_params(GfxState *state, int font_nr, const char *text, int ma
return GFX_OK; return GFX_OK;
} }
gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int maxwidth, gfx_alignment_t halign, TextHandle *gfxop_new_text(GfxState *state, int font_nr, const Common::String &text, int maxwidth, gfx_alignment_t halign,
gfx_alignment_t valign, gfx_color_t color1, gfx_color_t color2, gfx_color_t bg_color, int flags) { gfx_alignment_t valign, gfx_color_t color1, gfx_color_t color2, gfx_color_t bg_color, int flags) {
gfx_text_handle_t *handle; TextHandle *handle;
gfx_bitmap_font_t *font; gfx_bitmap_font_t *font;
int i, err = 0; int i, err = 0;
BASIC_CHECKS(NULL); BASIC_CHECKS(NULL);
@ -1929,36 +1929,34 @@ gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int
return NULL; return NULL;
} }
handle = (gfx_text_handle_t *)sci_malloc(sizeof(gfx_text_handle_t)); handle = new TextHandle();
handle->text = (char *)sci_malloc(strlen(text) + 1); handle->_text = text;
strcpy(handle->text, text);
handle->halign = halign; handle->halign = halign;
handle->valign = valign; handle->valign = valign;
handle->line_height = font->line_height; handle->line_height = font->line_height;
#ifdef CUSTOM_GRAPHICS_OPTIONS #ifdef CUSTOM_GRAPHICS_OPTIONS
handle->lines = gfxr_font_calculate_size(font, maxwidth, handle->text, &(handle->width), &(handle->height), &(handle->lines_nr), handle->lines = gfxr_font_calculate_size(font, maxwidth, handle->_text.c_str(), &(handle->width), &(handle->height), &(handle->lines_nr),
NULL, NULL, ((state->options->workarounds & GFX_WORKAROUND_WHITESPACE_COUNT) ? NULL, NULL, ((state->options->workarounds & GFX_WORKAROUND_WHITESPACE_COUNT) ?
kFontCountWhitespace : 0) | flags); kFontCountWhitespace : 0) | flags);
#else #else
handle->lines = gfxr_font_calculate_size(font, maxwidth, handle->text, &(handle->width), &(handle->height), &(handle->lines_nr), handle->lines = gfxr_font_calculate_size(font, maxwidth, handle->_text.c_str(), &(handle->width), &(handle->height), &(handle->lines_nr),
NULL, NULL, flags); NULL, NULL, flags);
#endif #endif
if (!handle->lines) { if (!handle->lines) {
free(handle->text);
free(handle);
GFXERROR("Could not calculate text parameters in font #%d\n", font_nr); GFXERROR("Could not calculate text parameters in font #%d\n", font_nr);
delete handle;
return NULL; return NULL;
} }
if (flags & kFontNoNewlines) { if (flags & kFontNoNewlines) {
handle->lines_nr = 1; handle->lines_nr = 1;
handle->lines->length = strlen(text); handle->lines->length = text.size();
} }
handle->text_pixmaps = (gfx_pixmap_t **)sci_malloc(sizeof(gfx_pixmap_t *) * handle->lines_nr); handle->text_pixmaps = (gfx_pixmap_t **)calloc(sizeof(gfx_pixmap_t *), handle->lines_nr);
for (i = 0; i < handle->lines_nr; i++) { for (i = 0; i < handle->lines_nr; i++) {
int chars_nr = handle->lines[i].length; int chars_nr = handle->lines[i].length;
@ -1969,16 +1967,8 @@ gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int
(bg_color.mask & GFX_MASK_VISUAL) ? &bg_color.visual : NULL); (bg_color.mask & GFX_MASK_VISUAL) ? &bg_color.visual : NULL);
if (!handle->text_pixmaps[i]) { if (!handle->text_pixmaps[i]) {
int j;
for (j = 0; j < i; j++)
gfx_free_pixmap(handle->text_pixmaps[j]);
free(handle->text_pixmaps);
free(handle->text);
free(handle->lines);
GFXERROR("Failed to draw text pixmap for line %d/%d\n", i, handle->lines_nr); GFXERROR("Failed to draw text pixmap for line %d/%d\n", i, handle->lines_nr);
free(handle); delete handle;
return NULL; return NULL;
} }
} }
@ -1991,25 +1981,39 @@ gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int
return handle; return handle;
} }
int gfxop_free_text(GfxState *state, gfx_text_handle_t *handle) { int gfxop_free_text(GfxState *state, TextHandle *handle) {
int j;
BASIC_CHECKS(GFX_ERROR); BASIC_CHECKS(GFX_ERROR);
if (handle->text_pixmaps) { delete handle;
for (j = 0; j < handle->lines_nr; j++)
gfx_free_pixmap(handle->text_pixmaps[j]);
free(handle->text_pixmaps);
}
free(handle->text);
free(handle->lines);
free(handle);
return GFX_OK; return GFX_OK;
} }
int gfxop_draw_text(GfxState *state, gfx_text_handle_t *handle, rect_t zone) { TextHandle::TextHandle() {
lines_nr = 0;
line_height = 0;
lines = 0;
font = 0;
text_pixmaps = 0;
width = height = 0;
priority = control = 0;
halign = valign = ALIGN_BOTTOM;
}
TextHandle::~TextHandle() {
if (text_pixmaps) {
for (int j = 0; j < lines_nr; j++)
if (text_pixmaps[j])
gfx_free_pixmap(text_pixmaps[j]);
free(text_pixmaps);
}
free(lines);
}
int gfxop_draw_text(GfxState *state, TextHandle *handle, rect_t zone) {
int line_height; int line_height;
rect_t pos; rect_t pos;
int i; int i;

View file

@ -47,12 +47,12 @@ struct text_fragment_t;
*/ */
#define GFXOP_ALPHA_THRESHOLD 0xff #define GFXOP_ALPHA_THRESHOLD 0xff
struct gfx_text_handle_t { struct TextHandle {
char *text; /* Copy of the actual text */ Common::String _text; /**< Copy of the actual text */
int lines_nr; int lines_nr;
int line_height; int line_height;
text_fragment_t *lines; /* Text offsets */ text_fragment_t *lines; /**< Text offsets */
gfx_bitmap_font_t *font; gfx_bitmap_font_t *font;
gfx_pixmap_t **text_pixmaps; gfx_pixmap_t **text_pixmaps;
@ -60,6 +60,9 @@ struct gfx_text_handle_t {
int priority, control; int priority, control;
gfx_alignment_t halign, valign; gfx_alignment_t halign, valign;
TextHandle();
~TextHandle();
}; };
/* Unless individually stated otherwise, the following applies: /* Unless individually stated otherwise, the following applies:
@ -563,13 +566,13 @@ int gfxop_get_text_params(GfxState *state, int font_nr, const char *text,
** after the last character in the last line ** after the last character in the last line
*/ */
gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int maxwidth, TextHandle *gfxop_new_text(GfxState *state, int font_nr, const Common::String &text, int maxwidth,
gfx_alignment_t halign, gfx_alignment_t valign, gfx_color_t color1, gfx_alignment_t halign, gfx_alignment_t valign, gfx_color_t color1,
gfx_color_t color2, gfx_color_t bg_color, int flags); gfx_color_t color2, gfx_color_t bg_color, int flags);
/* Generates a new text handle that can be used to draw any text /* Generates a new text handle that can be used to draw any text
** Parameters: (GfxState *) state: The state to use ** Parameters: (GfxState *) state: The state to use
** (int) font_nr: Font number to use for the calculation ** (int) font_nr: Font number to use for the calculation
** (char *) text: The text to examine ** (const char *) text: The text to examine
** (int) maxwidth: The maximum pixel width to allow for the text ** (int) maxwidth: The maximum pixel width to allow for the text
** (gfx_alignment_t) halign: The horizontal text alignment ** (gfx_alignment_t) halign: The horizontal text alignment
** (gfx_alignment_t) valign: The vertical text alignment ** (gfx_alignment_t) valign: The vertical text alignment
@ -577,24 +580,24 @@ gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int
** (the function will dither between those two) ** (the function will dither between those two)
** (gfx_color_t) bg_color: The background color ** (gfx_color_t) bg_color: The background color
** (int) flags: ORred GFXR_FONT_FLAGs ** (int) flags: ORred GFXR_FONT_FLAGs
** Returns : (gfx_text_handle_t *) A newly allocated gfx_text_handle_t, or ** Returns : (TextHandle *) A newly allocated TextHandle, or
** NULL if font_nr was invalid ** NULL if font_nr was invalid
** The control and priority values for the text will be extracted from color1. ** The control and priority values for the text will be extracted from color1.
** Note that the colors must have been allocated properly, or the text may display in ** Note that the colors must have been allocated properly, or the text may display in
** incorrect colors. ** incorrect colors.
*/ */
int gfxop_free_text(GfxState *state, gfx_text_handle_t *handle); int gfxop_free_text(GfxState *state, TextHandle *handle);
/* Frees a previously allocated text handle and all related resources /* Frees a previously allocated text handle and all related resources
** Parameters: (GfxState *) state: The state to use ** Parameters: (GfxState *) state: The state to use
** (gfx_text_handle_t *) handle: The handle to free ** (TextHandle *) handle: The handle to free
** Returns : (int) GFX_OK ** Returns : (int) GFX_OK
*/ */
int gfxop_draw_text(GfxState *state, gfx_text_handle_t *handle, rect_t zone); int gfxop_draw_text(GfxState *state, TextHandle *handle, rect_t zone);
/* Draws text stored in a text handle /* Draws text stored in a text handle
** Parameters: (GfxState *) state: The target state ** Parameters: (GfxState *) state: The target state
** (gfx_text_handle_t *) handle: The text handle to use for drawing ** (TextHandle *) handle: The text handle to use for drawing
** (rect_t) zone: The rectangular box to draw to. In combination with ** (rect_t) zone: The rectangular box to draw to. In combination with
** halign and valign, this defines where the text is ** halign and valign, this defines where the text is
** drawn to. ** drawn to.