Permalink
Browse files

Improved sideview. Faster horizontal resolution, better airspace labe…

…l placement.
  • Loading branch information...
1 parent 65ae9ef commit 02d3149631b861197419347108bd9c863615e988 @AlphaLima AlphaLima committed with pventafridda Feb 27, 2012
@@ -26,7 +26,7 @@
// the resolution turns to be too inaccurate
// so tha small (<5km airspaced) (e.g. dangerous areas) will not be shown
// with AIRSPACE_SCANSIZE_X 64 I tried to make a compromise between resolution and speed on slow devices
-#define AIRSPACE_SCANSIZE_X 80
+#define AIRSPACE_SCANSIZE_X 140
#define GC_MAX_POLYGON_PTS (2*AIRSPACE_SCANSIZE_X+4)
#define MAX_NO_SIDE_AS 40
// Define this, if airspace nearest distance infoboxes will use selected airpsace only
@@ -277,6 +277,8 @@ typedef struct
int iAreaSize;
int aiLable;
int iType;
+ int iMaxBase;
+ int iMinTop;
BOOL bRectAllowed;
BOOL bEnabled;
TCHAR szAS_Name[NAME_SIZE + 1];
@@ -28,8 +28,10 @@ extern COLORREF Sideview_TextColor;
-void Statistics::RenderAirspace(HDC hdc, const RECT rc) {
+void Statistics::RenderAirspace(HDC hdc, const RECT rci) {
+ RECT rc = rci;
+// rc.bottom = rc.bottom/2;
double fDist = 50.0*1000; // km
double aclat, aclon, ach, acb, speed, calc_average30s;
@@ -26,22 +26,18 @@ extern int Sideview_iNoHandeldSpaces;
void RenderAirspaceTerrain(HDC hdc, const RECT rc,double PosLat, double PosLon, double brg, DiagrammStruct* psDiag )
{
-
- double range =psDiag->fXMax - psDiag->fXMin; // km
-
- double hmin = psDiag->fYMin;
- double hmax = psDiag->fYMax;
- double lat, lon;
-
- int i,j;
+double range =psDiag->fXMax - psDiag->fXMin; // km
+double hmax = psDiag->fYMax;
+double lat, lon;
+int i,j;
#if (WINDOWSPC>0)
if(INVERTCOLORS)
RenderSky( hdc, rc, SKY_HORIZON_COL , SKY_SPACE_COL , GC_NO_COLOR_STEPS);
#endif
FindLatitudeLongitude(PosLat, PosLon, brg , psDiag->fXMin , &lat, &lon);
-
+ POINT apTerrainPolygon[AIRSPACE_SCANSIZE_X+4];
double d_lat[AIRSPACE_SCANSIZE_X];
double d_lon[AIRSPACE_SCANSIZE_X];
double d_h[AIRSPACE_SCANSIZE_X];
@@ -50,7 +46,8 @@ void RenderAirspaceTerrain(HDC hdc, const RECT rc,double PosLat, double PosLon,
-#define FRACT 0.75
+
+#define FRAMEWIDTH 2
RasterTerrain::Lock(); // want most accurate rounding here
RasterTerrain::SetTerrainRounding(0,0);
double fj;
@@ -89,150 +86,177 @@ void RenderAirspaceTerrain(HDC hdc, const RECT rc,double PosLat, double PosLon,
/**********************************************************************************
* transform into diagram coordinates
**********************************************************************************/
- double dx = dfj*(rc.right-rc.left-BORDER_X);
- int x0 = rc.left+BORDER_X;
- int y0 = rc.bottom-BORDER_Y;
+ double dx = dfj*(rc.right-rc.left);
+ int x0 = rc.left; //+BORDER_X;
+
for( i = 0 ; i < Sideview_iNoHandeldSpaces ;i++)
{
- Sideview_pHandeled[i].rc.left = iround((Sideview_pHandeled[i].rc.left -FRACT)*dx)+x0;
- Sideview_pHandeled[i].rc.right = iround((Sideview_pHandeled[i].rc.right +FRACT)*dx)+x0;
- if( Sideview_pHandeled[i].rc.bottom > 0)
- Sideview_pHandeled[i].rc.bottom = CalcHeightCoordinat((double) Sideview_pHandeled[i].rc.bottom, rc, psDiag);
- else
- Sideview_pHandeled[i].rc.bottom = rc.bottom;
+ Sideview_pHandeled[i].rc.left = iround((Sideview_pHandeled[i].rc.left )*dx)+x0 -FRAMEWIDTH/2;
+ Sideview_pHandeled[i].rc.right = iround((Sideview_pHandeled[i].rc.right+1)*dx)+x0+ FRAMEWIDTH/2;
- Sideview_pHandeled[i].rc.top = CalcHeightCoordinat((double) Sideview_pHandeled[i].rc.top, rc, psDiag);
+ Sideview_pHandeled[i].rc.bottom = CalcHeightCoordinat((double) Sideview_pHandeled[i].rc.bottom, rc, psDiag);//+FRAMEWIDTH/2;
+ Sideview_pHandeled[i].rc.top = CalcHeightCoordinat((double) Sideview_pHandeled[i].rc.top, rc, psDiag)-FRAMEWIDTH/2;
+ Sideview_pHandeled[i].iMaxBase = Sideview_pHandeled[i].rc.bottom ;
+ Sideview_pHandeled[i].iMinTop = Sideview_pHandeled[i].rc.top ;
+ int iN = Sideview_pHandeled[i].iNoPolyPts;
if(Sideview_pHandeled[i].bRectAllowed == false)
- for(j =0 ; j < Sideview_pHandeled[i].iNoPolyPts ; j++)
+ for(j =0 ; j < iN ; j++)
{
Sideview_pHandeled[i].apPolygon[j].x = iround(Sideview_pHandeled[i].apPolygon[j].x * dx)+x0;
- if( Sideview_pHandeled[i].apPolygon[j].y > 0)
- Sideview_pHandeled[i].apPolygon[j].y = CalcHeightCoordinat((double) Sideview_pHandeled[i].apPolygon[j].y, rc, psDiag);
- else
- Sideview_pHandeled[i].apPolygon[j].y = rc.bottom;
-
+ Sideview_pHandeled[i].apPolygon[j].y = CalcHeightCoordinat((double) Sideview_pHandeled[i].apPolygon[j].y, rc, psDiag);
+ if(j != iN-1)
+ {
+ if(( j < iN /2) )
+ Sideview_pHandeled[i].iMaxBase = min ((long)Sideview_pHandeled[i].iMaxBase ,(long)Sideview_pHandeled[i].apPolygon[j].y);
+ else
+ Sideview_pHandeled[i].iMinTop = max ((long)Sideview_pHandeled[i].iMinTop , (long)Sideview_pHandeled[i].apPolygon[j].y);
+ }
}
}
-
-
/**********************************************************************************
* draw airspaces
**********************************************************************************/
HPEN mpen = (HPEN)CreatePen(PS_NULL, 0, RGB(0xf0,0xf0,0xb0));
- HPEN oldpen = (HPEN)SelectObject(hdc, (HPEN)mpen);
+ HPEN oldpen = (HPEN)SelectObject(hdc, (HPEN)NULL);
_TCHAR text [80];
SIZE tsize;
+
for (int m=0 ; m < Sideview_iNoHandeldSpaces; m++)
{
int iSizeIdx = iSizeLookupTable[m];
- {
+
int type = Sideview_pHandeled[iSizeIdx].iType;
RECT rcd = Sideview_pHandeled[iSizeIdx].rc;
+ double fFrameColFact;
if(Sideview_pHandeled[iSizeIdx].bEnabled)
{
SelectObject(hdc, MapWindow::GetAirspaceBrushByClass(type));
SetTextColor(hdc, MapWindow::GetAirspaceColourByClass(type));
- if(Sideview_pHandeled[iSizeIdx].bRectAllowed == true)
- {
- Rectangle(hdc,rcd.left+1,rcd.top,rcd.right,rcd.bottom);
- }
- else
- {
- Polygon(hdc,Sideview_pHandeled[iSizeIdx].apPolygon ,Sideview_pHandeled[iSizeIdx].iNoPolyPts );
- }
- }
+ fFrameColFact = 0.8;
+ }
+ else
{
- // NULL_BRUSH
SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
- double fFrameColFact = 1.0;
- if(INVERTCOLORS)
- fFrameColFact = 0.8;
- else
- fFrameColFact = 1.2;
- long lDisabledColor = ChangeBrightness( MapWindow::GetAirspaceColourByClass(type), fFrameColFact);
+ SetTextColor(hdc, RGB_GGREY);
+ fFrameColFact = 1.2;
+ }
+ if(INVERTCOLORS)
+ fFrameColFact *= 0.8;
+ else
+ fFrameColFact *= 1.2;
+ long lColor = ChangeBrightness( MapWindow::GetAirspaceColourByClass(type), fFrameColFact);
+ HPEN mpen =(HPEN)CreatePen(PS_SOLID,FRAMEWIDTH,lColor);
+ HPEN oldpen = (HPEN)SelectObject(hdc, (HPEN)mpen);
+
+ if(Sideview_pHandeled[iSizeIdx].bRectAllowed == true)
+ Rectangle(hdc,rcd.left+1,rcd.top,rcd.right,rcd.bottom);
+ else
+ Polygon(hdc,Sideview_pHandeled[iSizeIdx].apPolygon ,Sideview_pHandeled[iSizeIdx].iNoPolyPts );
+ SelectObject(hdc, (HPEN)oldpen);
+ DeleteObject (mpen);
- // HPEN Newpen = (HPEN)CreatePen(PS_DOT, 3, lDisabledColor);
- HPEN Newpen = (HPEN)CreatePen(PS_SOLID, 3, lDisabledColor);
- HPEN Oldpen = (HPEN)SelectObject(hdc, Newpen);
#define LINE_DIFF 2
- if(Sideview_pHandeled[iSizeIdx].bRectAllowed == true)
- Rectangle(hdc,rcd.left+LINE_DIFF ,rcd.top - LINE_DIFF,rcd.right-LINE_DIFF,rcd.bottom+LINE_DIFF-1);
- else
- {
- Polygon(hdc,Sideview_pHandeled[iSizeIdx].apPolygon ,Sideview_pHandeled[iSizeIdx].iNoPolyPts );
- }
-#if TESTBENCH > 0
- SelectObject(hdc, GetStockObject(BLACK_PEN));
- Rectangle(hdc,rcd.left+1,rcd.top,rcd.right,rcd.bottom);
-#endif
- SelectObject(hdc, Oldpen);
- DeleteObject (Newpen);
- }
+ /************************************/
+// SetBkMode(hdc, OPAQUE); /* OPAQUE may be better readable but verry ugly
+ /************************************/
+ if(Sideview_pHandeled[iSizeIdx].bEnabled)
+ SetTextColor(hdc, Sideview_TextColor); // RGB_MENUTITLEFG
+ else
+ SetTextColor(hdc, RGB_GGREY);
- /************************************/
- // SetBkMode(hdc, OPAQUE); /* OPAQUE may be better readable but verry ugly
- /************************************/
- if(Sideview_pHandeled[iSizeIdx].bEnabled)
- SetTextColor(hdc, Sideview_TextColor); // RGB_MENUTITLEFG
- else
- SetTextColor(hdc, RGB_GGREY);
-
- /***********************************************
- * build view overlap for centering text
- ***********************************************/
- rcd.left = max(rcd.left ,rc.left);
- rcd.right = min(rcd.right ,rc.right);
- rcd.bottom = max(rcd.bottom ,rc.top);
- rcd.top = min(rcd.top ,rc.bottom);
-
- int x = rcd.left + (rcd.right - rcd.left)/2;
- int y = rcd.top - (rcd.top - rcd.bottom)/2;
-
- _tcsncpy(text, Sideview_pHandeled[iSizeIdx].szAS_Name,NAME_SIZE-1/* sizeof(text)/sizeof(text[0])*/);
- GetTextExtentPoint(hdc, text, _tcslen(text), &tsize);
- x -= tsize.cx/2; // - NIBLSCALE(5);
- y -= tsize.cy; // - NIBLSCALE(5);
- if (
- (tsize.cx < (rcd.right-rcd.left)) &&
- ((y) < rcd.top) &&
- ((y + tsize.cy) > rcd.bottom)
- )
- {
- ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, text, _tcslen(text), NULL);
- y = rcd.top - (rcd.top - rcd.bottom)/2;
- }
+ /***********************************************
+ * build view overlap for centering text
+ ***********************************************/
+ rcd.bottom = min( rcd.bottom, (long)Sideview_pHandeled[iSizeIdx].iMaxBase );
+ rcd.top = max( rcd.top , (long)Sideview_pHandeled[iSizeIdx].iMinTop );
- _tcsncpy((wchar_t*)text, (wchar_t*) CAirspaceManager::Instance().GetAirspaceTypeShortText( Sideview_pHandeled[iSizeIdx].iType), NAME_SIZE);
- GetTextExtentPoint(hdc, text, _tcslen(text), &tsize);
- x = rcd.left + (rcd.right - rcd.left)/2;
- if (
- (tsize.cx < (rcd.right-rcd.left)) &&
- ((y) < rcd.top) &&
- ((y + tsize.cy) > rcd.bottom)
- )
- {
- x -= tsize.cx/2; // - NIBLSCALE(5);
- ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, text, _tcslen(text), NULL);
- }
- }
+ rcd.left = max(rcd.left ,rc.left);
+ rcd.right = min(rcd.right ,rc.right);
+ rcd.bottom = min(rcd.bottom ,rc.bottom);
+ rcd.top = max(rcd.top ,rc.top);
+
+
+/*
+SelectObject(hdc, GetStockObject(WHITE_PEN));
+Rectangle(hdc,rcd.left+1,rcd.top,rcd.right,rcd.bottom);
+*/
+
+ _tcsncpy(text, Sideview_pHandeled[iSizeIdx].szAS_Name,NAME_SIZE-1/* sizeof(text)/sizeof(text[0])*/);
+ GetTextExtentPoint(hdc, text, _tcslen(text), &tsize);
+
+ int x ;
+ int y = rcd.bottom + (rcd.top - rcd.bottom)/2 -tsize.cy;
+ int iTextheight = tsize.cy;
+
+ if ( (tsize.cx < (rcd.right-rcd.left)) && (iTextheight < (rcd.bottom-rcd.top) ) )
+ {
+ x = rcd.left + (rcd.right - rcd.left - tsize.cx)/2;
+ ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, text, _tcslen(text), NULL);
+ y = rcd.bottom + (rcd.top - rcd.bottom )/2;
+ iTextheight = 2*tsize.cy;
}
+ _tcsncpy((wchar_t*)text, (wchar_t*) CAirspaceManager::Instance().GetAirspaceTypeShortText( Sideview_pHandeled[iSizeIdx].iType), NAME_SIZE);
+ GetTextExtentPoint(hdc, text, _tcslen(text), &tsize);
+ x = rcd.left + (rcd.right - rcd.left)/2;
+ if ( (tsize.cx < (rcd.right-rcd.left)) && (iTextheight < (rcd.bottom-rcd.top)) )
+ {
+ x = rcd.left + (rcd.right - rcd.left - tsize.cx)/2; // - NIBLSCALE(5);
+ ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, text, _tcslen(text), NULL);
+ }
+}
+
+if(1==0)
+ for (int m=0 ; m < Sideview_iNoHandeldSpaces; m++)
+ {
+
+ int iSizeIdx = iSizeLookupTable[m];
+ int type = Sideview_pHandeled[iSizeIdx].iType;
+ RECT rcd = Sideview_pHandeled[iSizeIdx].rc;
+ // NULL_BRUSH
+ SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
+ double fFrameColFact = 1.0;
+ if(INVERTCOLORS)
+ fFrameColFact = 0.8;
+ else
+ fFrameColFact = 1.2;
+ long lDisabledColor = ChangeBrightness( MapWindow::GetAirspaceColourByClass(type), fFrameColFact);
+
+ HPEN Newpen = (HPEN)CreatePen(PS_SOLID, 3, lDisabledColor);
+ HPEN Oldpen = (HPEN)SelectObject(hdc, Newpen);
+
+ if(Sideview_pHandeled[iSizeIdx].bRectAllowed == true)
+ Rectangle(hdc,rcd.left+LINE_DIFF ,rcd.top - LINE_DIFF,rcd.right-LINE_DIFF,rcd.bottom+LINE_DIFF-1);
+ else
+ {
+ Polygon(hdc,Sideview_pHandeled[iSizeIdx].apPolygon ,Sideview_pHandeled[iSizeIdx].iNoPolyPts );
+ }
+#if TESTBENCH > 0
+ SelectObject(hdc, GetStockObject(BLACK_PEN));
+ Rectangle(hdc,rcd.left+1,rcd.top,rcd.right,rcd.bottom);
+#endif
+ SelectObject(hdc, Oldpen);
+ DeleteObject (Newpen);
+ }
+ /*************************************************************
+ * draw ground
+ *************************************************************/
int iBottom = rc.bottom;
// draw ground
- POINT ground[4];
+
HPEN hpHorizonGround;
HBRUSH hbHorizonGround;
- int itemp;
+
hpHorizonGround = (HPEN)CreatePen(PS_SOLID, IBLSCALE(1), GROUND_COLOUR);
hbHorizonGround = (HBRUSH)CreateSolidBrush(GROUND_COLOUR);
SelectObject(hdc, hpHorizonGround);
@@ -252,37 +276,26 @@ void RenderAirspaceTerrain(HDC hdc, const RECT rc,double PosLat, double PosLon,
if(psDiag->fYMin < GC_SEA_LEVEL_TOLERANCE)
Rectangle(hdc,rc.left,rc.bottom,rc.right,rc.bottom-BORDER_Y);
#endif
- y0 = iBottom;
- SelectObject(hdc, hpHorizonGround);
- SelectObject(hdc, hbHorizonGround);
-
-
- for (j=1; j< AIRSPACE_SCANSIZE_X; j++) { // scan range
- ground[0].x = iround((j-1)*dx)+x0;
- ground[1].x = ground[0].x;
- ground[2].x = iround(j*dx)+x0;
- ground[3].x = ground[2].x;
- ground[0].y = iBottom;
-
- if (hmax==hmin) hmax++; // RECOVER DIVISION BY ZERO!
+ /*********************************************************************
+ * draw terrain
+ *********************************************************************/
+ SelectObject(hdc, hpHorizonGround);
+ for (j=0; j< AIRSPACE_SCANSIZE_X; j++) { // scan range
+ apTerrainPolygon[j].x = iround(j*dx)+x0;
+ apTerrainPolygon[j].y = CalcHeightCoordinat(d_h[j], rc, psDiag)+2;
- itemp = iround((d_h[j-1]-hmin)/(hmax-hmin)*(rc.top-rc.bottom+BORDER_Y))+y0;
- if (itemp>y0) itemp = y0;
- ground[1].y = itemp;
- itemp = iround((d_h[j]-hmin)/(hmax-hmin)*(rc.top-rc.bottom+BORDER_Y))+y0;
- if (itemp>y0) itemp = y0;
- ground[2].y = itemp;
- ground[3].y = iBottom;// y0;
- if ((ground[1].y == y0) && (ground[2].y == y0)) continue;
- Polygon(hdc, ground, 4);
}
+ apTerrainPolygon[AIRSPACE_SCANSIZE_X].x = iround(AIRSPACE_SCANSIZE_X*dx)+x0;; // x0;
+ apTerrainPolygon[AIRSPACE_SCANSIZE_X].y = iBottom;
+ apTerrainPolygon[AIRSPACE_SCANSIZE_X+1].x = iround(0*dx)+x0; //iround(j*dx)+x0;
+ apTerrainPolygon[AIRSPACE_SCANSIZE_X+1].y = iBottom;
+ Polygon(hdc, apTerrainPolygon, AIRSPACE_SCANSIZE_X+2);
SetTextColor(hdc, Sideview_TextColor); // RGB_MENUTITLEFG
-
SelectObject(hdc, (HPEN)oldpen);
DeleteObject(mpen);
DeleteObject(hpHorizonGround);
Oops, something went wrong.

0 comments on commit 02d3149

Please sign in to comment.