00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLEXT/GLViewPort.h>
00022 #include <GLEXT/GLState.h>
00023 #include <image/ImageFactory.h>
00024 #include <graph/Main2DCamera.h>
00025 #include <graph/OptionsDisplay.h>
00026 #include <dialogs/BackdropDialog.h>
00027 #include <common/Defines.h>
00028
00029 BackdropDialog *BackdropDialog::instance_ = 0;
00030
00031 BackdropDialog *BackdropDialog::instance()
00032 {
00033 if (!instance_)
00034 {
00035 instance_ = new BackdropDialog;
00036 }
00037 return instance_;
00038 }
00039
00040 BackdropDialog::BackdropDialog() :
00041 GLWWindow("", 0.0f, 0.0f, 0.0f, 0.0f, 0,
00042 "The backdrop dialog")
00043 {
00044 windowLevel_ = 5000000;
00045 }
00046
00047 BackdropDialog::~BackdropDialog()
00048 {
00049 }
00050
00051 void BackdropDialog::draw()
00052 {
00053 drawBackground();
00054 drawLogo();
00055 drawFooter();
00056 }
00057
00058 void BackdropDialog::drawBackground()
00059 {
00060 static bool createdTexture = false;
00061 if (!createdTexture)
00062 {
00063 createdTexture = true;
00064 ImageHandle originalBackMap = ImageFactory::loadImageHandle(
00065 S3D::getDataFile("data/windows/backdrop.jpg"));
00066 int w = originalBackMap.getWidth();
00067 int h = originalBackMap.getHeight();
00068 while (w > GLViewPort::getActualWidth() || h > GLViewPort::getActualHeight())
00069 {
00070 w /= 2;
00071 h /= 2;
00072 }
00073
00074 ImageHandle backMap = originalBackMap.createResize(w, h);
00075 backTex_.create(backMap, false);
00076 }
00077
00078 GLState currentState(GLState::DEPTH_OFF | GLState::TEXTURE_ON);
00079
00080
00081 float wWidth = (float) GLViewPort::getWidth();
00082 float wHeight = (float) GLViewPort::getHeight();
00083
00084
00085 backTex_.draw(true);
00086 glColor3f(1.0f, 1.0f, 1.0f);
00087 glBegin(GL_QUADS);
00088 glTexCoord2f(0.0f, 0.0f);
00089 glVertex2f(0.0f, 0.0f);
00090 glTexCoord2f(1.0f, 0.0f);
00091 glVertex2f(wWidth, 0.0f);
00092 glTexCoord2f(1.0f, 1.0f);
00093 glVertex2f(wWidth, wHeight);
00094 glTexCoord2f(0.0f, 1.0f);
00095 glVertex2f(0.0f, wHeight);
00096 glEnd();
00097 }
00098
00099 void BackdropDialog::drawLogo()
00100 {
00101 if (S3D::getDataFileMod() != lastMod_)
00102 {
00103 lastMod_ = S3D::getDataFileMod();
00104
00105 ImageHandle logoMap = ImageFactory::loadImageHandle(
00106 S3D::getDataFile("data/windows/scorched.jpg"),
00107 S3D::getDataFile("data/windows/scorcheda.jpg"),
00108 false);
00109 logoTex_.create(logoMap, false);
00110 }
00111
00112 GLState currentState(GLState::DEPTH_OFF | GLState::BLEND_ON | GLState::TEXTURE_ON);
00113
00114
00115 float wWidth = (float) GLViewPort::getWidth();
00116 float wHeight = (float) GLViewPort::getHeight();
00117
00118
00119 const float logoWidth = 480.0f;
00120 const float logoHeight = 90.0f;
00121 logoTex_.draw(true);
00122 glColor3f(1.0f, 1.0f, 1.0f);
00123 glPushMatrix();
00124 glTranslatef(
00125 wWidth - logoWidth - 50.0f,
00126 wHeight - logoHeight - 50.0f,
00127 0.0f);
00128 glBegin(GL_QUADS);
00129 glTexCoord2f(0.0f, 0.0f);
00130 glVertex2f(0.0f, 0.0f);
00131 glTexCoord2f(1.0f, 0.0f);
00132 glVertex2f(logoWidth, 0.0f);
00133 glTexCoord2f(1.0f, 1.0f);
00134 glVertex2f(logoWidth, logoHeight);
00135 glTexCoord2f(0.0f, 1.0f);
00136 glVertex2f(0.0f, logoHeight);
00137 glEnd();
00138 glPopMatrix();
00139 }
00140
00141 void BackdropDialog::drawFooter()
00142 {
00143 static bool createdTexture = false;
00144 if (!createdTexture)
00145 {
00146 createdTexture = true;
00147 ImageHandle logoMap = ImageFactory::loadAlphaImageHandle(
00148 S3D::getDataFile("data/windows/hiscore.png"));
00149 footerTex_.create(logoMap, false);
00150 }
00151
00152 GLState currentState(GLState::DEPTH_OFF | GLState::BLEND_ON | GLState::TEXTURE_ON);
00153
00154
00155 float wWidth = (float) GLViewPort::getWidth();
00156 float wHeight = (float) GLViewPort::getHeight();
00157
00158
00159 const float logoWidth = 200.0f;
00160 const float logoHeight = 90.0f;
00161 footerTex_.draw(true);
00162 glColor4f(1.0f, 1.0f, 1.0f, 0.6f);
00163 glPushMatrix();
00164 glTranslatef(
00165 wWidth - logoWidth - 10.0f,
00166 10.0f,
00167 0.0f);
00168 glBegin(GL_QUADS);
00169 glTexCoord2f(0.0f, 0.0f);
00170 glVertex2f(0.0f, 0.0f);
00171 glTexCoord2f(1.0f, 0.0f);
00172 glVertex2f(logoWidth, 0.0f);
00173 glTexCoord2f(1.0f, 1.0f);
00174 glVertex2f(logoWidth, logoHeight);
00175 glTexCoord2f(0.0f, 1.0f);
00176 glVertex2f(0.0f, logoHeight);
00177 glEnd();
00178 glPopMatrix();
00179 }
00180
00181 void BackdropDialog::capture()
00182 {
00183 if (OptionsDisplay::instance()->getNoProgressBackdrop()) return;
00184 if (!backTex_.getTexName() == 0) return;
00185
00186 glRasterPos2i(0, 0);
00187
00188 glPixelStorei(GL_PACK_ALIGNMENT, 4);
00189 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
00190 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
00191 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
00192
00193 int imageSize = GLViewPort::getActualWidth() * GLViewPort::getActualHeight() * 3;
00194 unsigned char *screenpixels = new unsigned char[imageSize];
00195 glReadPixels(0, 0, GLViewPort::getActualWidth(), GLViewPort::getActualHeight(),
00196 GL_RGB, GL_UNSIGNED_BYTE, screenpixels);
00197
00198 ImageHandle handle = ImageFactory::createBlank(
00199 backTex_.getWidth(), backTex_.getHeight());
00200
00201 unsigned char *src = screenpixels;
00202 for (int y=0; y<GLViewPort::getActualHeight(); y++)
00203 {
00204 for (int x=0; x<GLViewPort::getActualWidth(); x++, src+=3)
00205 {
00206 int totalr = 0;
00207 int totalg = 0;
00208 int totalb = 0;
00209 if (x>=3 && x<GLViewPort::getActualWidth()-3 &&
00210 y>=3 && y<GLViewPort::getActualHeight()-3)
00211 {
00212 for (int a=-3; a<=3; a++)
00213 {
00214 for (int b=-3; b<=3; b++)
00215 {
00216 int srcx = a + x;
00217 int srcy = b + y;
00218 unsigned char *src2 = src + a * 3 + b * GLViewPort::getActualWidth() * 3;
00219 if (src2 >= screenpixels && src2 - screenpixels < imageSize)
00220 {
00221 totalr += src2[0];
00222 totalg += src2[1];
00223 totalb += src2[2];
00224 }
00225 }
00226 }
00227 totalr /= 49;
00228 totalg /= 49;
00229 totalb /= 49;
00230 }
00231 else
00232 {
00233 totalr = src[0];
00234 totalg = src[1];
00235 totalb = src[2];
00236 }
00237
00238 int destx = (x * backTex_.getWidth() / GLViewPort::getActualWidth()) % backTex_.getWidth();
00239 int desty = (y * backTex_.getHeight() / GLViewPort::getActualHeight()) % backTex_.getHeight();
00240 unsigned char *dest = &handle.getBits()[destx * 3 + desty * backTex_.getWidth() * 3];
00241
00242 dest[0] = totalr;
00243 dest[1] = totalg;
00244 dest[2] = totalb;
00245 }
00246 }
00247
00248 delete [] screenpixels;
00249
00250 backTex_.replace(handle, false);
00251 }