Commit MetaInfo

Revision51dfbe15040edcf98001a1d6f2402a0746f8a5c0 (tree)
Time2014-05-21 03:57:19
AuthorFace
CommiterFace

Log Message

JumpDriveMFD: using sketchpad instead of device context handle

Change Summary

Incremental Difference

diff -r 83f5e15c7bd3 -r 51dfbe15040e Orbitersdk/samples/JumpDriveMFD/JumpDriveMFD.cpp
--- a/Orbitersdk/samples/JumpDriveMFD/JumpDriveMFD.cpp Tue May 20 08:08:00 2014 +0200
+++ b/Orbitersdk/samples/JumpDriveMFD/JumpDriveMFD.cpp Tue May 20 20:57:19 2014 +0200
@@ -38,8 +38,7 @@
3838 std::map< VESSEL*, JumpDrive* > g_JumpDrives; // static hash table for drive instances
3939 std::map< VESSEL*, std::map< int, JumpDriveMFDData* > > g_JumpDriveMFDs; // static hash table for MFD instances
4040 Environment g_Environment; // static environment structure
41-HBRUSH g_Bar; // used for drawing
42-COLORREF g_MiddleGreen; // used for drawing
41+oapi::Brush *myBrush; // used for drawing
4342
4443 // Configurable settings
4544 double JUMPVEL = 5E4;
@@ -87,7 +86,7 @@
8786 value[0]=0;
8887 GetPrivateProfileString("Features", "FleetRange", 0, value, MAXCHARS, INIFILE);
8988 if (value[0]!=0) FLEETRANGE=atof(value);
90- g_Bar=0;
89+ myBrush=oapiCreateBrush(0x00008000);
9190 // Register the new MFD mode with Orbiter
9291 static char *name = "JumpDrive";
9392 MFDMODESPEC spec;
@@ -104,8 +103,8 @@
104103 {
105104 // Unregister the custom MFD mode when the module is unloaded
106105 oapiUnregisterMFDMode (g_MFDmode);
106+ oapiReleaseBrush(myBrush);
107107
108- if (g_Bar!=0) DeleteObject(g_Bar);
109108 if (fopen(INIFILE, "r")==0)
110109 {
111110 char value[MAXCHARS];
@@ -194,7 +193,7 @@
194193 // instances if available. If the drive or MFD instance is not available, it will be
195194 // created.
196195 JumpDriveMFD::JumpDriveMFD (DWORD w, DWORD h, VESSEL *vessel, UINT mfd)
197-: MFD (w, h, vessel)
196+: MFD2 (w, h, vessel)
198197 {
199198 char key[30];
200199 DWORD i;
@@ -276,7 +275,7 @@
276275
277276
278277 // Repaint the MFD - contains display and navcomp routines
279-void JumpDriveMFD::Update (HDC hDC)
278+bool JumpDriveMFD::Update (oapi::Sketchpad *skp)
280279 {
281280 // Label strings
282281 static char *label[12] = {"Drive class","Jump range","Capacity","Charge rate","Fuel source", "Fuel mass",
@@ -300,62 +299,54 @@
300299 char buffer[80];
301300 int l=0;
302301 PROPELLANT_HANDLE propellant;
302+
303+ this->skp=skp;
303304
304- //Creating the pen for drawing the progress bar
305- if (g_Bar==0)
306- {
307- LOGPEN pen;
308- SelectDefaultPen(hDC, 2);
309- GetObject(GetCurrentObject(hDC, OBJ_PEN), sizeof(LOGPEN), &pen);
310- g_MiddleGreen=pen.lopnColor;
311- g_Bar=CreateSolidBrush(g_MiddleGreen);
312- }
313-
314305 //Get information from drive instance
315306 int cells=Drive->GetFilledCells();
316307 double jump=Drive->GetJumpRange(cells);
317308
318309 //Descriptions (normal, light green)
319- SelectDefaultFont (hDC, 0);
310+ SetWriteStyle(0);
320311 //Jump drive class
321312 sprintf(buffer, g_JumpDriveName);
322313 l=strlen(buffer);
323- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[0]*heigth) >> 1, buffer, l);
314+ skp->Text((1+(37-l)/2)*width, (labelpos[0]*heigth) >> 1, buffer, l);
324315 //Jump drive range
325316 sprintf(buffer, "%5.2em(%5.3fAU)", jump, jump/AU);
326317 l=strlen(buffer);
327- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[1]*heigth) >> 1, buffer, l);
318+ skp->Text((1+(37-l)/2)*width, (labelpos[1]*heigth) >> 1, buffer, l);
328319 //Jump drive capacity
329320 sprintf(buffer, "%4.1fkg x %d", CAPACITY, CELLS);
330321 l=strlen(buffer);
331- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[2]*heigth) >> 1, buffer, l);
322+ skp->Text((1+(37-l)/2)*width, (labelpos[2]*heigth) >> 1, buffer, l);
332323 //Jump drive charge rate
333324 sprintf(buffer, "%4.1fkg/s(%4.1fs)", CAPACITY/RELOADTIME, RELOADTIME);
334325 l=strlen(buffer);
335- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[3]*heigth) >> 1, buffer, l);
326+ skp->Text((1+(37-l)/2)*width, (labelpos[3]*heigth) >> 1, buffer, l);
336327 //Navigation computer mode setting
337328 l=strlen(modeLabel[Data->mode]);
338- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[9]*heigth) >> 1, modeLabel[Data->mode], l);
329+ skp->Text((1+(37-l)/2)*width, (labelpos[9]*heigth) >> 1, modeLabel[Data->mode], l);
339330
340- //Settings (normal, white)
341- SetTextColor(hDC, RGB(255,255,255));
331+ //Settings (normal, white)
332+ SetWriteStyle(0,2);
342333 //Fuel source info
343334 l=Drive->GetFuelSource();
344335 propellant=vessel->GetPropellantHandleByIndex(l);
345336 if (propellant!=NULL) sprintf(buffer, "%d of %d", l+1, vessel->GetPropellantCount());
346337 else sprintf(buffer, "OFF");
347338 l=strlen(buffer);
348- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[4]*heigth) >> 1, buffer, l);
339+ skp->Text((1+(37-l)/2)*width, (labelpos[4]*heigth) >> 1, buffer, l);
349340 if (propellant!=NULL) sprintf(buffer, "%4.1fkg", vessel->GetPropellantMass(propellant));
350341 else sprintf(buffer, "n/a");
351342 l=strlen(buffer);
352- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[5]*heigth) >> 1, buffer, l);
343+ skp->Text((1+(37-l)/2)*width, (labelpos[5]*heigth) >> 1, buffer, l);
353344 //Target information
354345 if (Data->target>=oapiGetObjectCount()) Data->target=oapiGetObjectCount()-1;
355346 OBJHANDLE obj=oapiGetObjectByIndex(Data->target);
356347 oapiGetObjectName(obj, buffer, 80);
357348 l=strlen(buffer);
358- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[7]*heigth) >> 1, buffer, l);
349+ skp->Text((1+(37-l)/2)*width, (labelpos[7]*heigth) >> 1, buffer, l);
359350 //Navigation computer mode value
360351 VECTOR3 v1, v2, v3;
361352 double d1, d2;
@@ -482,45 +473,46 @@
482473 break;
483474 }
484475 l=strlen(buffer);
485- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[10]*heigth) >> 1, buffer, l);
476+ skp->Text((1+(37-l)/2)*width, (labelpos[10]*heigth) >> 1, buffer, l);
486477 //Distance parameter
487478 sprintf(buffer, "%7.6em", Data->distance);
488479 l=strlen(buffer);
489- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[8]*heigth) >> 1, buffer, l);
480+ skp->Text((1+(37-l)/2)*width, (labelpos[8]*heigth) >> 1, buffer, l);
490481 //Additional navigation parameter
491482 sprintf(buffer, "2nd jump with %d cells", Data->j2cells);
492483 l=strlen(buffer);
493- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[11]*heigth) >> 1, buffer, l);
484+ skp->Text((1+(37-l)/2)*width, (labelpos[11]*heigth) >> 1, buffer, l);
494485
495486 //Capacitor status (small font, light green)
496- SetTextColor(hDC, RGB(255,255,0));
487+ SetWriteStyle(1);
488+ skp->SetBrush(myBrush);
497489 int i,j,k,s,w;
498490 s=7*width;
499491 w=25*width;
500- SelectObject(hDC, g_Bar);
501492 j=Drive->GetFuelCells();
502493 if (Drive->Jumping())
503494 {
504495 l=(int)(Drive->GetFuel()*100);
505- Rectangle(hDC, s, (((labelpos[6]-2)*heigth) >> 1)+2,
496+ skp->Rectangle( s, (((labelpos[6]-2)*heigth) >> 1)+2,
506497 w*l/100+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
507498 if (l==0) sprintf(buffer, "00%%");
508499 else if (l==100) sprintf(buffer, "GO");
509500 else sprintf(buffer, "%d%%", l);
510501 l=strlen(buffer);
511- TextOut(hDC, (1+(37-l)/2)*width, (labelpos[6]*heigth) >> 1, buffer, l);
512- SelectObject(hDC, GetStockObject(NULL_BRUSH));
513- Rectangle(hDC, s, (((labelpos[6]-2)*heigth) >> 1)+2,
514- w+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
502+ SetWriteStyle(1,1);
503+ skp->Text((1+(37-l)/2)*width, (labelpos[6]*heigth) >> 1, buffer, l);
504+ skp->SetBrush(NULL);
505+ SetWriteStyle(1);
506+ skp->Rectangle( s, (((labelpos[6]-2)*heigth) >> 1)+2,
507+ w+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
515508 }
516509 else
517510 {
518- SelectDefaultFont (hDC, 1);
519511 for(i=0;i<cells;i++)
520- Rectangle(hDC, w*i/j+s, (((labelpos[6]-2)*heigth) >> 1)+2,
521- w*(i+1)/j+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
512+ skp->Rectangle( w*i/j+s, (((labelpos[6]-2)*heigth) >> 1)+2,
513+ w*(i+1)/j+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
522514 l=(int)(Drive->GetFuel()*100);
523- Rectangle(hDC, w*i/j+s, (((labelpos[6]-2)*heigth) >> 1)+2,
515+ skp->Rectangle( w*i/j+s, (((labelpos[6]-2)*heigth) >> 1)+2,
524516 w*i/j+w*l/100/j+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
525517 if (l==0) sprintf(buffer, "00%%");
526518 else if (l==100) sprintf(buffer, "GO");
@@ -528,16 +520,19 @@
528520 l=strlen(buffer);
529521 k=w*i/j+w/j/2+s-(l/2)*(width-2);
530522 if (k<s+2) k=s+2;
531- TextOut(hDC, k, (labelpos[6]*heigth) >> 1, buffer, l);
532- SelectObject(hDC, GetStockObject(NULL_BRUSH));
523+ SetWriteStyle(1,1);
524+ skp->Text(k, (labelpos[6]*heigth) >> 1, buffer, l);
525+ skp->SetBrush(NULL);
526+ SetWriteStyle(1);
533527 for(;i<j;i++)
534- Rectangle(hDC, w*i/j+s, (((labelpos[6]-2)*heigth) >> 1)+2,
528+ skp->Rectangle( w*i/j+s, (((labelpos[6]-2)*heigth) >> 1)+2,
535529 w*(i+1)/j+s+1, (((labelpos[6]+4)*heigth) >> 1)+2);
536530 }
537531 //MFD mode labels (small font, dark green)
538- SelectDefaultFont (hDC, 1);
539- SetTextColor(hDC, g_MiddleGreen);
540- for (l=0; l<12; l++) TextOut(hDC, width, (labelpos[l]*heigth) >> 1, label[l], strlen(label[l]));
532+ skp->SetTextColor(0x00008000);
533+ for (l=0; l<12; l++) skp->Text(width, (labelpos[l]*heigth) >> 1, label[l], strlen(label[l]));
534+
535+ return true;
541536 }
542537
543538 // MFD message parser - returns a new MFD mode instance
@@ -713,3 +708,10 @@
713708 return false;
714709 }
715710
711+void JumpDriveMFD::SetWriteStyle(int font, int color, int intensity, int style)
712+{
713+ static DWORD colors[4] = {0x0000FF00, 0x0000FFFF, 0x00FFFFFF, 0x000000FF};
714+ skp->SetFont(GetDefaultFont(font));
715+ skp->SetTextColor(colors[color]);
716+ skp->SetPen(GetDefaultPen(color, intensity, style));
717+}
\ No newline at end of file
diff -r 83f5e15c7bd3 -r 51dfbe15040e Orbitersdk/samples/JumpDriveMFD/JumpDriveMFD.h
--- a/Orbitersdk/samples/JumpDriveMFD/JumpDriveMFD.h Tue May 20 08:08:00 2014 +0200
+++ b/Orbitersdk/samples/JumpDriveMFD/JumpDriveMFD.h Tue May 20 20:57:19 2014 +0200
@@ -35,7 +35,7 @@
3535 };
3636
3737 //The JumpDrive MFD mode class.
38-class JumpDriveMFD: public MFD {
38+class JumpDriveMFD: public MFD2 {
3939 public:
4040 //Default implementations
4141 JumpDriveMFD (DWORD w, DWORD h, VESSEL *vessel, UINT mfd);
@@ -44,7 +44,7 @@
4444 int ButtonMenu (const MFDBUTTONMENU **menu) const;
4545 bool ConsumeKeyBuffered (DWORD key);
4646 bool ConsumeButton (int bt, int event);
47- void Update (HDC hDC);
47+ bool Update (oapi::Sketchpad *skp);
4848 static int MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam);
4949 //The drive instance the mode is linked to
5050 JumpDrive *Drive;
@@ -56,6 +56,8 @@
5656 //Width and height of the MFD for text positions
5757 int width;
5858 int heigth;
59+ oapi::Sketchpad *skp;
60+ void SetWriteStyle(int font=0, int color=0, int intensity=0, int style=1);
5961 };
6062
6163 #endif // !__JUMPDRIVEMFD_H
\ No newline at end of file
Show on old repository browser