/** * @brief System editor custom widget rendering. */ static void uniedit_render( double bx, double by, double w, double h, void *data ) { (void) data; double x,y,r; StarSystem *sys; int i; /* Parameters. */ map_renderParams( bx, by, uniedit_xpos, uniedit_ypos, w, h, uniedit_zoom, &x, &y, &r ); /* background */ gl_renderRect( bx, by, w, h, &cBlack ); /* Render systems. */ map_renderSystems( bx, by, x, y, w, h, r, 1 ); /* Render system names. */ map_renderNames( x, y, 1 ); /* Render the selected system selections. */ for (i=0; i<uniedit_nsys; i++) { sys = uniedit_sys[i]; gl_drawCircleInRect( x + sys->pos.x * uniedit_zoom, y + sys->pos.y * uniedit_zoom, 1.5*r, bx, by, w, h, &cWhite, 0 ); } }
/** * @brief Renders the custom map widget. * * @param bx Base X position to render at. * @param by Base Y position to render at. * @param w Width of the widget. * @param h Height of the widget. */ static void map_render( double bx, double by, double w, double h, void *data ) { (void) data; int i,j, n,m; double x,y,r, tx,ty, fuel; StarSystem *sys, *jsys, *hsys, *lsys; glColour *col, c; GLfloat vertex[8*(2+4)]; int sw, sh; /* Parameters. */ r = round(CLAMP(5., 15., 6.*map_zoom)); x = round((bx - map_xpos + w/2) * 1.); y = round((by - map_ypos + h/2) * 1.); /* background */ gl_renderRect( bx, by, w, h, &cBlack ); /* * First pass renders everything almost (except names and markers). */ for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* check to make sure system is known or adjacent to known (or marked) */ if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys)) continue; tx = x + sys->pos.x*map_zoom; ty = y + sys->pos.y*map_zoom; /* draws the disk representing the faction */ if (sys_isKnown(sys) && (sys->faction != -1)) { sw = gl_faction_disk->sw; sh = gl_faction_disk->sw; col = faction_colour(sys->faction); c.r = col->r; c.g = col->g; c.b = col->b; c.a = 0.7; gl_blitTexture( gl_faction_disk, tx - sw/2, ty - sh/2, sw, sh, 0., 0., gl_faction_disk->srw, gl_faction_disk->srw, &c ); } /* Draw the system. */ if (!sys_isKnown(sys) || (sys->nfleets==0)) col = &cInert; else if (sys->security >= 1.) col = &cGreen; else if (sys->security >= 0.6) col = &cOrange; else if (sys->security >= 0.3) col = &cRed; else col = &cDarkRed; gl_drawCircleInRect( tx, ty, r, bx, by, w, h, col, 0 ); /* If system is known fill it. */ if (sys_isKnown(sys) && (sys->nplanets > 0)) { /* Planet colours */ if (!sys_isKnown(sys)) col = &cInert; else if (sys->nplanets==0) col = &cInert; else col = faction_getColour( sys->faction); /* Radius slightly shorter. */ gl_drawCircleInRect( tx, ty, 0.5*r, bx, by, w, h, col, 1 ); } if (!sys_isKnown(sys)) continue; /* we don't draw hyperspace lines */ /* draw the hyperspace paths */ glShadeModel(GL_SMOOTH); col = &cDarkBlue; /* first we draw all of the paths. */ for (j=0; j<sys->njumps; j++) { jsys = system_getIndex( sys->jumps[j] ); if (hyperspace_target != -1) hsys = system_getIndex( cur_system->jumps[hyperspace_target] ); /* Draw the lines. */ vertex[0] = x + sys->pos.x * map_zoom; vertex[1] = y + sys->pos.y * map_zoom; vertex[2] = vertex[0] + (jsys->pos.x - sys->pos.x)/2. * map_zoom; vertex[3] = vertex[1] + (jsys->pos.y - sys->pos.y)/2. * map_zoom; vertex[4] = x + jsys->pos.x * map_zoom; vertex[5] = y + jsys->pos.y * map_zoom; vertex[6] = col->r; vertex[7] = col->g; vertex[8] = col->b; vertex[9] = 0.; vertex[10] = col->r; vertex[11] = col->g; vertex[12] = col->b; vertex[13] = col->a; vertex[14] = col->r; vertex[15] = col->g; vertex[16] = col->b; vertex[17] = 0.; gl_vboSubData( map_vbo, 0, sizeof(GLfloat) * 3*(2+4), vertex ); gl_vboActivateOffset( map_vbo, GL_VERTEX_ARRAY, 0, 2, GL_FLOAT, 0 ); gl_vboActivateOffset( map_vbo, GL_COLOR_ARRAY, sizeof(GLfloat) * 2*3, 4, GL_FLOAT, 0 ); glDrawArrays( GL_LINE_STRIP, 0, 3 ); gl_vboDeactivate(); } glShadeModel( GL_FLAT ); } /* Now we'll draw over the lines with the new pathways. */ if (map_path != NULL) { lsys = cur_system; glShadeModel(GL_SMOOTH); col = &cGreen; fuel = player->fuel; for (j=0; j<map_npath; j++) { jsys = map_path[j]; if (fuel == player->fuel) col = &cGreen; else if (fuel < 100.) col = &cRed; else col = &cYellow; fuel -= 100; /* Draw the lines. */ vertex[0] = x + lsys->pos.x * map_zoom; vertex[1] = y + lsys->pos.y * map_zoom; vertex[2] = vertex[0] + (jsys->pos.x - lsys->pos.x)/2. * map_zoom; vertex[3] = vertex[1] + (jsys->pos.y - lsys->pos.y)/2. * map_zoom; vertex[4] = x + jsys->pos.x * map_zoom; vertex[5] = y + jsys->pos.y * map_zoom; vertex[6] = col->r; vertex[7] = col->g; vertex[8] = col->b; vertex[9] = 0.; vertex[10] = col->r; vertex[11] = col->g; vertex[12] = col->b; vertex[13] = col->a; vertex[14] = col->r; vertex[15] = col->g; vertex[16] = col->b; vertex[17] = 0.; gl_vboSubData( map_vbo, 0, sizeof(GLfloat) * 3*(2+4), vertex ); gl_vboActivateOffset( map_vbo, GL_VERTEX_ARRAY, 0, 2, GL_FLOAT, 0 ); gl_vboActivateOffset( map_vbo, GL_COLOR_ARRAY, sizeof(GLfloat) * 2*3, 4, GL_FLOAT, 0 ); glDrawArrays( GL_LINE_STRIP, 0, 3 ); gl_vboDeactivate(); lsys = jsys; } glShadeModel( GL_FLAT ); } /* * Second pass - System names */ for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* Skip system. */ if (!sys_isKnown(sys) || (map_zoom <= 0.5 )) continue; tx = x + (sys->pos.x+11.) * map_zoom; ty = y + (sys->pos.y-5.) * map_zoom; gl_print( &gl_smallFont, tx + SCREEN_W/2., ty + SCREEN_H/2., &cWhite, sys->name ); } /* * Third pass - system markers */ for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* We only care about marked now. */ if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) continue; /* Get the position. */ tx = x + sys->pos.x*map_zoom; ty = y + sys->pos.y*map_zoom; /* Count markers. */ n = (sys_isFlag(sys, SYSTEM_CMARKED)) ? 1 : 0; n += sys->markers_misc; n += sys->markers_cargo; n += sys->markers_rush; /* Draw the markers. */ j = 0; if (sys_isFlag(sys, SYSTEM_CMARKED)) { map_drawMarker( tx, ty, r, n, j, 0 ); j++; } for (m=0; m<sys->markers_misc; m++) { map_drawMarker( tx, ty, r, n, j, 1 ); j++; } for (m=0; m<sys->markers_rush; m++) { map_drawMarker( tx, ty, r, n, j, 2 ); j++; } for (m=0; m<sys->markers_cargo; m++) { map_drawMarker( tx, ty, r, n, j, 3 ); j++; } } /* Selected planet. */ if (map_selected != -1) { sys = system_getIndex( map_selected ); gl_drawCircleInRect( x + sys->pos.x * map_zoom, y + sys->pos.y * map_zoom, 1.5*r, bx, by, w, h, &cRed, 0 ); } /* Current planet. */ gl_drawCircleInRect( x + cur_system->pos.x * map_zoom, y + cur_system->pos.y * map_zoom, 1.5*r, bx, by, w, h, &cRadar_tPlanet, 0 ); }
/** * @brief Renders the custom map widget. * * @param bx Base X position to render at. * @param by Base Y position to render at. * @param w Width of the widget. * @param h Height of the widget. */ static void map_render( double bx, double by, double w, double h ) { int i,j, n,m; double x,y,r, tx,ty; StarSystem *sys, *jsys, *hsys; glColour* col; r = 5.; x = (bx - map_xpos + w/2) * 1.; y = (by - map_ypos + h/2) * 1.; /* background */ COLOUR(cBlack); glBegin(GL_QUADS); glVertex2d( bx, by ); glVertex2d( bx, by+h ); glVertex2d( bx+w, by+h ); glVertex2d( bx+w, by ); glEnd(); /* GL_QUADS */ /* render the star systems */ for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* check to make sure system is known or adjacent to known (or marked) */ if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys)) continue; /* system colours */ if (sys==cur_system) col = &cRadar_tPlanet; else if (!sys_isKnown(sys) || (sys->nplanets==0)) col = &cInert; else col = faction_getColour( sys->faction); COLOUR(*col); /* draw the system */ tx = x + sys->pos.x*map_zoom; ty = y + sys->pos.y*map_zoom; gl_drawCircleInRect( tx, ty, r, bx, by, w, h ); /* draw the system name */ if (sys_isKnown(sys) && (map_zoom > 0.5 )) { tx = x + 7. + sys->pos.x * map_zoom; ty = y - 5. + sys->pos.y * map_zoom; gl_print( &gl_smallFont, tx + SCREEN_W/2., ty + SCREEN_H/2., &cWhite, sys->name ); } if (!sys_isKnown(sys)) continue; /* we don't draw hyperspace lines */ /* draw the hyperspace paths */ glShadeModel(GL_SMOOTH); /* cheaply use transparency instead of actually calculating * from where to where the line must go :) */ for (j=0; j<sys->njumps; j++) { jsys = system_getIndex( sys->jumps[j] ); if (hyperspace_target != -1) hsys = system_getIndex( cur_system->jumps[hyperspace_target] ); n = map_inPath(jsys); m = map_inPath(sys); /* set the colours */ /* is the route the current one? */ if ((hyperspace_target != -1) && ( ((cur_system==sys) && (j==hyperspace_target)) || ((cur_system==jsys) && (sys==hsys )))) { if (player->fuel < HYPERSPACE_FUEL) col = &cRed; else col = &cGreen; } /* is the route part of the path? */ else if ((n > 0) && (m > 0)) { if ((n == 2) || (m == 2)) /* out of fuel */ col = &cRed; else col = &cYellow; } else col = &cDarkBlue; glBegin(GL_LINE_STRIP); ACOLOUR(*col,0.); tx = x + sys->pos.x * map_zoom; ty = y + sys->pos.y * map_zoom; glVertex2d( tx, ty ); COLOUR(*col); tx += (jsys->pos.x - sys->pos.x)/2. * map_zoom; ty += (jsys->pos.y - sys->pos.y)/2. * map_zoom; glVertex2d( tx, ty ); ACOLOUR(*col,0.); tx = x + jsys->pos.x * map_zoom; ty = y + jsys->pos.y * map_zoom; glVertex2d( tx, ty ); glEnd(); /* GL_LINE_STRIP */ } glShadeModel(GL_FLAT); } /* Second pass to put markers. */ for (i=0; i<systems_nstack; i++) { sys = system_getIndex( i ); /* We only care about marked now. */ if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) continue; /* Get the position. */ tx = x + sys->pos.x*map_zoom; ty = y + sys->pos.y*map_zoom; /* Count markers. */ n = (sys_isFlag(sys, SYSTEM_CMARKED)) ? 1 : 0; n += sys->markers_misc; n += sys->markers_cargo; n += sys->markers_rush; /* Draw the markers. */ j = 0; if (sys_isFlag(sys, SYSTEM_CMARKED)) { map_drawMarker( tx, ty, r, n, j, 0 ); j++; } for (m=0; m<sys->markers_misc; m++) { map_drawMarker( tx, ty, r, n, j, 1 ); j++; } for (m=0; m<sys->markers_rush; m++) { map_drawMarker( tx, ty, r, n, j, 2 ); j++; } for (m=0; m<sys->markers_cargo; m++) { map_drawMarker( tx, ty, r, n, j, 3 ); j++; } } /* selected planet */ if (map_selected != -1) { sys = system_getIndex( map_selected ); COLOUR(cRed); gl_drawCircleInRect( x + sys->pos.x * map_zoom, y + sys->pos.y * map_zoom, r+3., bx, by, w, h ); } }