Optimized gradient when top color is the same as the bottom one.
[supertux.git] / src / screen / drawing_context.cpp
index 6420291..13d260d 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#include <assert.h>
-#include "drawing_context.h"
-
-#include <iostream>
 #include <algorithm>
+#include <cassert>
+#include <iostream>
+
+#include "drawing_context.h"
 #include "texture.h"
 #include "globals.h"
 #include "font.h"
@@ -35,7 +35,7 @@ DrawingContext::~DrawingContext()
 
 void
 DrawingContext::draw_surface(const Surface* surface, const Vector& position,
-    int layer, uint32_t drawing_effect)
+    int layer, Uint32 drawing_effect)
 {
   assert(surface != 0);
   
@@ -52,7 +52,7 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position,
 
 void
 DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
-    const Vector& size, const Vector& dest, int layer, uint32_t drawing_effect)
+    const Vector& size, const Vector& dest, int layer, Uint32 drawing_effect)
 {
   assert(surface != 0);
 
@@ -181,15 +181,22 @@ DrawingContext::draw_gradient(DrawingRequest& request)
   else
   {
 #endif
-    float redstep = (float(bottom.red)-float(top.red)) / float(screen->h);
-    float greenstep = (float(bottom.green)-float(top.green)) / float(screen->h);
-    float bluestep = (float(bottom.blue) - float(top.blue)) / float(screen->h);
-
-    for(float y = 0; y < screen->h; y += 2)
-      fillrect(0, (int)y, screen->w, 2,
-          int(float(top.red) + redstep * y),
-          int(float(top.green) + greenstep * y),
-          int(float(top.blue) + bluestep * y), 255);
+    if(&top == &bottom)
+      {
+      fillrect(0, 0, screen->w, screen->h, top.red, top.green, top.blue);
+      }
+    else
+      {
+      float redstep = (float(bottom.red)-float(top.red)) / float(screen->h);
+      float greenstep = (float(bottom.green)-float(top.green)) / float(screen->h);
+      float bluestep = (float(bottom.blue) - float(top.blue)) / float(screen->h);
+
+      for(float y = 0; y < screen->h; y += 2)
+        fillrect(0, (int)y, screen->w, 2,
+            int(float(top.red) + redstep * y),
+            int(float(top.green) + greenstep * y),
+            int(float(top.blue) + bluestep * y), 255);
+      }
 #ifndef NOOPENGL
 
     }