Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

OPIE.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OPIE.CPP

Go to the documentation of this file.
00001 //Filename    : OPIE.CPP
00002 //Description : Object Pie Chart
00003 
00004 #include <math.h>
00005 
00006 #include <ALL.H>
00007 #include <VGAFUN.H>
00008 #include <OVGA.H>
00009 #include <OINFO.H>
00010 #include <OICONRES.H>
00011 #include <OGAME.H>
00012 #include <OPIE.H>
00013 
00014 #define PI_OVER180 1.74532925199433E-002
00015 
00016 //-------- Begin of function PieChart::init() ----------//
00021 void PieChart::init(char* slotIconPtr) {
00022     if( slotIconPtr )
00023         slot_icon_ptr = slotIconPtr;
00024     else
00025         slot_icon_ptr = icon_sys.read("PIESLOT1");
00026 
00027     box_width = *((short*)slot_icon_ptr);
00028 
00029     pie_radius = box_width/2-3;
00030 
00031     //-------- create table of arc points -----------//
00032 
00033     int   i=0;
00034     float curRadian;
00035 
00036     curRadian = PI_OVER180 * 180;                   // start from 180" degree
00037 
00038     for( i=0 ; i<MAX_DEGREE ; curRadian+=PI_OVER180, i++ ) {
00039         pie_point_table[i].x = (box_width>>1) + sin(curRadian) * pie_radius;
00040         pie_point_table[i].y = (box_width>>1) + cos(curRadian) * pie_radius;
00041 
00042         if( i>=2 ) {                                  // fill gaps between lines
00043             if( pie_point_table[i-1].x == pie_point_table[i-2].x &&
00044                 pie_point_table[i-1].y == pie_point_table[i-2].y &&
00045                 pie_point_table[i].x   -  pie_point_table[i-2].x &&
00046                 pie_point_table[i].y   -  pie_point_table[i-2].y ) {
00047                 pie_point_table[i-1].x = pie_point_table[i].x;
00048                 pie_point_table[i-1].y = pie_point_table[i-2].y;
00049             }
00050         }
00051     }
00052 }
00053 
00054 //-------- End of function PieChart::init() ----------//
00055 
00056 //-------- Begin of function PieChart::init_image ----------//
00063 void PieChart::init_image(int backColor) {
00064     if( backColor == -1 )
00065         backColor = V_BACKGROUND;
00066 
00067     vga.init_image( box_width, box_width );
00068 
00069     IMGputIcon( 0, 0, slot_icon_ptr );
00070 
00071     last_degree= -1;                                // no last degree, first time
00072 }
00073 
00074 //-------- End of function PieChart::init_image ----------//
00075 
00076 //-------- Begin of function PieChart::draw_slice ----------//
00083 void PieChart::draw_slice(float sliceShare, int sliceColor) {
00084     err_if( sliceShare<0 || sliceShare>100 || sliceShare==infinite_number )
00085         err_here();
00086 
00087     int i, lastX= -1, lastY = -1, pieCentre = box_width>>1;
00088 
00089     float endDegree = last_degree + (float) MAX_DEGREE * sliceShare / 100;
00090     endDegree = min( endDegree, MAX_DEGREE-1 );
00091 
00092     // last_degree+1 = current starting degree
00093     PiePoint *curPoint = pie_point_table + (int)last_degree+1;
00094 
00095     //---------- draw the slice -------------//
00096 
00097     for( i=last_degree+1 ; i<=endDegree ; i++, curPoint++ ) {
00098         if( curPoint->x != lastX || curPoint->y != lastY ) {
00099             IMGline( pieCentre, pieCentre, curPoint->x, curPoint->y, sliceColor );
00100 
00101             lastX = curPoint->x;
00102             lastY = curPoint->y;
00103         }
00104     }
00105 
00106     last_degree = endDegree;                        // degree of the last drawn slice
00107 }
00108 
00109 //-------- End of function PieChart::draw_slice ----------//
00110 
00111 //-------- Begin of function PieChart::put_image ----------//
00118 void PieChart::put_image(int x, int y) {
00119     if( last_degree < MAX_DEGREE-1 )
00120         draw_slice( 100L * (MAX_DEGREE - last_degree+1) / 360, V_WHITE );
00121 
00122     vga.put_image( x, y );                          // +3 = space between pie and panel down
00123     vga.deinit_image();
00124 }
00125 
00126 //-------- End of function PieChart::put_image ----------//

Generated on Fri Aug 23 01:38:10 2002 for VirtualU by doxygen1.2.17