Simplify the construction of text objects - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年01月04日 11:43:40 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年01月04日 11:43:40 +0100
commit3c1ad26e933233f6a7031b0b56c5b19ffb5ebf96 (patch)
treef2046e38a5238907638d3ab9beb8008cb942fc94 /agg-plot
parent0cd09ca0c5db79ede08b7df45c0a358c6a93d76d (diff)
downloadgsl-shell-3c1ad26e933233f6a7031b0b56c5b19ffb5ebf96.tar.gz
Simplify the construction of text objects
Changes also the Lua interface accordingly and updates the documentation and the demos.
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/lua-text.cpp 18
-rw-r--r--agg-plot/plot.h 27
-rw-r--r--agg-plot/text.h 23
3 files changed, 19 insertions, 49 deletions
diff --git a/agg-plot/lua-text.cpp b/agg-plot/lua-text.cpp
index 91a606bc..04129c78 100644
--- a/agg-plot/lua-text.cpp
+++ b/agg-plot/lua-text.cpp
@@ -17,7 +17,6 @@ static int agg_text_set_point (lua_State *L);
static int agg_text_index (lua_State *L);
static int agg_text_newindex (lua_State *L);
-static int agg_text_text_set (lua_State *L);
static int agg_text_angle_set (lua_State *L);
static int agg_text_justif_set (lua_State *L);
@@ -51,7 +50,6 @@ static const struct luaL_Reg text_properties_get[] = {
};
static const struct luaL_Reg text_properties_set[] = {
- {"text", agg_text_text_set },
{"angle", agg_text_angle_set },
{NULL, NULL}
};
@@ -65,9 +63,10 @@ check_agg_text (lua_State *L, int index)
int
agg_text_new (lua_State *L)
{
- double size = luaL_optnumber (L, 1, 10.0);
- double width = luaL_optnumber (L, 2, 1.0) + 0.7;
- new(L, GS_DRAW_TEXT) draw::text(size, width);
+ const char *text = luaL_checkstring (L, 1);
+ double size = luaL_optnumber (L, 2, 10.0);
+ double width = luaL_optnumber (L, 3, 1.0) + 0.7;
+ new(L, GS_DRAW_TEXT) draw::text(text, size, width);
return 1;
}
@@ -81,15 +80,6 @@ agg_text_free (lua_State *L)
}
int
-agg_text_text_set (lua_State *L)
-{
- draw::text *t = check_agg_text (L, 1);
- const char *str_text = luaL_checkstring (L, 2);
- t->set_text(str_text);
- return 0;
-}
-
-int
agg_text_angle_set (lua_State *L)
{
draw::text *t = check_agg_text (L, 1);
diff --git a/agg-plot/plot.h b/agg-plot/plot.h
index dbd5eb51..fe30ce9e 100644
--- a/agg-plot/plot.h
+++ b/agg-plot/plot.h
@@ -450,15 +450,10 @@ void plot<VS,RM>::draw_axis(canvas_type& canvas, agg::trans_affine& canvas_mtx)
this->m_trans.transform(&x, &y);
if (y >= - yeps && y <= 1.0 + yeps)
{
- draw::text* label = new draw::text(10.0 * scale, line_width);
-
char lab_text[32];
-
m_uy.mark_label(lab_text, 32, j);
- label->set_text(lab_text);
- label->hjustif(1.0);
- label->vjustif(0.5);
+ draw::text* label = new draw::text(lab_text, 10.0 * scale, line_width, 1.0, 0.5);
label->set_point(-ppad, y);
mark.move_to(0.0, y);
@@ -493,14 +488,10 @@ void plot<VS,RM>::draw_axis(canvas_type& canvas, agg::trans_affine& canvas_mtx)
this->m_trans.transform(&x, &y);
if (x >= - xeps && x <= 1.0 + xeps)
{
- draw::text* label = new draw::text(10.0 * scale, line_width);
char lab_text[32];
-
m_ux.mark_label(lab_text, 32, j);
- label->set_text(lab_text);
- label->hjustif(0.5);
- label->vjustif(1.0);
+ draw::text* label = new draw::text(lab_text, 10.0 * scale, line_width, 0.5, 1.0);
label->set_point(x, -ppad);
mark.move_to(x, 0.0);
@@ -591,9 +582,7 @@ void plot<VS,RM>::draw_axis(canvas_type& canvas, agg::trans_affine& canvas_mtx)
double _labx = 0.5, laby = 0.0;
canvas_mtx.transform(&_labx, &laby);
- draw::text xlabel(label_text_size, std_line_width(scale));
- xlabel.set_text(m_xlabel.cstr());
- xlabel.hjustif(0.5);
+ draw::text xlabel(m_xlabel.cstr(), label_text_size, line_width, 0.5, 0.0);
xlabel.set_point(labx, laby + ysign * (syr*ppad + fpad));
xlabel.apply_transform(identity_matrix, 1.0);
@@ -605,10 +594,7 @@ void plot<VS,RM>::draw_axis(canvas_type& canvas, agg::trans_affine& canvas_mtx)
double labx = 0.0, laby = 0.5;
m.transform(&labx, &laby);
- draw::text ylabel(label_text_size, std_line_width(scale));
- ylabel.set_text(m_ylabel.cstr());
- ylabel.hjustif(0.5);
- ylabel.vjustif(1.0);
+ draw::text ylabel(m_ylabel.cstr(), label_text_size, line_width, 0.5, 1.0);
ylabel.set_point(sxr*ppad + fpad, laby);
ylabel.angle(M_PI/2.0);
ylabel.apply_transform(identity_matrix, 1.0);
@@ -621,10 +607,7 @@ void plot<VS,RM>::draw_axis(canvas_type& canvas, agg::trans_affine& canvas_mtx)
double labx = 0.5, laby = 1.0;
m.transform(&labx, &laby);
- draw::text title(title_text_size, std_line_width(scale));
- title.set_text(m_title.cstr());
- title.hjustif(0.5);
- title.vjustif(0.0);
+ draw::text title(m_title.cstr(), title_text_size, line_width, 0.5, 0.0);
title.set_point(labx, laby + ysign * (2*syr*ppad));
title.apply_transform(identity_matrix, 1.0);
diff --git a/agg-plot/text.h b/agg-plot/text.h
index e9bcd3d1..4f930bd7 100644
--- a/agg-plot/text.h
+++ b/agg-plot/text.h
@@ -18,12 +18,11 @@ namespace draw {
agg::trans_affine m_matrix;
agg::trans_affine m_user_matrix;
+ str m_text_buf;
vs_text m_text;
vs_trans_text m_trans;
vs_stroked_text m_stroke;
- str m_text_buf;
-
double m_x, m_y;
double m_angle;
@@ -34,17 +33,21 @@ namespace draw {
double m_vjustif;
public:
- text(double size = 10.0, double width = 1.0):
- m_matrix(), m_user_matrix(),
+ text(const char* text, double size = 10.0, double width = 1.0,
+ double hjustif = 0.0, double vjustif = 0.0):
+ m_matrix(), m_user_matrix(), m_text_buf(text),
m_text(), m_trans(m_text, m_user_matrix), m_stroke(m_trans),
- m_text_buf(), m_x(0.0), m_y(0.0), m_angle(0.0),
+ m_x(0.0), m_y(0.0), m_angle(0.0),
m_text_width(0.0), m_text_height(size),
- m_hjustif(0.0), m_vjustif(0.0)
+ m_hjustif(hjustif), m_vjustif(vjustif)
{
+ m_text.text(m_text_buf.cstr());
+ m_text.size(size);
+ m_text_width = m_text.text_width();
+
m_stroke.width(width);
m_stroke.line_cap(agg::round_cap);
m_stroke.line_join(agg::round_join);
- m_text.size(size);
}
void angle(double th) {
@@ -60,12 +63,6 @@ namespace draw {
double angle() const { return m_angle; };
- void set_text(const char *txt) {
- str_copy_c(&m_text_buf, txt);
- m_text.text(txt);
- m_text_width = m_text.text_width();
- }
-
const char * get_text() const { return m_text_buf.cstr(); }
void set_point(double x, double y) {
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月27日 16:05:47 +0000

AltStyle によって変換されたページ (->オリジナル) /