| René Nyffenegger's collection of things on the web | |
|
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Shape [Ming wrapper class | ||
The sourceShape.h
#ifndef SHAPE_H__
#define SHAPE_H__
#include "ming.h"
#include "Bitmap.h"
#include "Character_.h"
#include "Gradient.h"
#include "GradientFill.h"
#include "Fill_.h"
class Shape : public Character_ {
friend class Button;
friend class Movie;
friend class MovieClip;
friend class Morph;
friend class Bitmap;
friend class Text;
public:
Shape();
void DrawFilledRectWithBorder(
float x1, float y1, float x2, float y2,
byte fill_r, byte fill_g, byte fill_b, byte fill_a,
unsigned short line_width,
byte line_r, byte line_g, byte line_b, byte line_a
);
void LineStyle(unsigned short width, byte r, byte g, byte b, byte a=0xff);
// Clears Line Style
void LineStyle();
void FillStyle(byte r, byte g, byte b, byte a=0xff);
GradientFill GetRadial(Gradient const&);
GradientFill GetLinear(Gradient const&);
//void Fill(GradientFill const&);
void Fill(Fill_ const&);
// Clears FillStyle
void FillStyle();
void LineTo(float x, float y);
void Line (float dx, float dy);
void MoveTo(float x, float y);
void Move (float dx, float dy);
void FillClipped(Bitmap const&);
void FillTiled (Bitmap const&);
void Circle(float r);
void Fill(SWFFill);
/* fill_type is any of
o SWFFILL_TILED_BITMAP
o SWFFILL_CLIPPED_BITMAP
*/
void Fill(Bitmap const&, int fill_type);
private:
SWFShape shape_;
Shape(SWFShape, bool use_right_fill);
bool use_right_fill_;
protected:
// HACK?
virtual SWFBlock_s* swf_block() const;
};
#endif // SHAPE_H__
Shape.cpp
#include "Shape.h"
#include "Text.h"
#include "SWFmovie.h"
Shape::Shape() {
shape_ = newSWFShape();
use_right_fill_ = true;
}
Shape::Shape(SWFShape s, bool use_right_fill) {
shape_=s;
use_right_fill_ = use_right_fill;
}
void Shape::DrawFilledRectWithBorder(
float x1, float y1, float x2, float y2,
byte fill_r, byte fill_g, byte fill_b, byte fill_a,
unsigned short line_width,
byte line_r, byte line_g, byte line_b, byte line_a
) {
LineStyle(line_width, line_r, line_g, line_b);
FillStyle(fill_r, fill_g, fill_b, fill_a);
MoveTo(x1, y1);
LineTo(x1, y2);
LineTo(x2, y2);
LineTo(x2, y1);
LineTo(x1, y1);
}
void Shape::LineTo(float x, float y) {
SWFShape_drawLineTo(shape_, x, y);
}
void Shape::Line(float dx, float dy) {
SWFShape_drawLine(shape_, dx, dy);
}
void Shape::MoveTo(float x, float y) {
SWFShape_movePenTo(shape_, x, y);
}
void Shape::Move(float dx, float dy) {
SWFShape_movePen(shape_, dx, dy);
}
void Shape::LineStyle(unsigned short width, byte r, byte g, byte b, byte a) {
SWFShape_setLine(shape_, width, r, g, b, a);
}
void Shape::LineStyle() {
SWFShape_setLine(shape_, 0, 0, 0, 0, 0);
}
/* TODO: return SWFFill or so
TODO: FillStyle better named Fill ???
(according to Fill(Bitmap const&...)
*/
void Shape::FillStyle(byte r, byte g, byte b, byte a) {
SWFFill fill = SWFShape_addSolidFill(shape_, r, g, b, a);
Fill(fill);
}
GradientFill Shape::GetRadial(Gradient const& g) {
SWFFill fill = SWFShape_addGradientFill(shape_, g.gradient_, SWFFILL_RADIAL_GRADIENT);
return GradientFill(fill);
}
GradientFill Shape::GetLinear(Gradient const& g) {
SWFFill fill = SWFShape_addGradientFill(shape_, g.gradient_, SWFFILL_LINEAR_GRADIENT);
return GradientFill(fill);
}
void Shape::FillStyle() {
/* It seems that Morphs need *Left* fills.
All that is beyond me....! */
if (use_right_fill_) { SWFShape_setRightFill(shape_, 0); }
else { SWFShape_setLeftFill (shape_, 0); }
}
void Shape::Circle(float r) {
SWFShape_drawCircle(shape_, r);
}
void Shape::Fill(Bitmap const& bmp, int fill_type) {
SWFFill fill=SWFShape_addBitmapFill(shape_, bmp.bitmap_, fill_type);
Fill(fill);
}
void Shape::FillTiled(Bitmap const& bmp) {
Fill(bmp, SWFFILL_TILED_BITMAP);
}
void Shape::FillClipped(Bitmap const& bmp) {
Fill(bmp, SWFFILL_CLIPPED_BITMAP);
}
/* TODO: remove this method, use Fill(Fill_ const&) instead */
void Shape::Fill(SWFFill fill) {
if (use_right_fill_) {
SWFShape_setRightFill(shape_, fill);
}
else {
SWFShape_setLeftFill(shape_, fill);
}
}
void Shape::Fill(Fill_ const& f) {
if (use_right_fill_) {
SWFShape_setRightFill(shape_, f.fill_);
}
else {
SWFShape_setLeftFill(shape_, f.fill_);
}
}
SWFBlock_s* Shape::swf_block() const {
return reinterpret_cast<SWFBlock_s*>(shape_);
}
Exmamples
The following classes demonstrate this class:
|