// Change the vector in 'src' into a unit vector at 'dst' - ie with length = 1 // src and dst can be the same vector void vector2d_Normalise(VECTOR2D* dst,const VECTOR2D* src){ vector2d_Copy(dst,src); if(!dst->normalised){ double dist = vector2d_Length(dst); dst->x /= dist; dst->y /= dist; dst->normalised = TRUE; } }
static void draw(GDISPLAY_WIDGET* widget){ GDISPLAY* display = widget->_owner_; DIAL_WIDGET* dial = (DIAL_WIDGET*)widget; // Get the center of the dial PIXEL radius = getRadius(dial); //PIXEL innerRadius = radius * (100 - dial->dialThickness) / 100; VECTOR2D north = MAKE_VECTOR2D(0,-1); VECTOR2D origin = MAKE_VECTOR2D(centerX(dial),centerY(dial)); MATRIX2D rotate; // Create the dial background circle _displayMoveTo(display, origin.x, origin.y); _displaySetInk(display,&dial->_props_.dial); _displayCircle(display, radius, TRUE); // _displaySetInk(display,&dial->_widget_.bgnd); // _displayCircle(display, innerRadius, TRUE); // Put grad marks for every x if(dial->_props_.gradVal != 0){ _displaySetInk(display, &dial->_props_.grad); for(double grad = dial->_props_.setting.min; grad <= dial->_props_.setting.max; grad+=dial->_props_.gradVal){ // Create Rotation matrix double angle = interpolatef(grad, dial->_props_.setting.min, dial->_props_.setting.max, dial->_props_.minAng, dial->_props_.maxAng); double rad = angle * M_PI/180.0; matrix2d_SetRotate(&rotate, rad); // Rotate the North vector VECTOR2D max,min; matrix2d_Transform(&max, &north, &rotate); vector2d_Copy(&min,&max); vector2d_Scale(&max,radius); double scale = 0.85; vector2d_Scale(&min,radius * scale); vector2d_Add(&min,&origin); vector2d_Add(&max,&origin); // Draw line from min to max _displayMoveTo(display, round(min.x), round(min.y)); _displayLineTo(display, round(max.x), round(max.y)); } } }