Commit b22ce8f8 authored by Pascal Noisette's avatar Pascal Noisette

a pretty arrow

parent 2a729774
......@@ -6,14 +6,39 @@ using namespace std;
void Svg::rectangle(){
_buffer << "<rect title='container' width='" << _w
<<"' height='"<< _h
<<"' x='" << _x
<<"' y='" << _y
<<"' x='" << _x1
<<"' y='" << _y1
<<"' fill='rgb("<<_r<<","<<_g<<","<<_b
<<")'/>";
print();
}
void Svg::line(){
_buffer << "<line title='line' x1='" << _x1
<<"' y1='" << _y1
<<"' x2='" << _x2
<<"' y2='" << _y2
<<"' />";
print();
}
void Svg::triangle(){
_buffer << "<polyline title='triangle' class='triangle' points='"
<< _x1 << "," << _y1
<< " " << _x2 << "," << _y2
<< " " << _x3 << "," << _y3
<<"' />";
print();
}
void Svg::print(){
if (_buffer.str().size()>BUFFER_SIZE){
......@@ -31,7 +56,25 @@ void Svg::init(const char *path){
if (_svg_file.is_open()==false){
std::cerr<<"unable to open file";
}
_buffer << "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' width='1280' height='728' id='svg2'>\n\t<style type='text/css' id='stylecss' >\n\t\trect:hover\n\t\t\t{\n\t\t\t\tfill:#8fbbd0;\n\t\t\t}\n\t</style>\n\t<desc>Rectangles</desc>\n";
_buffer << "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n"
<< "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n"
<< "<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' width='1280' height='728' id='svg2'>\n"
<< "\t<style type='text/css' id='stylecss' >\n"
<< "\t\trect:hover\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:#8fbbd0;\n"
<< "\t\t\t}\n"
<< "\t\tline\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:white;stroke:black;stroke-width:1\n"
<< "\t\t\t}\n"
<< "\t\t#triangle\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:black;stroke:black;stroke-width:1\n"
<< "\t\t\t}\n"
<< "\t</style>\n"
<< "\t<desc>Rectangles</desc>\n";
print();
}
......@@ -49,20 +92,41 @@ void Svg::draw_container(const Element_pos x, const Element_pos y, const Element
_b=0xcc;
_w=(unsigned long)w;
_h=(unsigned long)h;
_x=(unsigned long)x;
_y=(unsigned long)y;
_x1=(unsigned long)x;
_y1=(unsigned long)y;
rectangle();
}
void Svg::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){
_x1=(unsigned long)start_time;
_x2=(unsigned long)end_time;
_y1=(unsigned long)start_height;
_y2=(unsigned long)end_height;
line();
_x1=(unsigned long)end_time;
_x2=(unsigned long)end_time;
_x3=(unsigned long)end_time+ARROWSIZE;
_y1=(unsigned long)end_height+ARROWSIZE;
_y2=(unsigned long)end_height-ARROWSIZE;
_y3=(unsigned long)end_height;
triangle();//spike
}
void Svg::draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b){
_r=(unsigned char)r;
_g=(unsigned char)g;
_b=(unsigned char)b;
_w=(unsigned long)(end-start);
_h=(unsigned long)LEVEL - 10;
_x=(unsigned long)start;
_y=(unsigned long)level*LEVEL;
_h=(unsigned long)LEVEL - MARGIN;
_x1=(unsigned long)start;
_y1=(unsigned long)level*LEVEL;
rectangle();
}
......@@ -2,17 +2,18 @@
#define RENDER_SVG
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#define BUFFER_SIZE 2048 //character number stored before flush the _buffer
#define LEVEL 110 //distance between two containers
#define MARGIN 10 //distance between two object
#define ARROWSIZE 4 //spike size
typedef unsigned long Element_count ;
typedef double Element_pos;
typedef unsigned int Element_col;
typedef unsigned char Element_col;
class Svg{
......@@ -20,11 +21,16 @@ class Svg{
private:
std::ostringstream _buffer;
std::string _object_class;
std::ofstream _svg_file;
unsigned int _r,_g,_b;
unsigned long _x,_y,_w,_h;
void print();
unsigned int _r,_g,_b; // 0 < _r,_g,_b < 255 and displayed as int
unsigned long _w,_h;
unsigned long _x1,_y1,_x2,_y2,_x3,_y3;
inline void print();
inline void rectangle();
inline void line();
inline void triangle();
public:
/*!
* \brief SVG header buiding
......@@ -56,6 +62,13 @@ public:
* \param level refer to the container which state belongs to.
*/
void draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b) ;
/*!
* \brief Draw an arrow
*
*/
void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);
};
#endif // RENDER_SVG
......@@ -17,6 +17,8 @@ int main()
s.draw_state(400, 750, 2, 0xff,0xcc,33);
s.draw_state(70, 300, 3, 0xff,0xcc,33);
s.draw_arrow(100,700,LEVEL*1,LEVEL*3);
s.draw_arrow(200,400,LEVEL*2,LEVEL*2);
s.end();
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment