- added support for rounded rectangles for use in the menu
authorIngo Ruhnke <grumbel@gmx.de>
Mon, 25 Feb 2008 00:35:35 +0000 (00:35 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Mon, 25 Feb 2008 00:35:35 +0000 (00:35 +0000)
SVN-Revision: 5340

src/gui/menu.cpp
src/video/drawing_context.cpp
src/video/drawing_context.hpp
src/video/drawing_request.hpp
src/video/gl_renderer.cpp

index 8983515..9a16354 100644 (file)
@@ -705,13 +705,14 @@ Menu::draw(DrawingContext& context)
   }
 
   float menu_height = get_height();
-  float menu_width = get_width();
+  float menu_width  = get_width();
 
   /* Draw a transparent background */
-  context.draw_filled_rect(
-    Vector(pos_x - menu_width/2, pos_y - 24*items.size()/2 - 10),
-    Vector(menu_width,menu_height + 20),
-    Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-10);
+  context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2, pos_y - 24*items.size()/2 - 10),
+                                Vector(pos_x + menu_width/2, pos_y - 24*items.size()/2 + 10 + menu_height)),
+                           Color(0.6f, 0.7f, 0.8f, 0.5f), 
+                           16.0f,
+                           LAYER_GUI-10);
 
   for(unsigned int i = 0; i < items.size(); ++i)
     {
index 7ca3e26..02712fd 100644 (file)
@@ -219,6 +219,7 @@ DrawingContext::draw_filled_rect(const Vector& topleft, const Vector& size,
   fillrectrequest->size = size;
   fillrectrequest->color = color;
   fillrectrequest->color.alpha = color.alpha * transform.alpha;
+  fillrectrequest->radius = 0.0f;
   request->request_data = fillrectrequest;
 
   requests->push_back(request);
@@ -228,12 +229,18 @@ void
 DrawingContext::draw_filled_rect(const Rect& rect, const Color& color,
                                  int layer)
 {
+  draw_filled_rect(rect, color, 0.0f, layer);
+}
+
+void
+DrawingContext::draw_filled_rect(const Rect& rect, const Color& color, float radius, int layer)
+{
   DrawingRequest* request = new(obst) DrawingRequest();
 
   request->target = target;
-  request->type = FILLRECT;
-  request->pos = transform.apply(rect.p1);
-  request->layer = layer;
+  request->type   = FILLRECT;
+  request->pos    = transform.apply(rect.p1);
+  request->layer  = layer;
 
   request->drawing_effect = transform.drawing_effect;
   request->alpha = transform.alpha;
@@ -242,9 +249,10 @@ DrawingContext::draw_filled_rect(const Rect& rect, const Color& color,
   fillrectrequest->size = Vector(rect.get_width(), rect.get_height());
   fillrectrequest->color = color;
   fillrectrequest->color.alpha = color.alpha * transform.alpha;
+  fillrectrequest->radius = radius;
   request->request_data = fillrectrequest;
 
-  requests->push_back(request);
+  requests->push_back(request); 
 }
 
 void
index c8f9012..73713f7 100644 (file)
@@ -78,6 +78,7 @@ public:
   void draw_filled_rect(const Vector& topleft, const Vector& size,
                         const Color& color, int layer);
   void draw_filled_rect(const Rect& rect, const Color& color, int layer);
+  void draw_filled_rect(const Rect& rect, const Color& color, float radius, int layer);
 
   /// Processes all pending drawing requests and flushes the list.
   void do_drawing();
index 24e0c02..5eeb711 100644 (file)
@@ -94,8 +94,9 @@ struct GradientRequest
 
 struct FillRectRequest
 {
-  Color color;
+  Color  color;
   Vector size;
+  float  radius;
 };
 
 struct DrawingRequest
index 3eee8f1..54e9463 100644 (file)
@@ -241,23 +241,68 @@ namespace GL
     const FillRectRequest* fillrectrequest
       = (FillRectRequest*) request.request_data;
 
-    float x = request.pos.x;
-    float y = request.pos.y;
-    float w = fillrectrequest->size.x;
-    float h = fillrectrequest->size.y;
-
-    glDisable(GL_TEXTURE_2D);
-    glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
-              fillrectrequest->color.blue, fillrectrequest->color.alpha);
-
-    glBegin(GL_QUADS);
-    glVertex2f(x, y);
-    glVertex2f(x+w, y);
-    glVertex2f(x+w, y+h);
-    glVertex2f(x, y+h);
-    glEnd();
-    glEnable(GL_TEXTURE_2D);
-    glColor4f(1, 1, 1, 1);
+    if (fillrectrequest->radius != 0.0f)
+      {
+        // draw round rect
+        // Keep radius in the limits, so that we get a circle instead of
+        // just graphic junk
+        float radius = std::min(fillrectrequest->radius,
+                                std::min(fillrectrequest->size.x/2,
+                                         fillrectrequest->size.y/2));
+
+        // inner rectangle
+        Rect irect(request.pos.x    + radius,
+                   request.pos.y    + radius,
+                   request.pos.x + fillrectrequest->size.x - radius,
+                   request.pos.y + fillrectrequest->size.y - radius);
+
+        glDisable(GL_TEXTURE_2D);
+        glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
+                  fillrectrequest->color.blue, fillrectrequest->color.alpha);
+
+
+        int n = 8;
+        glBegin(GL_QUAD_STRIP);
+        for(int i = 0; i <= n; ++i)
+          {
+            float x = sinf(i * (M_PI/2) / n) * radius;
+            float y = cosf(i * (M_PI/2) / n) * radius;
+
+            glVertex2f(irect.get_left()  - x, irect.get_top() - y);
+            glVertex2f(irect.get_right() + x, irect.get_top() - y);
+          }
+        for(int i = 0; i <= n; ++i)
+          {
+            float x = cosf(i * (M_PI/2) / n) * radius;
+            float y = sinf(i * (M_PI/2) / n) * radius;
+
+            glVertex2f(irect.get_left()  - x, irect.get_bottom() + y);
+            glVertex2f(irect.get_right() + x, irect.get_bottom() + y);
+          }
+        glEnd();
+        glEnable(GL_TEXTURE_2D);
+        glColor4f(1, 1, 1, 1);
+      }
+    else
+      {
+        float x = request.pos.x;
+        float y = request.pos.y;
+        float w = fillrectrequest->size.x;
+        float h = fillrectrequest->size.y;
+
+        glDisable(GL_TEXTURE_2D);
+        glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
+                  fillrectrequest->color.blue, fillrectrequest->color.alpha);
+
+        glBegin(GL_QUADS);
+        glVertex2f(x, y);
+        glVertex2f(x+w, y);
+        glVertex2f(x+w, y+h);
+        glVertex2f(x, y+h);
+        glEnd();
+        glEnable(GL_TEXTURE_2D);
+        glColor4f(1, 1, 1, 1);
+      }
   }
 
   void