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:
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/Makefile 3
-rw-r--r--agg-plot/c-drawables.cpp 14
-rw-r--r--agg-plot/c-drawables.h 5
-rw-r--r--agg-plot/plot.cpp 9
-rw-r--r--agg-plot/plot.h 67
-rw-r--r--agg-plot/test.cpp 78
-rw-r--r--agg-plot/units-plot.h 1
7 files changed, 81 insertions, 96 deletions
diff --git a/agg-plot/Makefile b/agg-plot/Makefile
index b145f80d..fb6b84df 100644
--- a/agg-plot/Makefile
+++ b/agg-plot/Makefile
@@ -47,8 +47,7 @@ endif
INCLUDES += -I$(GSH_BASE_DIR) -I$(LUADIR)/src -I$(LUADIR)/etc
-AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp c-drawables.cpp plot.cpp colors.cpp xwin-show.cpp
-# AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp c-drawables.cpp test.cpp
+AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp c-drawables.cpp colors.cpp xwin-show.cpp
AGGPLOT_OBJ_FILES := $(AGGPLOT_SRC_FILES:%.cpp=%.o)
diff --git a/agg-plot/c-drawables.cpp b/agg-plot/c-drawables.cpp
index 43a6a96d..d5111c02 100644
--- a/agg-plot/c-drawables.cpp
+++ b/agg-plot/c-drawables.cpp
@@ -30,7 +30,6 @@ typedef my::path path_type;
CPLOT *
plot_new(int with_units)
{
- typedef units_plot<vertex_source, ref_manager> units_plot_type;
plot_type *p;
if (with_units)
@@ -129,6 +128,19 @@ void plot_add(CPLOT *_p, CVERTSRC *_vs, struct color *color,
p->add(curr, new_color(color), (bool) outline);
}
+void
+plot_set_title (CPLOT *_p, const char *title)
+{
+ plot_type* p = (plot_type*) _p;
+ p->set_title(title);
+}
+
+const char * plot_get_title (CPLOT *_p)
+{
+ plot_type* p = (plot_type*) _p;
+ return p->get_title();
+}
+
CPATH* path_new()
{
path_type* p = new path_type();
diff --git a/agg-plot/c-drawables.h b/agg-plot/c-drawables.h
index 28310246..624a816d 100644
--- a/agg-plot/c-drawables.h
+++ b/agg-plot/c-drawables.h
@@ -10,7 +10,10 @@
#define CTEXT struct my_c_text
#ifdef __cplusplus
+#include "units-plot.h"
+
typedef plot<vertex_source, ref_manager> plot_type;
+typedef units_plot<vertex_source, ref_manager> units_plot_type;
#endif
__BEGIN_DECLS
@@ -27,6 +30,8 @@ extern void plot_free (CPLOT *p);
extern void plot_add (CPLOT *p, CVERTSRC *src, struct color *color,
struct trans_spec *post, struct trans_spec *pre,
int outline);
+extern void plot_set_title (CPLOT *p, const char *title);
+extern const char * plot_get_title (CPLOT *p);
extern void vertex_source_ref (CVERTSRC *p);
extern void vertex_source_unref (CVERTSRC *p);
diff --git a/agg-plot/plot.cpp b/agg-plot/plot.cpp
deleted file mode 100644
index 32a37bff..00000000
--- a/agg-plot/plot.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-
-#include "utils.h"
-#include "plot.h"
-
-#include "agg_conv_stroke.h"
-#include "agg_conv_dash.h"
-#include "agg_conv_contour.h"
-#include "agg_vcgen_markers_term.h"
-#include "agg_bounding_rect.h"
diff --git a/agg-plot/plot.h b/agg-plot/plot.h
index 3c0ded21..48849548 100644
--- a/agg-plot/plot.h
+++ b/agg-plot/plot.h
@@ -45,7 +45,12 @@ class plot {
};
public:
- plot() : m_elements(), m_trans(), m_bbox_updated(true) { };
+ plot() : m_elements(), m_trans(), m_bbox_updated(true) {
+ m_title_size = 32;
+ m_title = new char[m_title_size];
+ m_title[0] = 0;
+ };
+
virtual ~plot()
{
#ifdef DEBUG_PLOT
@@ -57,8 +62,25 @@ public:
container& d = m_elements[j];
resource_manager::dispose(d.vs);
}
+
+ delete [] m_title;
};
+ void set_title(const char *text) {
+ unsigned int len = strlen(text);
+
+ if (m_title_size < len + 1)
+ {
+ delete [] m_title;
+ m_title = new char[len+1];
+ m_title_size = len+1;
+ }
+
+ memcpy(m_title, text, len+1);
+ };
+
+ const char *get_title() const { return m_title; };
+
void add(VertexSource* vs, agg::rgba8 color, bool outline = false)
{
container d(vs, color, outline);
@@ -67,14 +89,11 @@ public:
resource_manager::acquire(vs);
};
- virtual void draw(canvas &canvas)
- {
- trans_matrix_update();
- draw_elements(canvas);
- };
+ virtual void draw(canvas &canvas);
protected:
void draw_elements(canvas &canvas);
+ void draw_title(canvas& canvas);
void calc_bounding_box();
virtual void trans_matrix_update();
@@ -87,8 +106,44 @@ protected:
bool m_bbox_updated;
double m_x1, m_y1;
double m_x2, m_y2;
+
+ char *m_title;
+ unsigned int m_title_size;
};
+template <class VS, class RM>
+void plot<VS,RM>::draw(canvas &canvas)
+{
+ trans_matrix_update();
+ draw_title(canvas);
+ draw_elements(canvas);
+};
+
+template <class VS, class RM>
+void plot<VS,RM>::draw_title(canvas &canvas)
+{
+ double xt = 0.5, yt = 1;
+
+ agg::trans_affine m;
+ this->viewport_scale(m);
+ canvas.scale(m);
+
+ agg::gsv_text title;
+ agg::conv_stroke<agg::gsv_text> titlestroke(title);
+
+ title.size(12.0);
+ title.text(m_title);
+ titlestroke.width(1.0);
+
+ m.transform(&xt, &yt);
+
+ xt += -title.text_width() / 2;
+ yt += 10.0;
+
+ title.start_point(xt, yt);
+ canvas.draw(titlestroke, agg::rgba(0, 0, 0));
+}
+
template<class VS, class RM>
void plot<VS,RM>::draw_elements(canvas &canvas)
{
diff --git a/agg-plot/test.cpp b/agg-plot/test.cpp
deleted file mode 100644
index 60acf26d..00000000
--- a/agg-plot/test.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-#include "platform/agg_platform_support.h"
-
-#include "utils.h"
-#include "plot.h"
-#include "drawables.h"
-#include "trans.h"
-
-extern void platform_support_prepare();
-
-enum flip_y_e { flip_y = true };
-
-class the_application : public agg::platform_support
-{
-public:
- the_application(agg::pix_format_e format, bool flip_y) :
- agg::platform_support(format, flip_y)
- { };
-
- virtual ~the_application() { };
-
- virtual void on_draw()
- {
- canvas canvas(rbuf_window(), width(), height(), agg::rgba(1.0, 1.0, 1.0));
-
- canvas.clear();
-
- my::path tri;
-
- agg::path_storage& p = tri.get_path();
- p.move_to(0.0, 0.0);
- p.line_to(1.0, 0.0);
- p.line_to(0.5, 0.8);
- p.close_polygon();
-
- trans::resize ttri(tri);
-
- trans::stroke tris(ttri, 8.0);
- trans::stroke tris2(tris, 1.0);
-
- my::ellipse ell(1.5, 1.5, 0.3, 0.3);
- trans::resize tell(ell);
- trans::stroke ells(tell);
-
- my::text txt(-0.5, 1.5);
- txt.set_text("Hello world!");
-
- plot<vertex_source> plot;
- plot.add(&ttri, agg::rgba8(0,180,0));
- plot.add(&tris, agg::rgba8(0,0,120));
- plot.add(&tris2, agg::rgba8(0,0,0));
-
- plot.add(&tell, agg::rgba8(180,0,0));
- plot.add(&ells, agg::rgba8(0,0,0));
-
- plot.add(&txt, agg::rgba8(120,0,0));
-
- plot.draw(canvas);
- }
-};
-
-int main(int argc, char *argv[])
-{
- platform_support_prepare();
-
- the_application app(agg::pix_format_bgr24, flip_y);
- app.caption("GSL shell plot - TESTING");
-
- if(app.init(300, 300, agg::window_resize))
- {
- app.run();
- }
-
- return 0;
-};
diff --git a/agg-plot/units-plot.h b/agg-plot/units-plot.h
index ad0b2b07..0a5067d1 100644
--- a/agg-plot/units-plot.h
+++ b/agg-plot/units-plot.h
@@ -163,6 +163,7 @@ void units_plot<VS,RM>::draw(canvas &canvas)
{
trans_matrix_update();
draw_axis(canvas);
+ this->draw_title(canvas);
this->draw_elements(canvas);
};
generated by cgit v1.2.3 (git 2.46.0) at 2025年10月02日 12:00:33 +0000

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