1 #include <cstdlib>
2 #include <cstring>
3 #include <fstream>
4 #include <sstream>
5 #include <string>
6 using namespace std;
7
8 #include <unistd.h>
9
10 #include "keywords.h"
11 #include "Options.h"
12 #include "PlanetProperties.h"
13 #include "xpUtil.h"
14
15 #include "DisplayMSWin.h"
16
17 #include "libimage/Image.h"
18
19 #define WIN32_LEAN_AND_MEAN
20 #include <windows.h>
21
DisplayMSWin(const int tr)22 DisplayMSWin::DisplayMSWin(const int tr) : DisplayBase(tr)
23 {
24 fullWidth_ = GetSystemMetrics(SM_CXVIRTUALSCREEN);
25 fullHeight_ = GetSystemMetrics(SM_CYVIRTUALSCREEN);
26
27 Options *options = Options::getInstance();
28 switch (options->DisplayMode())
29 {
30 case WINDOW:
31 xpWarn("-window option not supported for MS Windows.\n",
32 __FILE__, __LINE__);
33 // fall through
34 case ROOT:
35 if (options->GeometrySelected())
36 {
37 width_ = options->getWidth();
38 height_ = options->getHeight();
39 }
40 else
41 {
42 width_ = fullWidth_;
43 height_ = fullHeight_;
44 }
45 break;
46 }
47
48 if (!options->CenterSelected())
49 {
50 if (width_ % 2 == 0)
51 options->CenterX(width_/2 - 0.5);
52 else
53 options->CenterX(width_/2);
54
55 if (height_ % 2 == 0)
56 options->CenterY(height_/2 - 0.5);
57 else
58 options->CenterY(height_/2);
59 }
60
61 allocateRGBData();
62 }
63
~DisplayMSWin()64 DisplayMSWin::~DisplayMSWin()
65 {
66 }
67
68 void
renderImage(PlanetProperties * planetProperties[])69 DisplayMSWin::renderImage(PlanetProperties *planetProperties[])
70 {
71 drawLabel(planetProperties);
72
73 string outputFilename(TmpDir());
74 outputFilename += "\\XPlanet.png";
75
76 Options *options = Options::getInstance();
77 if (options->GeometrySelected()) PlaceImageOnRoot();
78
79 Image i(fullWidth_, fullHeight_, rgb_data, alpha);
80 if (!i.Write(outputFilename.c_str()))
81 {
82 ostringstream errStr;
83 errStr << "Can't create image file " << outputFilename << "\n";
84 xpExit(errStr.str(), __FILE__, __LINE__);
85 }
86
87 if (options->Verbosity() > 1)
88 {
89 ostringstream msg;
90 msg << "Created image file " << outputFilename << "\n";
91 xpMsg(msg.str(), __FILE__, __LINE__);
92 }
93
94 // Tell Windows to update the desktop wallpaper
95 SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,
96 (char *) outputFilename.c_str(),
97 SPIF_UPDATEINIFILE);
98 }
99
100 string
TmpDir()101 DisplayMSWin::TmpDir()
102 {
103 Options *options = Options::getInstance();
104
105 string returnstring = options->TmpDir();
106 if (returnstring.empty())
107 {
108 char tmpdir[MAX_PATH];
109 GetTempPath(MAX_PATH, tmpdir);
110 returnstring.assign(tmpdir);
111 }
112 return(returnstring);
113 }
114