From 7e7df7dac0499f22ccb369636ecf3dd1da121c29 Mon Sep 17 00:00:00 2001 From: avolkov Date: Fri, 17 Mar 2006 23:02:28 +0000 Subject: [PATCH] Concentric-circle star designations positioning git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2280 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/map/large300.map | 36 ++++++++-------- tools/map/mapgen.c | 97 +++++++++++++++++++++++++----------------- 2 files changed, 75 insertions(+), 58 deletions(-) diff --git a/tools/map/large300.map b/tools/map/large300.map index 5f93f336a..98eb0c2d3 100755 --- a/tools/map/large300.map +++ b/tools/map/large300.map @@ -51,58 +51,58 @@ stars.desig.table=greek.map stars.colors=RGBOYW stars.sizes=3 stars.R.1.image=stars/fca_027_red.png -stars.R.1.radius=1.5 +stars.R.1.radius=1.6 stars.R.1.color=980000 stars.R.2.image=stars/fca_037_red.png -stars.R.2.radius=2.5 +stars.R.2.radius=2.7 stars.R.2.color=b80000 stars.R.3.image=stars/fca_070_red.png -stars.R.3.radius=3.0 +stars.R.3.radius=3.4 stars.R.3.color=d00000 stars.G.1.image=stars/fca_027_green.png -stars.G.1.radius=1.5 +stars.G.1.radius=1.6 stars.G.1.color=009800 stars.G.2.image=stars/fca_037_green.png -stars.G.2.radius=2.5 +stars.G.2.radius=2.7 stars.G.2.color=00b800 stars.G.3.image=stars/fca_070_green.png -stars.G.3.radius=3.0 +stars.G.3.radius=3.4 stars.G.3.color=00d000 stars.B.1.image=stars/fca_027_blue.png -stars.B.1.radius=1.5 +stars.B.1.radius=1.6 stars.B.1.color=000098 stars.B.2.image=stars/fca_037_blue.png -stars.B.2.radius=2.5 +stars.B.2.radius=2.7 stars.B.2.color=0000b8 stars.B.3.image=stars/fca_070_blue.png -stars.B.3.radius=3.0 +stars.B.3.radius=3.4 stars.B.3.color=0000d0 stars.O.1.image=stars/fca_027_orange.png -stars.O.1.radius=1.5 +stars.O.1.radius=1.6 stars.O.1.color=b86000 stars.O.2.image=stars/fca_037_orange.png -stars.O.2.radius=2.5 +stars.O.2.radius=2.7 stars.O.2.color=d06800 stars.O.3.image=stars/fca_070_orange.png -stars.O.3.radius=3.0 +stars.O.3.radius=3.4 stars.O.3.color=e8700 stars.Y.1.image=stars/fca_027_yellow.png -stars.Y.1.radius=1.5 +stars.Y.1.radius=1.6 stars.Y.1.color=b8b420 stars.Y.2.image=stars/fca_037_yellow.png -stars.Y.2.radius=2.5 +stars.Y.2.radius=2.7 stars.Y.2.color=d0ca28 stars.Y.3.image=stars/fca_070_yellow.png -stars.Y.3.radius=3.0 +stars.Y.3.radius=3.4 stars.Y.3.color=e8e430 stars.W.1.image=stars/fca_027_white.png -stars.W.1.radius=1.5 +stars.W.1.radius=1.6 stars.W.1.color=c8c8c8 stars.W.2.image=stars/fca_037_white.png -stars.W.2.radius=2.5 +stars.W.2.radius=2.7 stars.W.2.color=d8d8d8 stars.W.3.image=stars/fca_070_white.png -stars.W.3.radius=3.0 +stars.W.3.radius=3.4 stars.W.3.color=f0f0f0 # Star Clusters diff --git a/tools/map/mapgen.c b/tools/map/mapgen.c index fe73cad11..9b7e853e5 100755 --- a/tools/map/mapgen.c +++ b/tools/map/mapgen.c @@ -1969,7 +1969,7 @@ static void drawClusteredNames(const mg_driver_t* dst, script_t* scr) { const cluster_t* cluster = scr->clusters + i; const star_t* star = scr->stars + cluster->first; - const char* cname = star->cluster; + const unsigned char* cname = star->cluster; mg_rectf_t r; int placed = 0; int j; @@ -2043,15 +2043,68 @@ static void drawClusterNames(const mg_driver_t* dst, script_t* scr) drawClusteredNames(dst, scr); } -static void drawStarDesignations(const mg_driver_t* dst, script_t* scr) +static void drawStarDesignation(const mg_driver_t* dst, script_t* scr, const star_t* star) { - int i; const double orgx = scr->gridr.x; const double orgy = scr->gridr.y + scr->gridr.h; const double width = scr->gridr.w; const double height = scr->gridr.h; double stepx = width / scr->gridmx; double stepy = height / scr->gridmy; + const star_image_t* img = star->image; + const unsigned char* sdesig = scr->desigtab[star->prefix - 1].str; + mg_rectf_t r; + int placed = 0; + double rad, ang; + + if (!img) + { + mg_verbose(2, "Warning: star %s has no image\n", star->cluster); + return; + } + + r.x = r.y = 0; + dst->getTextSize(scr->desigfnt, sdesig, &r); + // add a little x margin + r.w += r.h / 8; + // placement is done in grid coordinates + r.w /= stepx; + r.h /= stepy; + + // search for a good placement spot + for (rad = r.w * 1.06; !placed && rad < r.h * 2.5; rad += r.h * 0.05) + { + double astep = M_PI / (rad / r.h * 32); + + for (ang = 0; !placed && ang < M_PI * 2; ang += astep) + { + placed = tryPlaceRect(scr, objt_DesigPlacement, &r, + star->pos.x + cos(ang) * rad, + star->pos.y + sin(ang) * rad); + } + } + + if (!placed) + { + mg_verbose(2, "Warning: cannot place %s %d designation w/o overlap\n", star->cluster, star->prefix); + return; // oops + } + + dst->drawText(scr->desigfnt, + orgx + r.x * stepx, + orgy - (r.y + r.h) * stepy, + sdesig, scr->desigclr); + + // register a rect grid object + addObject(scr, objt_Designation, sht_Rect, + r.x, r.y, r.x + r.w, r.y + r.h, + 0, 0); + +} + +static void drawStarDesignations(const mg_driver_t* dst, script_t* scr) +{ + int i; if (!scr->stars || !scr->desigtab || scr->cdesigtab == 0 || !scr->clusters) { @@ -2068,47 +2121,11 @@ static void drawStarDesignations(const mg_driver_t* dst, script_t* scr) for (s = 0; s < cluster->cstars; ++s) { const star_t* star = scr->stars + cluster->first + s; - double dx, dy; - double length; - double sinl, cosl; - double ofsx, ofsy; - shape_t shp; - const unsigned char* sdesig; - mg_rectf_t r; if (!star->prefix) continue; // no designation - sdesig = scr->desigtab[star->prefix - 1].str; - r.x = r.y = 0; - dst->getTextSize(scr->desigfnt, sdesig, &r); - - dx = star->pos.x - cluster->center.x; - dy = star->pos.y - cluster->center.y; - length = sqrt(SQR(dx) + SQR(dy)); - sinl = dy / length; - cosl = dx / length; - - ofsx = (r.w * cosl); - ofsy = (r.h * sinl); - - boxToRectShape(scr, &r, &shp); - shp.pt0.x += star->pos.x + shp.pt1.x * cosl - shp.pt1.x / 2; - shp.pt0.y += star->pos.y + shp.pt1.y * sinl - shp.pt1.y / 2; - shp.pt1.x += shp.pt0.x; - shp.pt1.y += shp.pt0.y; - if (isCollidingWith(scr, &shp, objt_DesigPlacement)) - continue; - - dst->drawText(scr->desigfnt, - orgx + (star->pos.x * stepx + ofsx) - r.w / 2, - orgy - (star->pos.y * stepy + ofsy) - r.h / 2, - sdesig, scr->desigclr); - - // register a rect grid object - addObject(scr, objt_Designation, sht_Rect, - shp.pt0.x, shp.pt0.y, shp.pt1.x, shp.pt1.y, - 0, 0); + drawStarDesignation(dst, scr, star); } } }