GEuser's CUSTOMIZABLE GUI LIBRARY: radar()
REPLACEMENT UPLOADED 04 April 2013
Demo Screenshot
DOWNLOADS (Large size due to station images)
Linux:
Mac:
Windows:
Demo Resources:
Symbol Template:-
INTRODUCTION
Wanted to create away to auto-generate a simple radar scanning system for any normal/canvass actors. To be-able to zoom in & out and change the size of individual targets displayed in radar and change the size of the radar window itself.
The radar() function will do all the laborious work for you. All you have to do is supply the Actor you want to include for radar scanning with all the various settings. Note because this is passed by reference you need the ampersand (&) in front of the actor name (e.g. for an actor called monster1 use radar(&monster1,...); You can add as many actors in successive radar calls to see multiple items on a radar scan. Important to note that the erase() function is only called once at the start of the radar() calls to avoid clearing of a previous radar() call. In the demo at end of post I've chosen to put the radar() function in the draw actor event. You may want to put it somewhere else but then you would have to be responsible for updating the radar display yourself.
UPDATE INFORMATION
Have done a complete overhaul of function:-
1. Now includes centreTarget, an actor that can be passed in (remember to add '&' symbol to actors name radar(..., &actorname, ...) for centering in radar. This can be for the player or whatever that needs to remain in the centre of the radar when view moves. centreScale can be used to specify sizing in radar. Note, the actor for this should be parented to the view).
2. Added displayMode that allows you to see targets in radar as actor images or symbols (first part of color parameter is for symbol color). Currently, there is a choice of 30 default symbols. These can be replaced or new ones added to switch() statement in radar global code (can use symbol template provided above).
3. radarColors now allows colors to be passed in as hex character string (must be capitals). The string is 16 long for two colors including alphas. This saves me using 8 parameters for the colors so big improvement for color management. Format is RRGGBBAA (RR=red, GG=green, BB=blue, AA=Alpha). The color coding is different from that given by skyderiegn in my arcbar() thread. My coding can be adjusted to allow for 31 colors in a single function parameter!!!
Use this LINK for getting the right hex color codes (they come in capitals on website so makes its easier to insert but you will need to add the alpha bits):-
http://www.workwithcolor.com/hsl-color-picker-01.htm or http://www.favicon.cc/
let me know if you find a link for one with an alpha setting included.
4. Got rid of radarY & radarX because it was causing problems but don't need it anyway cos can move the canvass that creates the radar.
BASIC INFORMATION
GLOBAL CODE
- Code: Select all
void radar (int displayMode, Actor * centreTarget, Actor * radarTarget, double centreScale, double targetScale, double radarScale, int radarWidth, int radarHeight, char * radarColors, int borderSize)
{
char colorRegister[17]="A3DE4F40A3DE4F50";
char hexCode[18]="0123456789ABCDEF";
char * ptr_hex;
char col1[3]="";
char col2[3]="";
char s=colorRegister[0];
int ColorParts[8];
int radar_i=0;
// calcluate target positioning within radar (relative to view & scale settings)
int posX=radarWidth/2+(radarTarget->x/radarScale)-((view.width/2)/radarScale)-(view.x/radarScale)+borderSize;
int posY=radarHeight/2+(radarTarget->y/radarScale)-((view.height/2)/radarScale)-(view.y/radarScale)+borderSize;
// calcluate central actors positioning within radar (relative to view & scale settings)
int cenX=radarWidth/2+((centreTarget->width/2)/radarScale);
int cenY=radarHeight/2+((centreTarget->height/2)/radarScale);
// load in parsed colors
strcpy(colorRegister, radarColors);
// extract color components
for(radar_i=0; radar_i<8; radar_i++)
{
//
s=colorRegister[(radar_i*2)];
ptr_hex=strchr(hexCode,s);
sprintf(col1, "%d", ptr_hex-(hexCode));
s=colorRegister[(radar_i*2)+1];
ptr_hex=strchr(hexCode,s);
sprintf(col2, "%d", ptr_hex-(hexCode));
ColorParts[radar_i]=atoi(col1)*16 + atoi(col2);
}
//place central actor in middle of radar screen
draw_from(centreTarget->name, cenX, cenY, centreScale);
// check target within radar display limits
if ((posX>-1*(radarTarget->width*targetScale)/2+borderSize)&&(posX<radarWidth+borderSize)&&(posY>-1*(radarTarget->height*targetScale)/2+borderSize)&&(posY<radarHeight+borderSize))
{
// Okay, draw target
// check if target actor or symbol display required (displayMode)
setpen(ColorParts[0], ColorParts[1], ColorParts[2], ColorParts[3]/255.0, 1);
switch (displayMode)
{
// actor display wanted, display it at targetScale
case 0:
draw_from(radarTarget->name, posX, posY, targetScale);
break;
// symbol display wanted
case 1:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
putpixel(posX-3, posY-3); putpixel(posX+3, posY-3);
moveto(posX-4, posY-2); lineto(posX-4, posY+2);
moveto(posX+4, posY-2); lineto(posX+4, posY+2);
putpixel(posX-3, posY+3); putpixel(posX+3, posY+3);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
break;
case 2:
moveto(posX-4, posY-4); lineto(posX+4, posY-4);
moveto(posX-4, posY-4); lineto(posX-4, posY+4);
moveto(posX+4, posY-4); lineto(posX+4, posY+4);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 3:
putpixel(posX, posY-4);
putpixel(posX-1, posY-3); putpixel(posX+1, posY-3);
putpixel(posX-1, posY-2); putpixel(posX+1, posY-2);
putpixel(posX-2, posY-1); putpixel(posX+2, posY-1);
putpixel(posX-2, posY); putpixel(posX+2, posY);
putpixel(posX-3, posY+1); putpixel(posX+3, posY+1);
putpixel(posX-3, posY+2); putpixel(posX+3, posY+2);
putpixel(posX-4, posY+3); putpixel(posX+4, posY+3);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 4:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
putpixel(posX-3, posY-3); putpixel(posX+3, posY-3);
moveto(posX-4, posY-2); lineto(posX-4, posY+2);
moveto(posX+4, posY-2); lineto(posX+4, posY+2);
putpixel(posX-3, posY+3); putpixel(posX+3, posY+3);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
moveto(posX-1, posY-2); lineto(posX+1, posY-2);
moveto(posX-2, posY-1); lineto(posX+2, posY-1);
moveto(posX-2, posY); lineto(posX+2, posY);
moveto(posX-2, posY+1); lineto(posX+2, posY+1);
moveto(posX-1, posY+2); lineto(posX+1, posY+2);
break;
case 5:
moveto(posX-4, posY-4); lineto(posX+4, posY-4);
moveto(posX-4, posY-4); lineto(posX-4, posY+4);
moveto(posX+4, posY-4); lineto(posX+4, posY+4);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
moveto(posX-2, posY-2); lineto(posX+2, posY-2);
moveto(posX-2, posY-1); lineto(posX+2, posY-1);
moveto(posX-2, posY); lineto(posX+2, posY);
moveto(posX-2, posY+1); lineto(posX+2, posY+1);
moveto(posX-2, posY+2); lineto(posX+2, posY+2);
break;
case 6:
putpixel(posX, posY-4);
putpixel(posX-1, posY-3); putpixel(posX+1, posY-3);
putpixel(posX-1, posY-2); putpixel(posX+1, posY-2);
putpixel(posX-2, posY-1); putpixel(posX+2, posY-1);
putpixel(posX-2, posY); putpixel(posX+2, posY);
putpixel(posX-3, posY+1); putpixel(posX+3, posY+1);
putpixel(posX-3, posY+2); putpixel(posX+3, posY+2);
putpixel(posX-4, posY+3); putpixel(posX+4, posY+3);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
putpixel(posX, posY-1); putpixel(posX, posY);
moveto(posX-1, posY+1); lineto(posX+1, posY+1);
moveto(posX-1, posY+2); lineto(posX+1, posY+2);
break;
case 7:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
moveto(posX-3, posY-3); lineto(posX+3, posY-3);
moveto(posX-4, posY-2); lineto(posX-2, posY-2);
moveto(posX+2, posY-2); lineto(posX+4, posY-2);
moveto(posX-4, posY-1); lineto(posX-4, posY+1);
moveto(posX-3, posY-1); lineto(posX-3, posY+1);
moveto(posX+3, posY-1); lineto(posX+3, posY+1);
moveto(posX+4, posY-1); lineto(posX+4, posY+1);
moveto(posX-4, posY+2); lineto(posX-2, posY+2);
moveto(posX+2, posY+2); lineto(posX+4, posY+2);
moveto(posX-3, posY+3); lineto(posX+3, posY+3);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
break;
case 8:
moveto(posX-4, posY-4); lineto(posX+4, posY-4);
moveto(posX-4, posY-3); lineto(posX+4, posY-3);
moveto(posX-4, posY-2); lineto(posX-4, posY+2);
moveto(posX-3, posY-2); lineto(posX-3, posY+2);
moveto(posX+3, posY-2); lineto(posX+3, posY+2);
moveto(posX+4, posY-2); lineto(posX+4, posY+2);
moveto(posX-4, posY+3); lineto(posX+4, posY+3);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 9:
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
moveto(posX-4, posY+3); lineto(posX+4, posY+3);
moveto(posX-3, posY+1); lineto(posX-3, posY+2);
moveto(posX-2, posY-1); lineto(posX-2, posY+2);
moveto(posX-1, posY-3); lineto(posX-1, posY);
moveto(posX, posY-4); lineto(posX, posY-2);
moveto(posX+1, posY-3); lineto(posX+1, posY);
moveto(posX+2, posY-1); lineto(posX+2, posY+2);
moveto(posX+3, posY+1); lineto(posX+3, posY+2);
break;
case 10:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
moveto(posX-3, posY-3); lineto(posX+3, posY-3);
moveto(posX-4, posY-2); lineto(posX+4, posY-2);
moveto(posX-4, posY-1); lineto(posX+4, posY-1);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-4, posY+1); lineto(posX+4, posY+1);
moveto(posX-4, posY+2); lineto(posX+4, posY+2);
moveto(posX-3, posY+3); lineto(posX+3, posY+3);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
break;
case 11:
for (radar_i=0; radar_i<9; radar_i++)
{
moveto(posX-4, posY-4+radar_i); lineto(posX+4, posY-4+radar_i);
}
break;
case 12:
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-1, posY-3); lineto(posX-1, posY+4);
moveto(posX+1, posY-3); lineto(posX+1, posY+4);
moveto(posX-2, posY-1); lineto(posX-2, posY+4);
moveto(posX+2, posY-1); lineto(posX+2, posY+4);
moveto(posX-3, posY+1); lineto(posX-3, posY+4);
moveto(posX+3, posY+1); lineto(posX+3, posY+4);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 13:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
putpixel(posX-3, posY-3); putpixel(posX+3, posY-3);
moveto(posX-4, posY-2); lineto(posX-4, posY+2);
moveto(posX+4, posY-2); lineto(posX+4, posY+2);
putpixel(posX-3, posY+3); putpixel(posX+3, posY+3);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-1, posY-1); lineto(posX+1, posY-1);
moveto(posX-1, posY); lineto(posX+1, posY);
moveto(posX-1, posY+1); lineto(posX+1, posY+1);
break;
case 14:
moveto(posX-4, posY-4); lineto(posX+4, posY-4);
moveto(posX-4, posY-4); lineto(posX-4, posY+4);
moveto(posX+4, posY-4); lineto(posX+4, posY+4);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-1, posY-1); lineto(posX+1, posY-1);
moveto(posX-1, posY); lineto(posX+1, posY);
moveto(posX-1, posY+1); lineto(posX+1, posY+1);
break;
case 15:
moveto(posX, posY-4); lineto(posX, posY);
moveto(posX-1, posY-3); lineto(posX-1, posY);
moveto(posX+1, posY-3); lineto(posX+1, posY);
moveto(posX-2, posY-1); lineto(posX-2, posY);
moveto(posX+2, posY-1); lineto(posX+2, posY);
putpixel(posX-3, posY+1); putpixel(posX+3, posY+1);
moveto(posX-3, posY+2); lineto(posX-2, posY+2);
moveto(posX+2, posY+2); lineto(posX+3, posY+2);
moveto(posX-4, posY+3); lineto(posX-1, posY+3);
moveto(posX+1, posY+3); lineto(posX+4, posY+3);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 16:
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-1, posY-1); lineto(posX+1, posY-1);
moveto(posX-1, posY); lineto(posX+1, posY);
moveto(posX-1, posY+1); lineto(posX+1, posY+1);
break;
case 17:
moveto(posX, posY-3); lineto(posX, posY+3);
moveto(posX-3, posY); lineto(posX+3, posY);
moveto(posX-1, posY-1); lineto(posX+1, posY-1);
moveto(posX-1, posY); lineto(posX+1, posY);
moveto(posX-1, posY+1); lineto(posX+1, posY+1);
moveto(posX-1, posY-4); lineto(posX+1, posY-4);
moveto(posX-1, posY+4); lineto(posX+1, posY+4);
moveto(posX-4, posY-1); lineto(posX-4, posY+1);
moveto(posX+4, posY-1); lineto(posX+4, posY+1);
break;
case 18:
moveto(posX, posY-4); lineto(posX, posY-1);
putpixel(posX-1, posY-3); putpixel(posX+1, posY-3);
putpixel(posX-2, posY-2); putpixel(posX+2, posY-2);
moveto(posX-1, posY); lineto(posX+1, posY);
moveto(posX-1, posY+1); lineto(posX+1, posY+1);
putpixel(posX-2, posY+2); putpixel(posX+2, posY+2);
putpixel(posX-3, posY+3); putpixel(posX+3, posY+3);
moveto(posX-4, posY+2); lineto(posX-4, posY+3);
moveto(posX+4, posY+2); lineto(posX+4, posY+3);
moveto(posX-4, posY+4); lineto(posX-2, posY+4);
moveto(posX+2, posY+4); lineto(posX+4, posY+4);
break;
case 19:
moveto(posX-4, posY-2); lineto(posX-4, posY+2);
moveto(posX+4, posY-2); lineto(posX+4, posY+2);
moveto(posX-3, posY-3); lineto(posX-3, posY+3);
moveto(posX+3, posY-3); lineto(posX+3, posY+3);
moveto(posX-2, posY-4); lineto(posX-2, posY-3);
moveto(posX-2, posY+3); lineto(posX-2, posY+4);
moveto(posX+2, posY-4); lineto(posX+2, posY-3);
moveto(posX+2, posY+3); lineto(posX+2, posY+4);
moveto(posX-2, posY); lineto(posX+2, posY);
putpixel(posX, posY-1); putpixel(posX, posY+1);
break;
case 20:
moveto(posX-4, posY-4); lineto(posX-4, posY+4);
moveto(posX+4, posY-4); lineto(posX+4, posY+4);
moveto(posX-3, posY-4); lineto(posX-3, posY+4);
moveto(posX+3, posY-4); lineto(posX+3, posY+4);
putpixel(posX-2, posY-4); putpixel(posX-2, posY+4);
putpixel(posX+2, posY-4); putpixel(posX+2, posY+4);
moveto(posX-2, posY); lineto(posX+2, posY);
putpixel(posX, posY-1); putpixel(posX, posY+1);
break;
case 21:
putpixel(posX, posY-4);
moveto(posX-1, posY-3); lineto(posX+1, posY-3);
moveto(posX-1, posY-2); lineto(posX+1, posY-2);
moveto(posX-2, posY-1); lineto(posX+2, posY-1);
putpixel(posX-3, posY+1); putpixel(posX+3, posY+1);
moveto(posX-3, posY+2); lineto(posX-2, posY+2);
moveto(posX+2, posY+2); lineto(posX+3, posY+2);
moveto(posX-4, posY+3); lineto(posX-2, posY+3);
moveto(posX+2, posY+3); lineto(posX+4, posY+3);
moveto(posX-4, posY+4); lineto(posX-1, posY+4);
moveto(posX+1, posY+4); lineto(posX+4, posY+4);
break;
case 22:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
moveto(posX-4, posY-2); lineto(posX+4, posY-2);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-4, posY+2); lineto(posX+4, posY+2);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
break;
case 23:
moveto(posX-4, posY-4); lineto(posX+4, posY-4);
moveto(posX-4, posY-2); lineto(posX+4, posY-2);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-4, posY+2); lineto(posX+4, posY+2);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 24:
putpixel(posX, posY-4);
moveto(posX-1, posY-2); lineto(posX+1, posY-2);
moveto(posX-2, posY); lineto(posX+2, posY);
moveto(posX-3, posY+2); lineto(posX+3, posY+2);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
break;
case 25:
moveto(posX-4, posY-2); lineto(posX-4, posY+2);
moveto(posX-2, posY-4); lineto(posX-2, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX+2, posY-4); lineto(posX+2, posY+4);
moveto(posX+4, posY-2); lineto(posX+4, posY+2);
break;
case 26:
moveto(posX-4, posY-4); lineto(posX-4, posY+4);
moveto(posX-2, posY-4); lineto(posX-2, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX+2, posY-4); lineto(posX+2, posY+4);
moveto(posX+4, posY-4); lineto(posX+4, posY+4);
break;
case 27:
moveto(posX-4, posY+3); lineto(posX-4, posY+4);
moveto(posX-2, posY-1); lineto(posX-2, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX+2, posY-1); lineto(posX+2, posY+4);
moveto(posX+4, posY+3); lineto(posX+4, posY+4);
break;
case 28:
moveto(posX-2, posY-4); lineto(posX+2, posY-4);
moveto(posX-4, posY-2); lineto(posX+4, posY-2);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-4, posY+2); lineto(posX+4, posY+2);
moveto(posX-2, posY+4); lineto(posX+2, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-1, posY-2); lineto(posX-1, posY+4);
moveto(posX+1, posY-2); lineto(posX+1, posY+4);
moveto(posX-2, posY-2); lineto(posX-2, posY+4);
moveto(posX+2, posY-2); lineto(posX+2, posY+4);
break;
case 29:
moveto(posX-4, posY-4); lineto(posX+4, posY-4);
moveto(posX-4, posY-2); lineto(posX+4, posY-2);
moveto(posX-4, posY); lineto(posX+4, posY);
moveto(posX-4, posY+2); lineto(posX+4, posY+2);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-1, posY-2); lineto(posX-1, posY+4);
moveto(posX+1, posY-2); lineto(posX+1, posY+4);
moveto(posX-2, posY-2); lineto(posX-2, posY+4);
moveto(posX+2, posY-2); lineto(posX+2, posY+4);
break;
case 30:
putpixel(posX, posY-4);
moveto(posX-1, posY-2); lineto(posX+1, posY-2);
moveto(posX-2, posY); lineto(posX+2, posY);
moveto(posX-3, posY+2); lineto(posX+3, posY+2);
moveto(posX-4, posY+4); lineto(posX+4, posY+4);
moveto(posX, posY-4); lineto(posX, posY+4);
moveto(posX-1, posY-2); lineto(posX-1, posY+4);
moveto(posX+1, posY-2); lineto(posX+1, posY+4);
moveto(posX-2, posY-2); lineto(posX-2, posY+4);
moveto(posX+2, posY-2); lineto(posX+2, posY+4);
break;
default:
//
break;
}
}
setpen(ColorParts[4], ColorParts[5], ColorParts[6], ColorParts[7]/255.0, 1);
for (radar_i=0; radar_i<borderSize; radar_i++)
{
moveto (radar_i, radar_i);
lineto(radarWidth+(2*borderSize-radar_i), radar_i);
lineto(radarWidth+(2*borderSize-radar_i), radarHeight+(2*borderSize-radar_i));
lineto(radar_i, radarHeight+(2*borderSize-radar_i));
lineto(radar_i, radar_i);
}
}
DEMO BUILDING INSTRUCTIONS
Demo resources provide as .zip above but instructions comming soon (getting late, out of time)...