Commit 2d1320b5 authored by Pascal Noisette's avatar Pascal Noisette

Objet render_svg (à parametrer)

parent e6aa3bd4
#include "render_svg.hpp"
void Svg::rectangle()
{
sprintf(_conteneur,"<rect title='container' width='%ld' height='%ld' x='%ld' y='%ld' fill='rgb(%d,%d,%d)' />",_w, _h, _x,_y,_r,_g,_b);
afficher(_conteneur);
}
void Svg::afficher(char* s)
{
printf(s);
}
void Svg::init()
{
char * entete = "<?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";
afficher(entete);
}
void Svg::end()
{
char* end_of_document = "</svg>";
afficher(end_of_document);
}
void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h)
{
_r=47;
_g=54;
_b=153;
_w=(unsigned long)w;
_h=(unsigned long)h;
_x=(unsigned long)x;
_y=(unsigned long)y;
rectangle();
}
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)100;
_x=(unsigned long)start;
_y=(unsigned long)50;
rectangle();
}
#ifndef RENDER_SGV
#define RENDER_SVG
#include <stdio.h>
typedef long Element_count ;
typedef double Element_pos;
typedef double Element_col;
class Svg{
private:
char _conteneur[2048];
unsigned char _r,_g,_b;
unsigned long _x,_y,_w,_h;
void afficher(char*s);
void rectangle();
public:
/*!
* \brief SVG header buiding
*/
void init();
/*!
* \brief SVG bottom file buiding
*/
void end();
/*!
* \brief Draw a container according to the parameters
* \param x the x position of the container
* \param y the y position of the container
* \param w the width of the container
* \param h the height of the container
*/
void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) ;
/*!
* \brief Draw a state of the trace.
* \param r the red color rate of the state.
* \param g the green color rate of the state.
* \param b the blue color rate of the state.
* \param start the beginning time of the state.
* \param end the ending time of the state.
* \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) ;
};
#endif// RENDER_SGV
test_svg.o: test_svg.cpp
g++ -c -g -Wall test_svg.cpp -o test_svg.o
render_svg.o: ../src/render_svg.cpp ../src/render_svg.hpp
g++ -c -g -Wall ../src/render_svg.cpp -o render_svg.o
test_svg: test_svg.o render_svg.o
g++ -g -Wall render_svg.o test_svg.o -o test_svg
\ No newline at end of file
#include <iostream>
#include "../src/render_svg.hpp"
using namespace std;
int main()
{
Svg s;
s.init();
s.draw_container(0,100,100,100);
s.draw_state(0 , 150, 0, 50,50,50);
s.draw_state(400, 750, 0, 0xff,0xcc,33);
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