}
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)
{
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);
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;
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
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();
struct FillRectRequest
{
- Color color;
+ Color color;
Vector size;
+ float radius;
};
struct DrawingRequest
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