graphics

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 596bf5aaf442c1e8aa2c544eb994487bb26c6921
parent d0034d74211e0a2cd5a674d323614fcc3adb51ac
Author: Brian Swetland <swetland@frotz.net>
Date:   Tue, 10 Sep 2013 05:13:35 -0700

textgrid: provide resize()

Diffstat:
Mcommon/textgrid.cc | 32++++++++++++++++++++------------
Mcommon/textgrid.h | 1+
2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/common/textgrid.cc b/common/textgrid.cc @@ -38,6 +38,19 @@ static float unit_box_2d[] = { 0, 1, 0, 0, }; +void TextGrid::resize(int columns, int rows) { + width = columns; + height = rows; + dirty = 1; + + // TODO: bring existing character data to new grid + + if (grid) + delete[] grid; + grid = new unsigned char[width * height]; + clear(); +} + int TextGrid::init(int cellw, int cellh, int columns, int rows) { VertexBuffer *data[] = { &vtx, @@ -45,19 +58,9 @@ int TextGrid::init(int cellw, int cellh, int columns, int rows) { &cbuf, }; float box_2d[4 * 6]; - width = columns; - height = rows; - dirty = 0; - - grid = (unsigned char*) malloc(width * height); - if (!grid) - return -1; - clear(); - if (texture.load("font-vincent-8x8.png", 0)) - return -1; - if (!(effect = Effect::load("textgrid"))) - return -1; + grid = nullptr; + resize(columns, rows); // scale quad to character cell and texture cell size for (int n = 0; n < (4 * 6); n += 4) { @@ -67,6 +70,11 @@ int TextGrid::init(int cellw, int cellh, int columns, int rows) { box_2d[n + 3] = unit_box_2d[n + 3] * (1.0f / 16.0f); } + if (texture.load("font-vincent-8x8.png", 0)) + return -1; + if (!(effect = Effect::load("textgrid"))) + return -1; + vtx.load(box_2d, sizeof(box_2d)); cbuf.load(grid, width * height); attr.init(layout, data, sizeof(layout) / sizeof(layout[0])); diff --git a/common/textgrid.h b/common/textgrid.h @@ -21,6 +21,7 @@ class TextGrid { public: int init(int cellw, int cellh, int columns, int rows); + void resize(int columns, int rows); void render(void); void clear(void); void printf(int x, int y, const char *fmt, ...);