Channels ▼

Flash, Ming, & C++

December, 2004: Flash, Ming, & C++

Listing 2

#include <cmath>    //For M_PI and similar constants
#include <mingpp.h>
class Shape{
unsigned short line_sz;
int line_col,line_op;
int fill_col,fill_op;
Shape(unsigned short s=1,int c1=0x000000,int c2=0x000000,int o1=100,
  int o2=100)
/** Splits a RGB colour into its components */
static void get_rgb(const int col,int &r,int &g,int &b){
/** Convert a 0..100 opacity to 0x00 to 0xff*/
static int get_opacity(const int op){
if(op>=100)return 0xff;
if(op<=0)return 0;
return (op*256)/100;
/** Initialize pen : called before other drawing functions */
void init_pen(SWFShape *shape,float sx,float sy)const{
int r,g,b;get_rgb(line_col,r,g,b);
/** Draw arc, anticlockwise */
void draw_arc_helper_ac(SWFShape *shape,float sx,float sy,double sa,
                                         double ea,float xr,float yr)const{
const double PIBy4=M_PI_4;
const double PIBy8=M_PI_4/2.0;
double control_xr=xr/cos(PIBy8);
double control_yr=yr/cos(PIBy8);
    double ma;
    if((ea-sa)>PIBy4){  //Draw a 45 degree segment
        ma=sa+PIBy8;    //Add 22.5 degrees
        sa+=PIBy4;      //Add 45 degrees
    else{               //Final segment
    double cx=sx+(cos(ma)*control_xr);
    double cy=sy-(sin(ma)*control_yr);
    double ex=sx+(cos(sa)*xr);
    double ey=sy-(sin(sa)*yr);
/** Draw a pie-slice */
void draw_pie_slice(SWFSprite *movieclip,const float sx,const float sy,
    const double sa,const double ea,const float xr,const float yr)const{
float x=sx+(cos(sa)*xr);
float y=sy-(sin(sa)*yr);
SWFShape *shape=new SWFShape;
int r,g,b;get_rgb(fill_col,r,g,b);


Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.