aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2009-04-27 14:21:39 +0000
committerMax Horn2009-04-27 14:21:39 +0000
commit6322478508e4a2a412efdb819b38d54c067cbbb6 (patch)
tree618483152443c03910a1b2873c7f71a42230f3bd /engines/sci
parentb5e9d79e157d4460f4b9038d19bfc31cf279c5f0 (diff)
downloadscummvm-rg350-6322478508e4a2a412efdb819b38d54c067cbbb6.tar.gz
scummvm-rg350-6322478508e4a2a412efdb819b38d54c067cbbb6.tar.bz2
scummvm-rg350-6322478508e4a2a412efdb819b38d54c067cbbb6.zip
SCI: renamed gfx_text_handle_t -> TextHandle; changed some string code to use Common::String
svn-id: r40162
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/gfx/gfx_state_internal.h4
-rw-r--r--engines/sci/gfx/gfx_test.cpp6
-rw-r--r--engines/sci/gfx/gfx_widgets.cpp15
-rw-r--r--engines/sci/gfx/operations.cpp70
-rw-r--r--engines/sci/gfx/operations.h23
5 files changed, 60 insertions, 58 deletions
diff --git a/engines/sci/gfx/gfx_state_internal.h b/engines/sci/gfx/gfx_state_internal.h
index 22a8e7f97b..f6085b4a0e 100644
--- a/engines/sci/gfx/gfx_state_internal.h
+++ b/engines/sci/gfx/gfx_state_internal.h
@@ -267,13 +267,13 @@ public:
struct GfxText : public GfxWidget {
int _font;
int lines_nr, lineheight, lastline_width;
- char *text;
+ Common::String _text;
gfx_alignment_t halign, valign;
gfx_color_t _color1, _color2, _bgcolor;
int _textFlags;
int width; /**< Real text width */
int height; /**< Real text height */
- gfx_text_handle_t *_textHandle;
+ TextHandle *_textHandle;
public:
GfxText(GfxState *state, rect_t area, int font, const char *text, gfx_alignment_t halign,
diff --git a/engines/sci/gfx/gfx_test.cpp b/engines/sci/gfx/gfx_test.cpp
index 746ded32b8..a3c24159e7 100644
--- a/engines/sci/gfx/gfx_test.cpp
+++ b/engines/sci/gfx/gfx_test.cpp
@@ -559,7 +559,7 @@ int wait_specific_key(int key) {
int message(char *msg) {
- gfx_text_handle_t *handle;
+ TextHandle *handle;
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) {
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,
width, ALIGN_LEFT, ALIGN_TOP, white, white, transparent, 0);
@@ -939,7 +939,7 @@ void test_wrap(int width, char *text) {
void test_f(void) {
int i;
int x, y;
- gfx_text_handle_t *handle;
+ TextHandle *handle;
MESSAGE("-- Test F: Full font test --");
waitkey();
diff --git a/engines/sci/gfx/gfx_widgets.cpp b/engines/sci/gfx/gfx_widgets.cpp
index d90414b622..a90458118c 100644
--- a/engines/sci/gfx/gfx_widgets.cpp
+++ b/engines/sci/gfx/gfx_widgets.cpp
@@ -822,9 +822,6 @@ GfxDynView::GfxDynView(GfxState *state, Common::Point pos_, int z_, int view_, i
//*** Text ***
GfxText::~GfxText() {
- free(text);
- text = NULL;
-
if (_textHandle) {
GfxState *state = _visual ? _visual->_gfxState : NULL;
if (!state) {
@@ -841,7 +838,7 @@ int GfxText::draw(const Common::Point &pos) {
DRAW_ASSERT(this, GFXW_TEXT);
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);
}
@@ -851,7 +848,7 @@ int GfxText::draw(const Common::Point &pos) {
void GfxText::print(int indentation) const {
printIntern(indentation);
- sciprintf("TEXT:'%s'", text);
+ sciprintf("TEXT:'%s'", _text.c_str());
}
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;
- return strcmp(wtext->text, otext->text);
+ return wtext->_text != otext->_text;
}
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);
}
-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_)
: GfxWidget(GFXW_TEXT) {
_widgetPriority = _gfxw_color_get_priority(color1_);
_font = font;
- text = (char *)sci_malloc(strlen(text_) + 1);
+ _text = text;
halign = halign_;
valign = valign_;
_color1 = color1_;
@@ -922,8 +919,6 @@ GfxText::GfxText(GfxState *state, rect_t area, int font, const char *text_, gfx_
_textFlags = text_flags_;
_textHandle = NULL;
- strcpy(text, text_);
-
gfxop_get_text_params(state, font, text, area.width, &width, &height, _textFlags,
&lines_nr, &lineheight, &lastline_width);
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index d5b6153b1e..13e0e8755b 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -1906,9 +1906,9 @@ int gfxop_get_text_params(GfxState *state, int font_nr, const char *text, int ma
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_text_handle_t *handle;
+ TextHandle *handle;
gfx_bitmap_font_t *font;
int i, err = 0;
BASIC_CHECKS(NULL);
@@ -1929,36 +1929,34 @@ gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int
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);
- strcpy(handle->text, text);
+ handle->_text = text;
handle->halign = halign;
handle->valign = valign;
handle->line_height = font->line_height;
#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) ?
kFontCountWhitespace : 0) | flags);
#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);
#endif
if (!handle->lines) {
- free(handle->text);
- free(handle);
GFXERROR("Could not calculate text parameters in font #%d\n", font_nr);
+ delete handle;
return NULL;
}
if (flags & kFontNoNewlines) {
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++) {
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);
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);
- free(handle);
+ delete handle;
return NULL;
}
}
@@ -1991,25 +1981,39 @@ gfx_text_handle_t *gfxop_new_text(GfxState *state, int font_nr, char *text, int
return handle;
}
-int gfxop_free_text(GfxState *state, gfx_text_handle_t *handle) {
- int j;
-
+int gfxop_free_text(GfxState *state, TextHandle *handle) {
BASIC_CHECKS(GFX_ERROR);
- if (handle->text_pixmaps) {
- 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);
+ delete handle;
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;
rect_t pos;
int i;
diff --git a/engines/sci/gfx/operations.h b/engines/sci/gfx/operations.h
index d9890001a6..47126324be 100644
--- a/engines/sci/gfx/operations.h
+++ b/engines/sci/gfx/operations.h
@@ -47,12 +47,12 @@ struct text_fragment_t;
*/
#define GFXOP_ALPHA_THRESHOLD 0xff
-struct gfx_text_handle_t {
- char *text; /* Copy of the actual text */
+struct TextHandle {
+ Common::String _text; /**< Copy of the actual text */
int lines_nr;
int line_height;
- text_fragment_t *lines; /* Text offsets */
+ text_fragment_t *lines; /**< Text offsets */
gfx_bitmap_font_t *font;
gfx_pixmap_t **text_pixmaps;
@@ -60,6 +60,9 @@ struct gfx_text_handle_t {
int priority, control;
gfx_alignment_t halign, valign;
+
+ TextHandle();
+ ~TextHandle();
};
/* 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
*/
-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_color_t color2, gfx_color_t bg_color, int flags);
/* Generates a new text handle that can be used to draw any text
** Parameters: (GfxState *) state: The state to use
** (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
** (gfx_alignment_t) halign: The horizontal 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)
** (gfx_color_t) bg_color: The background color
** (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
** 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
** 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
** 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
*/
-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
** 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
** halign and valign, this defines where the text is
** drawn to.