Pen now uses a std::vector<PenScanline> instead of a raw pointer to PenScanline[] array.

This commit is contained in:
David Capello 2010-11-06 20:31:30 -03:00
parent d0a694cbb1
commit 18b0f903d7
3 changed files with 11 additions and 17 deletions

View File

@ -21,8 +21,6 @@
#include <allegro/base.h> #include <allegro/base.h>
#include <math.h> #include <math.h>
#include "gui/jbase.h" // TODO remove this reference
#include "raster/algo.h" #include "raster/algo.h"
#include "raster/pen.h" #include "raster/pen.h"
#include "raster/image.h" #include "raster/image.h"
@ -33,7 +31,6 @@ Pen::Pen()
m_size = 1; m_size = 1;
m_angle = 0; m_angle = 0;
m_image = NULL; m_image = NULL;
m_scanline = NULL;
regenerate_pen(); regenerate_pen();
} }
@ -44,7 +41,6 @@ Pen::Pen(PenType type, int size, int angle)
m_size = size; m_size = size;
m_angle = angle; m_angle = angle;
m_image = NULL; m_image = NULL;
m_scanline = NULL;
regenerate_pen(); regenerate_pen();
} }
@ -89,10 +85,7 @@ void Pen::clean_pen()
m_image = NULL; m_image = NULL;
} }
if (m_scanline) { m_scanline.clear();
jfree(m_scanline);
m_scanline = NULL;
}
} }
static void algo_hline(int x1, int y, int x2, void *data) static void algo_hline(int x1, int y, int x2, void *data)
@ -151,7 +144,7 @@ void Pen::regenerate_pen()
} }
} }
m_scanline = jnew(PenScanline, m_size); m_scanline.resize(m_size);
for (y=0; y<m_size; y++) { for (y=0; y<m_size; y++) {
m_scanline[y].state = false; m_scanline[y].state = false;

View File

@ -20,6 +20,7 @@
#define RASTER_PEN_H_INCLUDED #define RASTER_PEN_H_INCLUDED
#include "pen_type.h" #include "pen_type.h"
#include <vector>
class Image; class Image;
@ -30,12 +31,6 @@ struct PenScanline
class Pen class Pen
{ {
PenType m_type; /* type of pen */
int m_size; /* size (diameter) */
int m_angle; /* angle in degrees 0-360 */
Image* m_image; /* image of the pen */
PenScanline* m_scanline;
public: public:
Pen(); Pen();
Pen(PenType type, int size, int angle); Pen(PenType type, int size, int angle);
@ -46,7 +41,7 @@ public:
int get_size() const { return m_size; } int get_size() const { return m_size; }
int get_angle() const { return m_angle; } int get_angle() const { return m_angle; }
Image* get_image() { return m_image; } Image* get_image() { return m_image; }
PenScanline* get_scanline() { return m_scanline; } const std::vector<PenScanline>& get_scanline() const { return m_scanline; }
void set_type(PenType type); void set_type(PenType type);
void set_size(int size); void set_size(int size);
@ -55,6 +50,12 @@ public:
private: private:
void clean_pen(); void clean_pen();
void regenerate_pen(); void regenerate_pen();
PenType m_type; /* type of pen */
int m_size; /* size (diameter) */
int m_angle; /* angle in degrees 0-360 */
Image* m_image; /* image of the pen */
std::vector<PenScanline> m_scanline;
}; };
#endif #endif

View File

@ -48,7 +48,7 @@ public:
void transformPoint(IToolLoop* loop, int x, int y) void transformPoint(IToolLoop* loop, int x, int y)
{ {
Pen* pen = loop->getPen(); Pen* pen = loop->getPen();
register PenScanline *scanline = pen->get_scanline(); std::vector<PenScanline>::const_iterator scanline = pen->get_scanline().begin();
register int h = pen->get_size(); register int h = pen->get_size();
register int c = h/2; register int c = h/2;