Parcourir la source

Fixes compile error on Linux introduced by previous commit.
Fixes crash in Font when minimizing windows, introduced by previous commit.

Fixed #1153

sgrenier il y a 12 ans
Parent
commit
e7cd166e3f
3 fichiers modifiés avec 27 ajouts et 14 suppressions
  1. 1 0
      gameplay/src/Base.h
  2. 7 4
      gameplay/src/Font.cpp
  3. 19 10
      samples/particles/src/ParticlesGame.cpp

+ 1 - 0
gameplay/src/Base.h

@@ -45,6 +45,7 @@ using std::size_t;
 using std::min;
 using std::max;
 using std::modf;
+using std::atoi;
 
 // Common
 #ifndef NULL

+ 7 - 4
gameplay/src/Font.cpp

@@ -157,10 +157,13 @@ void Font::start()
 
     // Update the projection matrix for our batch to match the current viewport
     const Rectangle& vp = Game::getInstance()->getViewport();
-    Game* game = Game::getInstance();
-    Matrix projectionMatrix;
-    Matrix::createOrthographicOffCenter(vp.x, vp.width, vp.height, vp.y, 0, 1, &projectionMatrix);
-    _batch->setProjectionMatrix(projectionMatrix);
+    if (!vp.isEmpty())
+    {
+        Game* game = Game::getInstance();
+        Matrix projectionMatrix;
+        Matrix::createOrthographicOffCenter(vp.x, vp.width, vp.height, vp.y, 0, 1, &projectionMatrix);
+        _batch->setProjectionMatrix(projectionMatrix);
+    }
 
     _batch->start();
 }

+ 19 - 10
samples/particles/src/ParticlesGame.cpp

@@ -262,6 +262,20 @@ std::string toString(bool b)
     return b ? "true" : "false";
 }
 
+std::string toString(int i)
+{
+    char buf[1024];
+    sprintf(buf, "%d", i);
+    return buf;
+}
+
+std::string toString(unsigned int i)
+{
+    char buf[1024];
+    sprintf(buf, "%d", i);
+    return buf;
+}
+
 void ParticlesGame::saveFile()
 {
     std::string filename;
@@ -705,15 +719,11 @@ void ParticlesGame::updateFrames()
     {
         if (w > _particleEmitter->getTexture()->getWidth())
         {
-            w = texture->getWidth();
-            char buf[1024];
-            wBox->setText(itoa(w, buf, 10));
+            wBox->setText(toString(texture->getWidth()).c_str());
         }
         if (h > texture->getHeight())
         {
-            h = texture->getHeight();
-            char buf[1024];
-            hBox->setText(itoa(h, buf, 10));
+            hBox->setText(toString(texture->getHeight()).c_str());
         }
 
         _particleEmitter->setSpriteFrameCoords(fc, w, h);
@@ -1086,10 +1096,9 @@ void ParticlesGame::updateImageControl()
     ((ImageControl*)_form->getControl("sprite"))->setSize(w, h);
     _form->getControl("image")->setHeight(h + _form->getControl("imageSettings")->getHeight() + 50);
 
-    char buf[1024];
-    ((TextBox*)_form->getControl("frameCount"))->setText(itoa((int)_particleEmitter->getSpriteFrameCount(), buf, 10));
-    ((TextBox*)_form->getControl("frameWidth"))->setText(itoa((int)_particleEmitter->getSpriteWidth(), buf, 10));
-    ((TextBox*)_form->getControl("frameHeight"))->setText(itoa((int)_particleEmitter->getSpriteHeight(), buf, 10));
+    ((TextBox*)_form->getControl("frameCount"))->setText(toString(_particleEmitter->getSpriteFrameCount()).c_str());
+    ((TextBox*)_form->getControl("frameWidth"))->setText(toString(_particleEmitter->getSpriteWidth()).c_str());
+    ((TextBox*)_form->getControl("frameHeight"))->setText(toString(_particleEmitter->getSpriteHeight()).c_str());
 
     switch (_particleEmitter->getTextureBlending())
     {