class::draw::DrawingAttributes

class draw::DrawingAttributes
  : public api::InfoObject

This class contains the information needed to draw various Drawing objects on a bitmap.

This class is passed to Drawing::draw() to render graphics on a bitmap.

The following code will draw an rectangle in the middle of a 64x64 pixel bitmap.

#include <sapi/sgfx.hpp>
#include <sapi/draw.hpp>

Bitmap bitmap(64,64); //64x64 pixel bitmap
DrawingAttributes attributes;

attributes << bitmap; //apply bitmap to attributes

Rectangle().draw(attributes + DrawingPoint(250,250) + DrawingArea(500,500));

A DrawingAttributes object is always passed to the Drawing::draw() method.

The + operator when adding a DrawingPoint will create a new DrawingAttributes object that starts at the specified point. The coordinates are the width of the bitmap / 1000.

The + operator when adding a DrawingArea will scale the region of the DrawingAttributes based on the size of the bitmap where 1000 represents full width and height.

So in the example above, the top left corner of the rectangle is mapped to 16,16 (64*2501000=16). The width and height of the rectangle are both 32 (64*5001000=32).

These operators allow the cascading of drawing objects as the region scales. For example, if we create a DrawingAttributes object that is already region limited, the + operators will operate within the existing region.

Bitmap bitmap(64,64); //64x64 pixel bitmap
DrawingAttributes attributes;

DrawingRegion region(DrawingPoint(0,0), DrawingArea(500,500));
attributes << bitmap << region; //apply bitmap and region to attributes

//rectangle will be 500/1000 of 500/1000 of the area of the bitmap
Rectangle().draw(attributes + DrawingArea(500,500));

In this second example, because the DrawingAttributes region was already set to a subregion of the bitmap, the + operator with the DrawingArea scales the region down by 5001000. So the rectangle is 16,16 (64*5001000 * 5001000).

Using these operators to cascade is great for creating compound drawing objects like a button.

class Button: public Drawing {
public:
 void draw(const DrawingAttributes & attributes){
   RoundedRectangle().draw(attributes); //files entire attributes region

   //The Icon is scaled down to half the width/height and centered
   Icon().set_name("OK").draw(attributes + DrawingPoint(250,250) + DrawingArea(500,500));

 }
};

Summary

DrawingAttributes()

DrawingAttributes(

const drawing_attr_t & attr
)

DrawingAttributes(

sgfx::Bitmap & bitmap
)

DrawingAttributes(

sgfx::Bitmap & bitmap,
const DrawingRegion & region
)

DrawingArea area() const

drawing_attr_t & attr()

sgfx::Bitmap & bitmap() const

sg_area_t calc_dim_on_bitmap() const

drawing_size_t calc_height(

drawing_size_t v
) const

sg_size_t calc_height_on_bitmap() const

sg_size_t calc_height_on_bitmap(

drawing_size_t value
) const

sg_point_t calc_point_on_bitmap() const

sg_region_t calc_region_on_bitmap() const

drawing_area_t calc_square_h(

drawing_size_t v
) const

drawing_size_t calc_width(

drawing_size_t v
) const

sg_size_t calc_width_on_bitmap() const

sg_size_t calc_width_on_bitmap(

drawing_size_t value
) const

drawing_area_t calculate_square(

drawing_size_t v
) const

drawing_area_t calculate_square_height(

drawing_size_t v
) const

drawing_area_t calculate_square_width(

drawing_size_t v
) const

drawing_size_t height() const

bool is_bitmap_available() const

bool is_valid() const

[operator drawing_attr_t](#classdraw_1_1_drawing_attributes_1a5fad1a118b7987d3e95888be1a81f69c)()

DrawingAttributes operator+(

const drawing_point_t & d
) const

DrawingAttributes operator+(

const drawing_area_t & d
) const

DrawingAttributes operator+(

const DrawingPoint & d
) const

DrawingAttributes operator+(

const DrawingArea & d
) const

DrawingAttributes operator+(

DrawingRegion region
) const

DrawingAttributes & operator<<(

sgfx::Bitmap & bitmap
)

DrawingAttributes & operator<<(

const DrawingRegion & region
)

DrawingAttributes & operator<<(

const DrawingPoint & point
)

DrawingAttributes & operator<<(

const DrawingArea & area
)

DrawingPoint point() const

DrawingRegion region() const

sgfx::Bitmap * scratch() const

void set(

sgfx::Bitmap & b,
drawing_point_t p,
drawing_area_t d,
sgfx::Bitmap * scratch
)

void set_bitmap(

sgfx::Bitmap & b
)

void set_dim(

drawing_area_t d
)

void set_dim(

drawing_size_t w,
drawing_size_t h
)

void set_point(

drawing_point_t p
)

void set_point(

drawing_int_t x,
drawing_int_t y
)

void set_scratch(

sgfx::Bitmap * b
)

drawing_size_t width() const

drawing_int_t x() const

drawing_int_t y() const

static sg_area_t calc_dim_on_bitmap(

const DrawingAttributes & attr
)

static sg_size_t calc_height_on_bitmap(

const DrawingAttributes & attr
)

static sg_size_t calc_height_on_bitmap(

const DrawingAttributes & attr,
drawing_size_t value
)

static sg_point_t calc_point_on_bitmap(

const DrawingAttributes & attr
)

static sg_region_t calc_region_on_bitmap(

const DrawingAttributes & attr
)

static sg_size_t calc_width_on_bitmap(

const DrawingAttributes & attr
)

static sg_size_t calc_width_on_bitmap(

const DrawingAttributes & attr,
drawing_size_t value
)

static drawing_size_t scale()

Members

DrawingAttributes()

Construct an object


DrawingAttributes(

const drawing_attr_t & attr
)

Construct an object from a drawing_attr_t


DrawingAttributes(

sgfx::Bitmap & bitmap
)


DrawingAttributes(

sgfx::Bitmap & bitmap,
const DrawingRegion & region
)


DrawingArea area() const

Returns a copy of the dimensions.


drawing_attr_t & attr()

Access the underlying attr object


sgfx::Bitmap & bitmap() const

Access the bitmap


sg_area_t calc_dim_on_bitmap() const

drawing_size_t calc_height(

drawing_size_t v
) const

Calculate the scaled height relative to the height of the DrawingAttributes object.

Parameters

  • v The value to calculate

This method will calculate a height relative to the heigh of the object and the scale() value. For example, if the current object maps to a region of a bitmap height of 500 pixels, this method will return a drawing height that will be from 0 to 500 pixels with v being from 0 to DrawingAttributes::scale().


sg_size_t calc_height_on_bitmap() const

sg_size_t calc_height_on_bitmap(

drawing_size_t value
) const


sg_point_t calc_point_on_bitmap() const

sg_region_t calc_region_on_bitmap() const

drawing_area_t calc_square_h(

drawing_size_t v
) const


drawing_size_t calc_width(

drawing_size_t v
) const

Calculate the scaled width (width of object on the bitmap)


sg_size_t calc_width_on_bitmap() const

sg_size_t calc_width_on_bitmap(

drawing_size_t value
) const


drawing_area_t calculate_square(

drawing_size_t v
) const

Calculate dimensions that will map to the bitmap as a square.

Parameters

  • v The maximum width or height

Returns

Square dimensions


drawing_area_t calculate_square_height(

drawing_size_t v
) const

Calculate dimensions that will map to the bitmap as a square with the given height.

Parameters

  • v The height (width will be calculated)

Returns

Square dimensions


drawing_area_t calculate_square_width(

drawing_size_t v
) const

Calculate dimensions that will map to the bitmap as a square with the given width.

Parameters

  • v The width (height will be calculated)

Returns

Square dimensions


drawing_size_t height() const

Return the height


bool is_bitmap_available() const

Checks to see if bitmap is available.


bool is_valid() const

operator drawing_attr_t()

Return the underlying drawing_attr_t


DrawingAttributes operator+(

const drawing_point_t & d
) const

Add a drawing_point_t offset

This operated can be used to create a subregion within the object when used with operation+ (drawing_area_t).

For example:

DrawingAttributes attr0;
DrawingAttributes attr1;
attr0 = attr1 + DrawingPoint(250,250) + DrawingArea(500,500);

When mapped to the same bitmap, attr0 will be half the height and half the width of attr1. attr0 and attr1 will have the same center point.

These operators can be used to draw sub-drawings on drawings. The following example draws a rectangles recursively in an object.

void draw_rect_recursive(const DrawingAttributes & attr){
 static sg_color_t color = 0;
 Rectangle().set_color(color++ % 1).draw(attr + DrawingPoint(250,250) + DrawingArea(500,500);
 if( attr.width() > 100 ){
   draw_rect_recursive(attr);
 }
}

DrawingAttributes operator+(

const drawing_area_t & d
) const

Update the dimension (must come after adding drawing_point_t)


DrawingAttributes operator+(

const DrawingPoint & d
) const


DrawingAttributes operator+(

const DrawingArea & d
) const


DrawingAttributes operator+(

DrawingRegion region
) const


DrawingAttributes & operator<<(

sgfx::Bitmap & bitmap
)


DrawingAttributes & operator<<(

const DrawingRegion & region
)


DrawingAttributes & operator<<(

const DrawingPoint & point
)


DrawingAttributes & operator<<(

const DrawingArea & area
)


DrawingPoint point() const

Returns a copy of the position.


DrawingRegion region() const

Returns a copy of the region.


sgfx::Bitmap * scratch() const

Access the scratch bitmap


void set(

sgfx::Bitmap & b,
drawing_point_t p,
drawing_area_t d,
sgfx::Bitmap * scratch
)

Assign the bitmap point and dimensions


void set_bitmap(

sgfx::Bitmap & b
)

Set the bitmap


void set_dim(

drawing_area_t d
)

Set the dimensions. Both width and height are from 0 to 1000.


void set_dim(

drawing_size_t w,
drawing_size_t h
)

Set the dimensions. Both width and height are from 0 to 1000.


void set_point(

drawing_point_t p
)

Set the location. Both x and y are from 0 to 1000.


void set_point(

drawing_int_t x,
drawing_int_t y
)

Set the location. Both x and y are from 0 to 1000.


void set_scratch(

sgfx::Bitmap * b
)

Set the scratch bitmap


drawing_size_t width() const

Return the width


drawing_int_t x() const

Return the x value


drawing_int_t y() const

Return the y value


static sg_area_t calc_dim_on_bitmap(

const DrawingAttributes & attr
)

Return the dimensions (in pixels) if any Element is drawn on the specified bitmap


static sg_size_t calc_height_on_bitmap(

const DrawingAttributes & attr
)


static sg_size_t calc_height_on_bitmap(

const DrawingAttributes & attr,
drawing_size_t value
)


static sg_point_t calc_point_on_bitmap(

const DrawingAttributes & attr
)


static sg_region_t calc_region_on_bitmap(

const DrawingAttributes & attr
)


static sg_size_t calc_width_on_bitmap(

const DrawingAttributes & attr
)


static sg_size_t calc_width_on_bitmap(

const DrawingAttributes & attr,
drawing_size_t value
)


static drawing_size_t scale()

This value determines how all objects are scaled.

The default value is 1000. This means a value of 500 is half the target bitmap.

sg_size_t * drawing_size_t / scale() = sg_size_t (drawing_size_t cancels with scale())


X

Thanks for Coming!

Subscribe to news and updates