Example #1
0
void DrawSelectionFrame(LKSurface& Surface, const RECT& rc)
{
Surface.SetBkMode(TRANSPARENT);
RECT rci = rc;
#define SHRINK 1
	rci.left +=1;
	rci.top -=1;
	rci.right -=2;
	rci.bottom -=2;
	int iSize = NIBLSCALE(2);
	LKColor col = RGB_BLACK;

  Surface.DrawLine   (PEN_SOLID, iSize, (POINT) {rci.left,rci.top}     ,(POINT) {rci.left,rci.bottom} , col, rci);
  Surface.DrawLine   (PEN_SOLID, iSize, (POINT) {rci.left,rci.bottom}  ,(POINT) {rci.right,rci.bottom}, col, rci);
  Surface.DrawLine   (PEN_SOLID, iSize, (POINT) {rci.right,rci.bottom} ,(POINT) {rci.right,rci.top}   , col, rci);
  Surface.DrawLine   (PEN_SOLID, iSize, (POINT) {rci.right,rci.top}    ,(POINT) {rci.left,rci.top}    , col, rci);

  col = RGB_YELLOW;
  Surface.DrawDashLine(iSize,(POINT) {rci.left,rci.top}    ,(POINT) {rci.left,rci.bottom} ,  col, rci);
  Surface.DrawDashLine(iSize,(POINT) {rci.left,rci.bottom} ,(POINT) {rci.right,rci.bottom},  col, rci);
  Surface.DrawDashLine(iSize,(POINT) {rci.right,rci.bottom},(POINT) {rci.right,rci.top}   ,  col, rci);
  Surface.DrawDashLine(iSize,(POINT) {rci.right,rci.top}   ,(POINT) {rci.left,rci.top}    ,  col, rci);


}
Example #2
0
void MapWindow::DrawHeadUpLine(LKSurface& Surface, const POINT& Orig, const RECT& rc, double fMin, double fMax  ) {

    const double tmp = fMax*zoom.ResScaleOverDistanceModify();
    const double trackbearing =  DisplayAircraftAngle+  (DerivedDrawInfo.Heading-DrawInfo.TrackBearing);

    const POINT p2 = { Orig.x + (int)(tmp*fastsine(trackbearing)), Orig.y - (int)(tmp*fastcosine(trackbearing)) };

    const LKColor rgbCol = BlackScreen?RGB_INVDRAW:RGB_BLACK;

    // Reduce the rectangle for a better effect
    const RECT ClipRect = {rc.left+NIBLSCALE(5), rc.top+NIBLSCALE(5), rc.right-NIBLSCALE(5), rc.bottom-NIBLSCALE(5) };
    Surface.DrawLine(PEN_SOLID, NIBLSCALE(1), Orig, p2, rgbCol, ClipRect);
}
Example #3
0
void MapWindow::DrawFuturePos(LKSurface& Surface, const POINT& Orig, const RECT& rc, bool headUpLine) {
    if(DrawInfo.Speed < 13.88) return; //Don't continue if ground speed < 50 Km/h
    const double trackBearing = headUpLine ? DisplayAircraftAngle+(DerivedDrawInfo.Heading-DrawInfo.TrackBearing) : DrawInfo.TrackBearing;
    const double dist2min=120*DrawInfo.Speed*zoom.ResScaleOverDistanceModify(); // 2 min
    if(dist2min>=NIBLSCALE(3)) { //proceed only if the distance is not too small on the map
        const double dist5min=300*DrawInfo.Speed*zoom.ResScaleOverDistanceModify(); // 5 min
        const double dist10min=600*DrawInfo.Speed*zoom.ResScaleOverDistanceModify(); //10 min
        
        // Reduce the rectangle for a better effect
        const RECT ClipRect = (RECT){rc.left+NIBLSCALE(5), rc.top+NIBLSCALE(5), rc.right-NIBLSCALE(5), rc.bottom-NIBLSCALE(5) };

        POINT p1,p2;

        if( !MapWindow::mode.autoNorthUP() && !headUpLine && (DisplayOrientation==TRACKUP || DisplayOrientation==NORTHCIRCLE || DisplayOrientation==TARGETCIRCLE || DisplayOrientation==TARGETUP)) { //Track up map view
            p1.x=Orig.x-NIBLSCALE(4);
            p2.x=Orig.x+NIBLSCALE(4);
            p1.y=p2.y=Orig.y-(int)round(dist2min);
            Surface.DrawLine(PEN_SOLID,NIBLSCALE(1),p1,p2,BlackScreen?RGB_INVDRAW:RGB_BLACK,ClipRect);
            p1.y=p2.y=Orig.y-(int)round(dist5min);
            Surface.DrawLine(PEN_SOLID,NIBLSCALE(1),p1,p2,BlackScreen?RGB_INVDRAW:RGB_BLACK,ClipRect);
            p1.y=p2.y=Orig.y-(int)round(dist10min);
            Surface.DrawLine(PEN_SOLID,NIBLSCALE(1),p1,p2,BlackScreen?RGB_INVDRAW:RGB_BLACK,ClipRect);
        } else { //North up map view
            const double sin=fastsine(trackBearing);
            const double cos=fastcosine(trackBearing);
            double distXsin=dist2min*sin;
            double distXcos=dist2min*cos;
            const double tickXsin=NIBLSCALE(4)*sin;
            const double tickXcos=NIBLSCALE(4)*cos;
            p1.x=Orig.x+(int)round(distXsin-tickXcos);
            p1.y=Orig.y-(int)round(distXcos+tickXsin);
            p2.x=Orig.x+(int)round(distXsin+tickXcos);
            p2.y=Orig.y-(int)round(distXcos-tickXsin);
            Surface.DrawLine(PEN_SOLID,NIBLSCALE(1),p1,p2,BlackScreen?RGB_INVDRAW:RGB_BLACK,ClipRect);
            distXsin=dist5min*sin;
            distXcos=dist5min*cos;
            p1.x=Orig.x+(int)round(distXsin-tickXcos);
            p1.y=Orig.y-(int)round(distXcos+tickXsin);
            p2.x=Orig.x+(int)round(distXsin+tickXcos);
            p2.y=Orig.y-(int)round(distXcos-tickXsin);
            Surface.DrawLine(PEN_SOLID,NIBLSCALE(1),p1,p2,BlackScreen?RGB_INVDRAW:RGB_BLACK,ClipRect);
            distXsin=dist10min*sin;
            distXcos=dist10min*cos;
            p1.x=Orig.x+(int)round(distXsin-tickXcos);
            p1.y=Orig.y-(int)round(distXcos+tickXsin);
            p2.x=Orig.x+(int)round(distXsin+tickXcos);
            p2.y=Orig.y-(int)round(distXcos-tickXsin);
            Surface.DrawLine(PEN_SOLID,NIBLSCALE(1),p1,p2,BlackScreen?RGB_INVDRAW:RGB_BLACK,ClipRect);
        }
    }
}
Example #4
0
void MapWindow::DrawStartEndSector(LKSurface& Surface, const RECT& rc,
        const POINT &Start, const POINT &End, int Index,
        int Type, double Radius) {

    double tmp;
    LKSurface::OldPen oldpen;
    LKSurface::OldBrush oldbrush;

    switch (Type) {
        case 0: // CIRCLE
            tmp = Radius * zoom.ResScaleOverDistanceModify();
            oldpen = Surface.SelectObject(hpStartFinishThick);
            oldbrush = Surface.SelectObject(LKBrush_Hollow);
            Surface.Circle(WayPointList[Index].Screen.x,
                    WayPointList[Index].Screen.y, (int) tmp, rc, false, false);
            Surface.SelectObject(LKPen_Red_N1);
            Surface.Circle(WayPointList[Index].Screen.x,
                    WayPointList[Index].Screen.y, (int) tmp, rc, false, false);

            Surface.SelectObject(oldpen);
            Surface.SelectObject(oldbrush);
            break;
        case 1: // LINE
            Surface.DrawLine(PEN_SOLID, NIBLSCALE(5), End, Start, taskcolor, rc);
            Surface.DrawLine(PEN_SOLID, NIBLSCALE(1), End, Start, LKColor(255, 0, 0), rc);
            break;
        case 2: // SECTOR
            Surface.DrawLine(PEN_SOLID, NIBLSCALE(5), WayPointList[Index].Screen,
                    Start, taskcolor, rc);
            Surface.DrawLine(PEN_SOLID, NIBLSCALE(5), WayPointList[Index].Screen,
                    End, taskcolor, rc);
            Surface.DrawLine(PEN_SOLID, NIBLSCALE(1), WayPointList[Index].Screen,
                    Start, LKColor(255, 0, 0), rc);
            Surface.DrawLine(PEN_SOLID, NIBLSCALE(1), WayPointList[Index].Screen,
                    End, LKColor(255, 0, 0), rc);
            break;
    }

}
void MapWindow::DrawAspNearest(LKSurface& Surface, const RECT& rc) {


  SIZE ASPTextSize, DSTextSize, BETextSize, TYTextSize, ACTextSize, HLTextSize, MITextSize;
  SIZE phdrTextSize;
  TCHAR Buffer[LKSIZEBUFFERLARGE];
  static RECT s_sortBox[6]; 
  static TCHAR Buffer1[MAXNEARAIRSPACES][MAXAIRSPACENUMPAGES][30], Buffer2[MAXNEARAIRSPACES][MAXAIRSPACENUMPAGES][12];
  static TCHAR Buffer3[MAXNEARAIRSPACES][MAXAIRSPACENUMPAGES][12];
  static TCHAR Buffer4[MAXNEARAIRSPACES][MAXAIRSPACENUMPAGES][12], Buffer5[MAXNEARAIRSPACES][MAXAIRSPACENUMPAGES][12];
  static short s_maxnlname;
  static TCHAR s_trailspace[3];
  short i, j, k, iRaw, wlen, rli=0, curpage, drawn_items_onpage;
  double value;
  LKColor rcolor;

  // column0 starts after writing 1:2 (ModeIndex:CURTYPE+1) with a different font..
  static short Column0;
  static short Column1, Column2, Column3, Column4, Column5;
  static POINT p1, p2;
  static short s_rawspace;
  static unsigned short lincr;
  // Printable area for live nearest values
  static short left,right,bottom;
  // one for each mapspace, no matter if 0 and 1 are unused

  // we lock to current mapspace for this drawing
  short curmapspace=MapSpaceMode; 

  static int AspNumraws=0;
  static bool usetwolines=0;


  // Vertical and horizontal spaces
  #define INTERRAW	1
  #define HEADRAW	NIBLSCALE(6)	
  BrushReference sortbrush;
  RECT invsel;

  if (INVERTCOLORS) {
  	sortbrush=LKBrush_LightGreen;
  } else {
  	sortbrush=LKBrush_DarkGreen;
  }

  if (DoInit[MDI_DRAWASPNEAREST]) {

  usetwolines=UseTwoLines;

  // Set screen borders to avoid writing on extreme pixels
  if ( !ScreenLandscape ) {
	// Portrait mode can work on two rows
	left=rc.left+NIBLSCALE(1);
	right=rc.right-NIBLSCALE(1);
  	bottom=rc.bottom-BottomSize-NIBLSCALE(2);
	s_maxnlname=7; 
  	_stprintf(Buffer,TEXT("AKSJSMMMM"));  
  } else {
	left=rc.left+NIBLSCALE(5);
	right=rc.right-NIBLSCALE(5);
  	bottom=rc.bottom-BottomSize;
	s_maxnlname=15; 
  	_stprintf(Buffer,TEXT("ABCDEF GHIJK-LM"));  
	// now resize for tuning on resolutions
	if (ScreenSize == ss320x240) s_maxnlname=9;
	if (ScreenSize == ss400x240) s_maxnlname=10;
  }
  Buffer[s_maxnlname]='\0';


  /// WPT is now AIRSPACE name
  Surface.SelectObject(LK8InfoBigFont); // Text font for Nearest  was LK8Title
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &ASPTextSize);

  // DST is always distance
  _stprintf(Buffer,TEXT("000.0")); 
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &DSTextSize);

  // Bearing
  _stprintf(Buffer,TEXT("<<123")); 
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &BETextSize);

  // TYPE, 4 letters printed
  #define LKASP_TYPE_LEN	4
  _stprintf(Buffer,TEXT("CTRA")); 
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &TYTextSize);

  // Flags can be SFE, three chars
  _stprintf(Buffer,TEXT("SFE")); 
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &ACTextSize);

  Surface.SelectObject(LK8InfoNormalFont);
  _stprintf(Buffer,TEXT("MMMM")); 
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &HLTextSize);

  Surface.SelectObject(LK8PanelMediumFont);
  _stprintf(Buffer,TEXT("1.1")); 
  Surface.GetTextSize(Buffer, _tcslen(Buffer), &MITextSize);

  short afterwpname=left+ASPTextSize.cx+NIBLSCALE(5);
  short intercolumn=(right-afterwpname- DSTextSize.cx-BETextSize.cx-TYTextSize.cx-ACTextSize.cx)/3; 

  // Col0 is where ASP 1/3 can be written, after ModeIndex:Curtype
  Column0=MITextSize.cx+LEFTLIMITER+NIBLSCALE(5);
  Column1=left;							// WP align left

  if (ScreenLandscape || !usetwolines) {
      Column2=afterwpname+TYTextSize.cx;				// TY align right
      Column3=Column2+intercolumn+DSTextSize.cx;			// DS align right
      Column4=Column3+intercolumn+BETextSize.cx;			// BE align right
      Column5=Column4+intercolumn+ACTextSize.cx;			// AC align right
  } else {
      Surface.SelectObject(LK8PanelMediumFont);
      Surface.GetTextSize(_T("2.4_ASP_3/3_"), 12, &phdrTextSize);
      int s=(rc.right - phdrTextSize.cx)/4;
      Column5= right - NIBLSCALE(2);
      Column4= Column5 - s;
      Column3= Column4 - s;
      Column2= Column3 - s;
  }

  if ( !ScreenLandscape ) {
        if (usetwolines) {
	    lincr=2;
  	    TopSize=rc.top+HEADRAW*2+ASPTextSize.cy;
        } else {
	    lincr=1;
  	    TopSize=rc.top+HEADRAW*2+HLTextSize.cy;
        }
  	p1.x=0; p1.y=TopSize; p2.x=rc.right; p2.y=p1.y;
  	TopSize+=HEADRAW;
  	AspNumraws=(bottom - TopSize) / (ASPTextSize.cy+(INTERRAW*2));
  	if (AspNumraws>MAXNEARAIRSPACES) AspNumraws=MAXNEARAIRSPACES;
  	s_rawspace=(ASPTextSize.cy+INTERRAW);
	Column5=rc.right-NIBLSCALE(1)-1;
	_tcscpy(s_trailspace,_T(""));
  } else {
	lincr=1;
  	TopSize=rc.top+HEADRAW*2+HLTextSize.cy;
  	p1.x=0; p1.y=TopSize; p2.x=rc.right; p2.y=p1.y;
  	TopSize+=HEADRAW/2;
  	AspNumraws=(bottom - TopSize) / (ASPTextSize.cy+INTERRAW);
  	if (AspNumraws>MAXNEARAIRSPACES) AspNumraws=MAXNEARAIRSPACES;
  	s_rawspace=(ASPTextSize.cy+INTERRAW);
	_tcscpy(s_trailspace,_T(" "));
  }

#define INTERBOX intercolumn/2

  s_sortBox[0].left=Column0; 
  if (!ScreenLandscape && usetwolines) {
      s_sortBox[0].right=phdrTextSize.cx;
  } else {
      if ( !ScreenLandscape ) s_sortBox[0].right= left+ASPTextSize.cx-NIBLSCALE(2);
      else s_sortBox[0].right=left+ASPTextSize.cx-NIBLSCALE(10);
  }
  s_sortBox[0].top=2;
  s_sortBox[0].bottom=p1.y;
  SortBoxX[MSM_AIRSPACES][0]=s_sortBox[0].right;

  if (!ScreenLandscape && usetwolines) {
      s_sortBox[1].left=s_sortBox[0].right;
  } else {
      if ( !ScreenLandscape ) s_sortBox[1].left=Column1+afterwpname-INTERBOX;
      else s_sortBox[1].left=Column1+afterwpname-INTERBOX-NIBLSCALE(2);
  }

  if (!ScreenLandscape && usetwolines) s_sortBox[1].right=Column2+NIBLSCALE(2);
  else s_sortBox[1].right=Column2+INTERBOX;
  s_sortBox[1].top=2;
  s_sortBox[1].bottom=p1.y;
  SortBoxX[MSM_AIRSPACES][1]=s_sortBox[1].right;

  if (!ScreenLandscape && usetwolines) {
      s_sortBox[2].left=Column2+NIBLSCALE(2);
      s_sortBox[2].right=Column3+NIBLSCALE(2);
  } else {
      s_sortBox[2].left=Column2+INTERBOX;
      s_sortBox[2].right=Column3+INTERBOX;
  }
  s_sortBox[2].top=2;
  s_sortBox[2].bottom=p1.y;
  SortBoxX[MSM_AIRSPACES][2]=s_sortBox[2].right;

  if (!ScreenLandscape && usetwolines) {
      s_sortBox[3].left=Column3+NIBLSCALE(2);
      s_sortBox[3].right=Column4+NIBLSCALE(2);
  } else {
      s_sortBox[3].left=Column3+INTERBOX;
      s_sortBox[3].right=Column4+INTERBOX;
  }
  s_sortBox[3].top=2;
  s_sortBox[3].bottom=p1.y;
  SortBoxX[MSM_AIRSPACES][3]=s_sortBox[3].right;

  if (!ScreenLandscape && usetwolines) {
      s_sortBox[4].left=Column4+NIBLSCALE(2);
      s_sortBox[4].right=rc.right-1;
  } else {
      s_sortBox[4].left=Column4+INTERBOX;
      s_sortBox[4].right=rc.right-1;
  }
  s_sortBox[4].top=2;
  s_sortBox[4].bottom=p1.y;
  SortBoxX[MSM_AIRSPACES][4]=s_sortBox[4].right;

  SortBoxY[MSM_AIRSPACES]=p1.y;

  AspNumpages=roundupdivision(MAXNEARAIRSPACES*lincr, AspNumraws);
  if (AspNumpages>MAXAIRSPACENUMPAGES) AspNumpages=MAXAIRSPACENUMPAGES;
  else if (AspNumpages<1) AspNumpages=1;

  SelectedRaw[MSM_AIRSPACES]=0;
  SelectedPage[MSM_AIRSPACES]=0;

  DoInit[MDI_DRAWASPNEAREST]=false;
  return;
  } // doinit

  bool ndr;
  ndr=DoAirspaces(&DrawInfo, &DerivedDrawInfo);

  AspNumpages=roundupdivision(LKNumAirspaces*lincr, AspNumraws);
  if (AspNumpages>MAXAIRSPACENUMPAGES) AspNumpages=MAXAIRSPACENUMPAGES;
  else if (AspNumpages<1) AspNumpages=1;

  curpage=SelectedPage[curmapspace];
  if (curpage<0||curpage>=MAXAIRSPACENUMPAGES) { // TODO also >Numpages
	SelectedPage[curmapspace]=0;
	LKevent=LKEVENT_NONE;
	return;
  }

  switch (LKevent) {
	case LKEVENT_NONE:
		break;
	case LKEVENT_ENTER:
		LKevent=LKEVENT_NONE;
		i=LKSortedAirspaces[SelectedRaw[curmapspace] + (curpage*AspNumraws/lincr)];

		if ( ValidAirspace(i)) {
            CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef());
            CAirspaceManager::Instance().PopupAirspaceDetail(LKAirspaces[i].Pointer);
        }
		LKevent=LKEVENT_NONE; 
		return;
		break;
	case LKEVENT_DOWN:
		if (++SelectedRaw[curmapspace] >=AspNumraws) SelectedRaw[curmapspace]=0;
		break;
	case LKEVENT_UP:
		if (--SelectedRaw[curmapspace] <0) SelectedRaw[curmapspace]=AspNumraws-1;
		break;
	case LKEVENT_PAGEUP:
		LKevent=LKEVENT_NONE;
		break;
	case LKEVENT_PAGEDOWN:
		LKevent=LKEVENT_NONE;
		break;
	case LKEVENT_NEWRUN:
		for (i=0; i<MAXNEARAIRSPACES; i++) {
			for (k=0; k<MAXAIRSPACENUMPAGES; k++) {
				_stprintf(Buffer1[i][k], _T("----------------------------"));  // max 30
				Buffer1[i][k][s_maxnlname+7]='\0'; // some more dashes 
				_stprintf(Buffer2[i][k],_T("----"));
				_stprintf(Buffer3[i][k],_T("----"));
				_stprintf(Buffer4[i][k],_T("----"));
				_stprintf(Buffer5[i][k],_T("  "));
			}
		}
		break;
	case LKEVENT_NEWPAGE:
		break;
	default:
		LKevent=LKEVENT_NONE;
		break;
  }

  if (INVERTCOLORS)
	  Surface.DrawLine(PEN_SOLID, NIBLSCALE(1), p1, p2, RGB_GREEN, rc);
  else
	  Surface.DrawLine(PEN_SOLID, NIBLSCALE(1), p1, p2, RGB_DARKGREEN, rc);

  Surface.SelectObject(LK8InfoNormalFont); // Heading line

  short cursortbox=SortedMode[curmapspace];

  if ( !ScreenLandscape ) { // portrait mode
	Surface.FillRect(&s_sortBox[cursortbox], sortbrush);

	_stprintf(Buffer,TEXT("%d.%d"),ModeIndex,CURTYPE+1);
  	Surface.SelectObject(LK8PanelMediumFont);

	LKWriteText(Surface, Buffer, LEFTLIMITER, rc.top+TOPLIMITER , 0,  WTMODE_NORMAL, WTALIGN_LEFT, RGB_LIGHTGREEN, false);
  	Surface.SelectObject(LK8InfoNormalFont);

	_stprintf(Buffer,TEXT("%s %d/%d"), gettext(TEXT("_@M1642_")), curpage+1, AspNumpages);  // ASP

	if (cursortbox == 0)
		LKWriteText(Surface, Buffer, Column0, HEADRAW-NIBLSCALE(1) , 0, WTMODE_NORMAL, WTALIGN_LEFT, RGB_BLACK, false);
	else
		LKWriteText(Surface, Buffer, Column0, HEADRAW-NIBLSCALE(1) , 0, WTMODE_NORMAL, WTALIGN_LEFT, RGB_LIGHTGREEN, false);

	_tcscpy(Buffer,gettext(TEXT("_@M752_"))); // Type
	if (cursortbox==1)
		LKWriteText(Surface, Buffer, Column2, HEADRAW , 0, WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
	else
		LKWriteText(Surface, Buffer, Column2, HEADRAW , 0, WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

	_tcscpy(Buffer,gettext(TEXT("_@M1300_")));  // Dist
	if (cursortbox==2)
		LKWriteText(Surface, Buffer, Column3, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
	else
		LKWriteText(Surface, Buffer, Column3, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

	_tcscpy(Buffer,gettext(TEXT("_@M1301_")));  // Dir
	if (cursortbox==3)
		LKWriteText(Surface, Buffer, Column4, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
	else
		LKWriteText(Surface, Buffer, Column4, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

	// Active mode
	_tcscpy(Buffer,TEXT("*")); 
	if (cursortbox==4)
		LKWriteText(Surface, Buffer, Column5, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
	else
		LKWriteText(Surface, Buffer, Column5, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);


  } else {
	Surface.FillRect(&s_sortBox[cursortbox], sortbrush);

		_stprintf(Buffer,TEXT("%d.%d"),ModeIndex,CURTYPE+1);
  		Surface.SelectObject(LK8PanelMediumFont);
		LKWriteText(Surface, Buffer, LEFTLIMITER, rc.top+TOPLIMITER , 0, WTMODE_NORMAL, WTALIGN_LEFT, RGB_LIGHTGREEN, false);
  		Surface.SelectObject(LK8InfoNormalFont);

		_stprintf(Buffer,TEXT("%s %d/%d"), gettext(TEXT("_@M1642_")), curpage+1, AspNumpages);  // ASP

		if (cursortbox==0)
			LKWriteText(Surface, Buffer, Column0, HEADRAW-NIBLSCALE(1) , 0,WTMODE_NORMAL, WTALIGN_LEFT, RGB_BLACK, false);
		else
			LKWriteText(Surface, Buffer, Column0, HEADRAW-NIBLSCALE(1) , 0,WTMODE_NORMAL, WTALIGN_LEFT, RGB_LIGHTGREEN, false);

		_tcscpy(Buffer,gettext(TEXT("_@M752_"))); // Type
		if (cursortbox==1)
			LKWriteText(Surface, Buffer, Column2, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
		else
			LKWriteText(Surface, Buffer, Column2, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

		_tcscpy(Buffer,gettext(TEXT("_@M1300_")));  // Dist
		if (cursortbox==2)
			LKWriteText(Surface, Buffer, Column3, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
		else
			LKWriteText(Surface, Buffer, Column3, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

		_tcscpy(Buffer,gettext(TEXT("_@M1301_")));  // dir
		if (cursortbox==3)
			LKWriteText(Surface, Buffer, Column4, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
		else
			LKWriteText(Surface, Buffer, Column4, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

		_stprintf(Buffer,TEXT("*"));
		if (cursortbox==4)
			LKWriteText(Surface, Buffer, Column5, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_BLACK, false);
		else
			LKWriteText(Surface, Buffer, Column5, HEADRAW , 0,WTMODE_NORMAL, WTALIGN_RIGHT, RGB_WHITE, false);

  } // landscape mode


  Surface.SelectObject(LK8InfoBigFont); // Text font for Nearest


  int *psortedindex;
  psortedindex=LKSortedAirspaces;

  for (i=0, j=0, drawn_items_onpage=0; i<AspNumraws; j++, i+=lincr) {
	iRaw=TopSize+(s_rawspace*i);
	short curraw=(curpage*AspNumraws);
        if (!ScreenLandscape && usetwolines) {
            curraw/=2;
            curraw+=j;
        } else {
            curraw+=i;
        }
	if (curraw>=MAXNEARAIRSPACES) break;

	rli=*(psortedindex+curraw);

	if (!ndr) {
		goto KeepOldValues;
	}
	if ( ValidAirspace(rli) ) {

		//
		// AIRSPACE NAME
		//
		wlen=_tcslen(LKAirspaces[rli].Name);
		if (!ScreenLandscape && usetwolines) {
			LK_tcsncpy(Buffer, LKAirspaces[rli].Name, 15);
		} else {
			if (wlen>s_maxnlname) {
				LK_tcsncpy(Buffer, LKAirspaces[rli].Name, s_maxnlname);
			} else {
				LK_tcsncpy(Buffer, LKAirspaces[rli].Name, wlen);
			}
		}
		CharUpper(Buffer);
		_tcscpy(Buffer1[i][curpage],Buffer); 


		//
		// AIRSPACE TYPE
		//
		wlen=_tcslen(LKAirspaces[rli].Type);
		if (wlen>LKASP_TYPE_LEN) {
			LK_tcsncpy(Buffer, LKAirspaces[rli].Type, LKASP_TYPE_LEN);
		}
		else {
			LK_tcsncpy(Buffer, LKAirspaces[rli].Type, wlen);
		}
		CharUpper(Buffer);
		_tcscpy(Buffer2[i][curpage],Buffer); 

		
		//
		// AIRSPACE DISTANCE
		//
		switch(LKAirspaces[rli].WarningLevel) {
			case awYellow:
				value=LKAirspaces[rli].Distance*DISTANCEMODIFY;
				if (!ScreenLandscape && usetwolines) 
       				    _stprintf(Buffer3[i][curpage],TEXT("%0.1lf%s!"),value,Units::GetDistanceName());
				else
       				    _stprintf(Buffer3[i][curpage],TEXT("%0.1lf!"),value);
				break;
			case awRed:
       				_stprintf(Buffer3[i][curpage],TEXT("IN"));
				break;
			default:
				value=LKAirspaces[rli].Distance*DISTANCEMODIFY;
				if (!ScreenLandscape && usetwolines) 
       				    _stprintf(Buffer3[i][curpage],TEXT("%0.1lf%s"),value,Units::GetDistanceName());
				else
       				    _stprintf(Buffer3[i][curpage],TEXT("%0.1lf"),value);
				break;
		}

		//
		// AIRSPACE BEARING DIFFERENCE, OR BEARING IF CIRCLING
		//
		if (!MapWindow::mode.Is(MapWindow::Mode::MODE_CIRCLING)) {
			value = LKAirspaces[rli].Bearing -  DrawInfo.TrackBearing;

			if (value < -180.0)
				value += 360.0;
			else
				if (value > 180.0)
					value -= 360.0;

			if (value > 1)
				_stprintf(Buffer4[i][curpage], TEXT("%2.0f%s%s"), value, gettext(_T("_@M2179_")), gettext(_T("_@M2183_")));
			else if (value < -1)
				_stprintf(Buffer4[i][curpage], TEXT("%s%2.0f%s"), gettext(_T("_@M2182_")), -value, gettext(_T("_@M2179_")));
            else
			    _stprintf(Buffer4[i][curpage], TEXT("%s%s"), gettext(_T("_@M2182_")), gettext(_T("_@M2183_")));
		} else
			_stprintf(Buffer4[i][curpage], TEXT("%2.0f%s"), LKAirspaces[rli].Bearing, gettext(_T("_@M2179_")));


		//
		// AIRSPACE FLAGS
		//
		TCHAR aspflags[5];
		_stprintf(aspflags,_T("%s%s%s%s"),
			LKAirspaces[rli].Selected ? _T("S") : _T(""),
			LKAirspaces[rli].Flyzone  ? _T("F") : _T("  "),
			LKAirspaces[rli].Enabled  ? _T("E") : _T("D"), s_trailspace);

		if (!ScreenLandscape && usetwolines) _stprintf(Buffer5[i][curpage], TEXT("*%s"), aspflags);
		else _stprintf(Buffer5[i][curpage], TEXT("%s"), aspflags);

	} else {
		_stprintf(Buffer1[i][curpage], _T("----------------------------"));  // max 30
		Buffer1[i][curpage][s_maxnlname+7]='\0'; // some more dashes 
		_stprintf(Buffer2[i][curpage],_T("----"));
		_stprintf(Buffer3[i][curpage],_T("----"));
		_stprintf(Buffer4[i][curpage],_T("----"));
		_stprintf(Buffer5[i][curpage],_T("  "));
	}


KeepOldValues:

	if ( ValidAirspace(rli) ) {

		drawn_items_onpage++;

		switch(LKAirspaces[rli].WarningLevel) {
			case awYellow:
				rcolor=RGB_LIGHTYELLOW;
  				Surface.SelectObject(LK8InfoBigItalicFont);
				break;
			case awRed:
				rcolor=RGB_LIGHTRED;
  				Surface.SelectObject(LK8InfoBigItalicFont);
				break;
			case awNone:
			default:
				rcolor=RGB_WHITE;
  				Surface.SelectObject(LK8InfoBigFont);
				break;
		}
	} else {
		rcolor=RGB_GREY;
	}

	if (ScreenLandscape || !usetwolines) {
		LKWriteText(Surface, Buffer1[i][curpage], Column1, iRaw , 0, WTMODE_NORMAL, WTALIGN_LEFT, rcolor, false);
		LKWriteText(Surface, Buffer2[i][curpage], Column2, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
		LKWriteText(Surface, Buffer3[i][curpage], Column3, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
		LKWriteText(Surface, Buffer4[i][curpage], Column4, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
		LKWriteText(Surface, Buffer5[i][curpage], Column5, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
	} else {
		LKWriteText(Surface, Buffer1[i][curpage], Column1, iRaw , 0, WTMODE_NORMAL, WTALIGN_LEFT, rcolor, false);
		LKWriteText(Surface, Buffer2[i][curpage], Column5, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
		iRaw+=s_rawspace;
		unsigned int iCol=ScreenSizeX/3;
		LKWriteText(Surface, Buffer3[i][curpage], iCol, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
		LKWriteText(Surface, Buffer4[i][curpage], iCol*2, iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
		LKWriteText(Surface, Buffer5[i][curpage], right-IBLSCALE(2), iRaw , 0, WTMODE_NORMAL, WTALIGN_RIGHT, rcolor, false);
	}

  } 


  if (LKevent==LKEVENT_NEWRUN || LKevent==LKEVENT_NEWPAGE ) {
		LKevent=LKEVENT_NONE;
		return;
  }

  if (drawn_items_onpage>0) {

	if (SelectedRaw[curmapspace] <0 || SelectedRaw[curmapspace]>(AspNumraws-1)) {
		return;
	}
	if (SelectedRaw[curmapspace] >= drawn_items_onpage) {
		if (LKevent==LKEVENT_DOWN) SelectedRaw[curmapspace]=0;
		else 
		if (LKevent==LKEVENT_UP) SelectedRaw[curmapspace]=drawn_items_onpage-1;
		else {
			// DoStatusMessage(_T("Cant find valid raw")); not needed anymore
			SelectedRaw[curmapspace]=0;
		}
	}

	
	invsel.left=left;
	invsel.right=right;
        if (!ScreenLandscape && usetwolines) invsel.top=TopSize+(s_rawspace*SelectedRaw[curmapspace]*lincr);
	else invsel.top=TopSize+(s_rawspace*SelectedRaw[curmapspace])+NIBLSCALE(2);
	invsel.bottom=TopSize+(s_rawspace*(SelectedRaw[curmapspace]*lincr+1))-NIBLSCALE(1);
	if (!ScreenLandscape && usetwolines) invsel.bottom+=s_rawspace;

	Surface.InvertRect(invsel);

  } 

  LKevent=LKEVENT_NONE;
  return;
}
Example #6
0
int RenderFAISector (LKSurface& Surface, const RECT& rc , double lat1, double lon1, double lat2, double lon2, int iOpposite , const LKColor& fillcolor)
{

POINT Pt1;
float fFAI_Percentage = FAI_NORMAL_PERCENTAGE;
double fDist_a, fDist_b, fDist_c, fAngle;
int i;

int iPolyPtr=0;
double lat_d,lon_d;
double alpha, fDistTri, cos_alpha=0;
POINT apSectorPolygon[MAX_FAI_SECTOR_PTS+1];
DistanceBearing(lat1, lon1, lat2, lon2, &fDist_c, &fAngle);

if(fabs(fDist_c) < 1000.0)  /* distance too short for a FAI sector */
	return -1;


double fDistMax = fDist_c/FAI_NORMAL_PERCENTAGE;
double fDistMin = fDist_c/(1.0-2.0*FAI28_45Threshold);
double fDelta_Dist = 2.0* fDist_c*fFAI_Percentage / (double)(FAI_SECTOR_STEPS-1);
double fA, fB;
double fMinLeg, fMaxLeg,fDiff=0;
double dir = -1.0;
BOOL bBigFAISector = false;

if(fDistMax > FAI28_45Threshold)
{
  bBigFAISector = true;
  fDistMax = fDist_c/FAI_BIG_PERCENTAGE;
}

if(fDistMin < FAI28_45Threshold)
{
  fDistMin = fDist_c/(1.0-2.0*FAI_NORMAL_PERCENTAGE);
}


if (iOpposite >0)
{
  dir = 1.0;
}

//#define  HELP_LINES
#ifdef HELP_LINES
  int x2,y2, style;
  FindLatitudeLongitude(lat1, lon1, AngleLimit360 (fAngle), fDist_c/2, &lat_d, &lon_d);
  x1 = (lon_d - lon_c)*fastcosine(lat_d);
  y1 = (lat_d - lat_c);
  FindLatitudeLongitude(lat_d, lon_d, AngleLimit360 (fAngle-90.0), fDist_c, &lat_d, &lon_d);
  x2 = (lon_d - lon_c)*fastcosine(lat_d);
  y2 = (lat_d - lat_c);
  Surface.DrawLine(rc, x1, y1, x2, y2, style);
#endif

  /********************************************************************
   * right below threshold 1
   ********************************************************************/
  fA = 	fDistMin;
  if(fDistMax > FAI28_45Threshold)
    fB = FAI28_45Threshold;
  else
	fB = fDistMax ;


  if(fA<fB)
  {
	fDelta_Dist =(fB-fA)/ (double)(FAI_SECTOR_STEPS-1);
	fDistTri = fA;
    for(i =0 ;i < FAI_SECTOR_STEPS; i++)
    {
	  fDist_a = FAI_NORMAL_PERCENTAGE * fDistTri;
	  fDist_b = fDistTri - fDist_a - fDist_c;

	  LKASSERT(fDist_c*fDist_b!=0);
	  cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	  alpha = acos(cos_alpha)*180/PI * dir;
	  FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);

	  MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
	  LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	  apSectorPolygon[iPolyPtr++] = Pt1;


      fDistTri += fDelta_Dist;
    }
  }

  /********************************************************************
   * right  threshold extender 2
   ********************************************************************/
if(fDistMin < FAI28_45Threshold)
  if(bBigFAISector && (fDistMin < FAI28_45Threshold))
  {
	fMaxLeg = FAI28_45Threshold*FAI_BIG_MAX_PERCENTAGE;
	fMinLeg = FAI28_45Threshold*FAI_BIG_PERCENTAGE;
	fA = FAI28_45Threshold*FAI_NORMAL_PERCENTAGE;
	fB = FAI28_45Threshold-fMaxLeg-fDist_c;

	if(fB < fMinLeg)
	  fB = fMinLeg;

	fDist_a = fA;
	fDelta_Dist =  (fB-fA) / (double)(FAI_SECTOR_STEPS-1);
    for(i =0 ;i < FAI_SECTOR_STEPS; i++)
    {
	  fDist_b = FAI28_45Threshold - fDist_a - fDist_c;
  	  LKASSERT(fDist_c*fDist_b!=0);
	  cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	  alpha = acos(cos_alpha)*180/PI * dir;
	  FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);
	  MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
	  LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	  apSectorPolygon[iPolyPtr++] = Pt1;

	  fDist_a += fDelta_Dist;
    }
  }
  /********************************************************************
   * right  above threshold  3
   ********************************************************************/
  if(bBigFAISector)
  {
    fA = 	FAI28_45Threshold;
    if(fDistMin > fA)
	  fA= fDistMin;
    fB =fDist_c/(1- FAI_BIG_PERCENTAGE-FAI_BIG_MAX_PERCENTAGE);

    if(fA < fB)
    {
      fDelta_Dist =(fB-fA)/ (double)(FAI_SECTOR_STEPS-1);
      fDistTri = fA;
      for(i =0 ;i < FAI_SECTOR_STEPS; i++)
      {
  	    fMaxLeg = fDistTri*FAI_BIG_MAX_PERCENTAGE;
	    fMinLeg = fDistTri*FAI_BIG_PERCENTAGE;
	    fDist_a = fDistTri-fMinLeg-fDist_c;;
	    fDist_b = fMinLeg;

	    if(fDist_a > fMaxLeg)
	    {
	      fDiff =  fDist_a - fMaxLeg;
	      fDist_b+=fDiff;
	      fDist_a-=fDiff;
	    }

	    LKASSERT(fDist_c*fDist_b!=0);
	    cos_alpha = ( fDist_a*fDist_a + fDist_c*fDist_c - fDist_b*fDist_b )/(2.0*fDist_c*fDist_a);
	    alpha = acos(cos_alpha)*180/PI * dir;
	    FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_a, &lat_d, &lon_d);
		MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
		LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	    apSectorPolygon[iPolyPtr++] = Pt1;


	    fDistTri += fDelta_Dist;
      }
    }
  }
/********************************************************************
 * TOP limited round 4
 ********************************************************************/
  if(fDistMax <= FAI28_45Threshold)
	fDist_b = fDistMax*(1.0-2*FAI_NORMAL_PERCENTAGE);
  else
	fDist_b = fDistMax*FAI_BIG_MAX_PERCENTAGE;

  fDist_a = fDistMax-fDist_b-fDist_c;
  fDelta_Dist =  (fDist_a-fDist_b) / (double)(FAI_SECTOR_STEPS-1);
  for(i =0 ;i < FAI_SECTOR_STEPS; i++)
  {
	LKASSERT(fDist_c*fDist_b!=0);
	cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	alpha = acos(cos_alpha)*180/PI * dir;
	FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);

	MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
	LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
    apSectorPolygon[iPolyPtr++] = Pt1;


    fDist_a -= fDelta_Dist;
    fDist_b += fDelta_Dist;
  }

/********************************************************************
 * calc left leg
 ********************************************************************/

/********************************************************************
 * LEFT above threshold 5
 ********************************************************************/
  if(bBigFAISector)
  {
    fB = FAI28_45Threshold;
    if( fB < fDistMin)
	  fB = fDistMin;

    fA =fDist_c/(1- FAI_BIG_PERCENTAGE-FAI_BIG_MAX_PERCENTAGE);

    if(fA >= fB)
    {
      fDelta_Dist =(fA-fB)/ (double)(FAI_SECTOR_STEPS-1);
      fDistTri = fA;
      for(i =0 ;i < FAI_SECTOR_STEPS; i++)
      {
	    fMaxLeg = fDistTri*FAI_BIG_MAX_PERCENTAGE;
	    fMinLeg = fDistTri*FAI_BIG_PERCENTAGE;
	    fDist_a = fDistTri-fMinLeg-fDist_c;
	    fDist_b = fMinLeg;

	    if(fDist_a > fMaxLeg)
	    {
	      fDiff =  fDist_a - fMaxLeg;
	      fDist_b+=fDiff;
	      fDist_a-=fDiff;
  	    }

	    LKASSERT(fDist_c*fDist_b!=0);
	    cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	    alpha = acos(cos_alpha)*180/PI * dir;
	    FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);
		MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
		LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	    apSectorPolygon[iPolyPtr++] = Pt1;


	    fDistTri -= fDelta_Dist;
     }
    }
  }

  /********************************************************************
   * LEFT threshold extender 6
   ********************************************************************/
if(fDistMin < FAI28_45Threshold)
  if((fDistMin < FAI28_45Threshold) && (FAI28_45Threshold < fDistMax))
  {
	fMaxLeg = FAI28_45Threshold*FAI_BIG_MAX_PERCENTAGE;
	fMinLeg = FAI28_45Threshold*FAI_BIG_PERCENTAGE;
	fA = FAI28_45Threshold*FAI_NORMAL_PERCENTAGE;
	fB = FAI28_45Threshold-fMaxLeg-fDist_c;

	if(fB < fMinLeg)
	  fB = fMinLeg;

	fDist_b = fB;
	fDelta_Dist =  (fA-fB) / (double)(FAI_SECTOR_STEPS-1);

    for(i =0 ;i < FAI_SECTOR_STEPS; i++)
    {
	  fDist_a = FAI28_45Threshold - fDist_b - fDist_c;
	  LKASSERT(fDist_c*fDist_b!=0);
	  cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	  alpha = acos(cos_alpha)*180/PI * dir;
	  FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);
	  MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
	  LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	  apSectorPolygon[iPolyPtr++] = Pt1;

	  fDist_b += fDelta_Dist;
    }
  }


  /********************************************************************
   * LEFT below threshold 7
   ********************************************************************/
  fA = 	fDistMin;
  if(fDistMax > FAI28_45Threshold)
    fB = FAI28_45Threshold;
  else
	fB = fDistMax ;

  if(fA<fB)
  {
	fDelta_Dist =(fB-fA)/ (double)(FAI_SECTOR_STEPS-1);
	fDistTri = fB;
    for(i =0 ;i < FAI_SECTOR_STEPS; i++)
    {
	  fDist_b = FAI_NORMAL_PERCENTAGE * fDistTri;
	  fDist_a = fDistTri - fDist_b - fDist_c;

	  LKASSERT(fDist_c*fDist_b!=0);
	  cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	  alpha = acos(cos_alpha)*180/PI * dir;
	  FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);
	  MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
	  LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	  apSectorPolygon[iPolyPtr++] = Pt1;
      fDistTri -= fDelta_Dist;
    }
  }

  /********************************************************************
   * low open PEAK round 8
   ********************************************************************/
  if(fDistMin >FAI28_45Threshold)
  {
	fDist_b = fDistMin*FAI_BIG_PERCENTAGE;
	fDist_a = fDistMin-fDist_b-fDist_c;
	fDelta_Dist =  (fDist_b-fDist_a) / (double)(FAI_SECTOR_STEPS-1);

	for(i =0 ;i < FAI_SECTOR_STEPS; i++)
	{
		LKASSERT(fDist_c*fDist_b!=0);
		cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
		alpha = acos(cos_alpha)*180/PI * dir;
		FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);
		MapWindow::LatLon2Screen(lon_d, lat_d,  Pt1);
		LKASSERT(iPolyPtr < MAX_FAI_SECTOR_PTS);
	    apSectorPolygon[iPolyPtr++] = Pt1;

	    fDist_a += fDelta_Dist;
	    fDist_b -= fDelta_Dist;
	}
  }

  /********************************************************************
   * draw polygon
   ********************************************************************/
  LKPen   hpSectorPen(PEN_SOLID, IBLSCALE(2),  fillcolor );

  LKPen hpOldPen = Surface.SelectObject(hpSectorPen);
  LKBrush hpOldBrush = Surface.SelectObject(LKBrush_Hollow);

  Surface.Polygon(apSectorPolygon,iPolyPtr,rc);

  Surface.SelectObject(hpOldPen);
  Surface.SelectObject(hpOldBrush);
  hpSectorPen.Release();

  /********************************************************************
   * calc round leg grid
   ********************************************************************/
  hpSectorPen.Create(PEN_SOLID, (1), RGB_BLACK );
  Surface.SelectObject(hpSectorPen);
  Surface.SetTextColor(RGB_BLACK);
  double fTic= 1/DISTANCEMODIFY;
  if(fDist_c > 5/DISTANCEMODIFY)   fTic = 10/DISTANCEMODIFY;
  if(fDist_c > 50/DISTANCEMODIFY)  fTic = 25/DISTANCEMODIFY;
  if(fDist_c > 100/DISTANCEMODIFY) fTic = 50/DISTANCEMODIFY;
//  if(fDist_c > 200/DISTANCEMODIFY) fTic = 100/DISTANCEMODIFY;
  if(fDist_c > 500/DISTANCEMODIFY) fTic = 250/DISTANCEMODIFY;
  POINT line[2];
  BOOL bFirstUnit = true;
  LKASSERT(fTic!=0);
  fDistTri = ((int)(fDistMin/fTic)+1) * fTic ;
  LKFont hfOld = Surface.SelectObject(LK8PanelUnitFont);

int iCnt = 0;

  while(fDistTri <= fDistMax)
  {
    TCHAR text[180]; SIZE tsize;
	if(bFirstUnit)
	  _stprintf(text, TEXT("%i%s"), (int)(fDistTri*DISTANCEMODIFY), Units::GetUnitName(Units::GetUserDistanceUnit()));
	else
	  _stprintf(text, TEXT("%i"), (int)(fDistTri*DISTANCEMODIFY));
	bFirstUnit = false;
	Surface.GetTextSize(text, _tcslen(text), &tsize);

    int j=0;

	if(fDistTri < FAI28_45Threshold)
	{
	  fDist_b = fDistTri*FAI_NORMAL_PERCENTAGE;
	  fDist_a = fDistTri-fDist_b-fDist_c;
	  fDelta_Dist =  (fDist_a-fDist_b) / (double)(FAI_SECTOR_STEPS-1);
	}
	else
	{
      fMaxLeg = fDistTri*FAI_BIG_MAX_PERCENTAGE;
      fMinLeg = fDistTri*FAI_BIG_PERCENTAGE;
	  fA = fMaxLeg;
	  fB = fDistTri-fA-fDist_c;
	  fDist_a = fA;
	  fDist_b = fB;
	  if(fB < fMinLeg)
	  {
		  fDiff = fMinLeg-fB;
		  fB+=2*fDiff;
		  fDist_b += fDiff;
		  fDist_a -= fDiff;
	  }
	  if(fB > fMaxLeg)
	  {
		  fDiff =  fB - fMaxLeg;
		  fB+=2*fDiff;
		  fDist_b-=fDiff;
		  fDist_a+=fDiff;
	  }
	  fFAI_Percentage =  FAI_BIG_PERCENTAGE;
	  fDelta_Dist =  (fA-fB) / (double)(FAI_SECTOR_STEPS-1);
	}


    for(i =0 ;i < FAI_SECTOR_STEPS; i++)
    {
	  LKASSERT(fDist_c*fDist_b!=0);
	  cos_alpha = ( fDist_b*fDist_b + fDist_c*fDist_c - fDist_a*fDist_a )/(2.0*fDist_c*fDist_b);
	  alpha = acos(cos_alpha)*180/PI * dir;
	  FindLatitudeLongitude(lat1, lon1, AngleLimit360( fAngle + alpha ) , fDist_b, &lat_d, &lon_d);
	  MapWindow::LatLon2Screen(lon_d, lat_d,  line[0]);

      if(j> 0)
      {
  		ForcedClipping=true;
  		Surface.DrawLine(PEN_DASH, NIBLSCALE(1), line[0] , line[1] , RGB_BLACK, rc);
  		ForcedClipping=false;
      }


      if(j==0)
      {
    	Surface.DrawText(line[0].x, line[0].y, text, _tcslen(text));
    	j=1;

      }

//      TCHAR text[180]; SIZE tsize;
      if(iCnt==0)
        _stprintf(text, TEXT("%i%s"), (int)(fDistTri*DISTANCEMODIFY), Units::GetUnitName(Units::GetUserDistanceUnit()));
      else
        _stprintf(text, TEXT("%i"), (int)(fDistTri*DISTANCEMODIFY));
      Surface.GetTextSize(text, _tcslen(text), &tsize);
      if(i == 0)
        Surface.DrawText(line[0].x, line[0].y, text, _tcslen(text));

      if(iCnt > 1)
  	    if(i == FAI_SECTOR_STEPS-1)
  	      Surface.DrawText(line[0].x, line[0].y, text, _tcslen(text));

      if(iCnt > 2)
  	    if((i== (FAI_SECTOR_STEPS/2)))
  	      Surface.DrawText(line[0].x, line[0].y, text, _tcslen(text));

      line[1] =  line[0];



	  fDist_a -= fDelta_Dist;
	  fDist_b += fDelta_Dist;
    }
    fDistTri+=fTic;iCnt++;
 //   if((iCnt %2) ==0)
  //    DrawText(hdc, line[0].x, line[0].y, ETO_OPAQUE, NULL, text, _tcslen(text), NULL);
  }

Surface.SelectObject(hfOld);
Surface.SelectObject(hpOldPen);

return 0;
}
Example #7
0
void MapWindow::DrawWindAtAircraft2(LKSurface& Surface, const POINT& Orig, const RECT& rc) {
  int i;
  POINT Start;
  TCHAR sTmp[12];
  static SIZE tsize = {0,0};
  
  if (DerivedDrawInfo.WindSpeed<1) {
    return; // JMW don't bother drawing it if not significant
  }
  
  if (tsize.cx == 0){

    const auto oldFont = Surface.SelectObject(MapWindowBoldFont);
    Surface.GetTextSize(TEXT("99"), 2, &tsize);
    Surface.SelectObject(oldFont);
    tsize.cx = tsize.cx/2;
  }

  int wmag = iround(4.0*DerivedDrawInfo.WindSpeed);
  
  Start.y = Orig.y;
  Start.x = Orig.x;

  int kx = tsize.cx/ScreenScale/2;

  POINT Arrow[7] = { {0,-20}, {-6,-26}, {0,-20}, 
                     {6,-26}, {0,-20}, 
                     {8+kx, -24}, 
                     {-8-kx, -24}};

  for (i=1;i<4;i++)
    Arrow[i].y -= wmag;

  PolygonRotateShift(Arrow, 7, Start.x, Start.y, 
		     DerivedDrawInfo.WindBearing-DisplayAngle);

  //
  // Draw Wind Arrow
  //
  POINT Tail[2] = {{0,-20}, {0,-26-min(20,wmag)*3}};
  double angle = AngleLimit360(DerivedDrawInfo.WindBearing-DisplayAngle);
  for(i=0; i<2; i++) {
    if (ScreenScale>1) {
      Tail[i].x *= ScreenScale;
      Tail[i].y *= ScreenScale;
    }
    protateshift(Tail[i], angle, Start.x, Start.y);
  }
  // optionally draw dashed line for wind arrow
  Surface.DrawLine(PEN_DASH, 1, Tail[0], Tail[1], LKColor(0,0,0), rc);

  // Paint wind value only while circling
  if ( (mode.Is(Mode::MODE_CIRCLING)) ) {

    _stprintf(sTmp, _T("%d"), iround(DerivedDrawInfo.WindSpeed * SPEEDMODIFY));

    TextInBoxMode_t TextInBoxMode = {0};
    TextInBoxMode.AlligneCenter = true;   // { 16 | 32 }; // JMW test {2 | 16};
    TextInBoxMode.WhiteBorder = true;
    if (Arrow[5].y>=Arrow[6].y) {
      TextInBox(Surface, &rc, sTmp, Arrow[5].x-kx, Arrow[5].y, 0, &TextInBoxMode);
    } else {
      TextInBox(Surface, &rc, sTmp, Arrow[6].x-kx, Arrow[6].y, 0, &TextInBoxMode);
    }
  }
  const auto hpOld = Surface.SelectObject(LKPen_Black_N2);
  const auto hbOld = Surface.SelectObject(LKBrush_Grey);
  Surface.Polygon(Arrow,5);

  Surface.SelectObject(hbOld);
  Surface.SelectObject(hpOld);
}