/* -*- Objc -*- */ /* * $Id: DrawFuncs.m,v 1.1 2003/09/08 14:06:47 dam Exp $ * * Copyright (C) 2003 Free Software Foundation, Inc. * * This file is part of GNU Hégémonie. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * 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 #include #include "Common/Math.h" #include "DrawFuncs.h" #define NB_SLICES 10 static const color_t themeTopColor = {0.77f, 0.11f, 0.11f}; static const color_t themeBottomColor = {0.0f, 0.0f, 0.0f}; static const color_t themeInTopColor = {0.25f, 0.03f, 0.03f}; static const color_t themeInBottomColor = {0.54f, 0.07f, 0.07f}; void draw_partial_disk (const real_t radius, const real_t startAngle, const color_t startColor, const real_t sweepAngle, const color_t sweepColor) { NSCParameterAssert (radius > 0.0f); const real_t delta_angle = DEGTORAD(sweepAngle / NB_SLICES); real_t angle = angle = DEGTORAD(startAngle); glBegin (GL_QUAD_STRIP); int slice; for (slice = 0; slice <= NB_SLICES; slice++) { const real_t sin_angle = sinf (angle); const real_t t = sin_angle / 2.0f + 0.5f; const color_t color = InterpolateColor (startColor, sweepColor, t); glColor3f ((GLfloat)color.red, (GLfloat)color.green, (GLfloat)color.blue); glVertex2f ((GLfloat)sin_angle, (GLfloat)cosf (angle)); angle += delta_angle; } glEnd(); } void draw_gradient_rectangle (const real_t left, const real_t right, const real_t bottom, const real_t top, const color_t bottomColor, const color_t topColor) { NSCParameterAssert (left < right); NSCParameterAssert (bottom < top); glBegin (GL_POLYGON); glColor3f ((GLfloat)bottomColor.red, (GLfloat)bottomColor.green, (GLfloat)bottomColor.blue); glVertex2f ((GLfloat)left, (GLfloat)bottom); glVertex2f ((GLfloat)right, (GLfloat)bottom); glColor3f ((GLfloat)topColor.red, (GLfloat)topColor.green, (GLfloat)topColor.blue); glVertex2f ((GLfloat)right, (GLfloat)top); glVertex2f ((GLfloat)left, (GLfloat)top); glEnd(); } void draw_rounded_rectangle (const real_t left, const real_t right, const real_t bottom, const real_t top, const color_t bottomColor, const color_t topColor) { const real_t r = MIN (right - left, top - bottom) / 6.0; /* top of the rectangle */ glPushMatrix(); glTranslatef (left + r, top - r, 0.0f); draw_partial_disk (r, 270.0f, topColor, 90.0f, topColor); glPopMatrix(); draw_gradient_rectangle (left + r, right - r, top - r, top, topColor, topColor); glPushMatrix(); glTranslatef (right - r, top - r, 0.0f); draw_partial_disk (r, 0.0f, topColor, 90.0f, topColor); glPopMatrix(); /* middle of the rectangle */ draw_gradient_rectangle (left, right, bottom + r, top - r, bottomColor, topColor); /* bottom of the rectangle */ glPushMatrix(); glTranslatef (left + r, bottom + r, 0.0f); draw_partial_disk (r, 180.0f, bottomColor, 90.0f, bottomColor); glPopMatrix(); draw_gradient_rectangle (left + r, right - r, bottom, bottom + r, bottomColor, bottomColor); glPushMatrix(); glTranslatef (right - r, bottom + r, 0.0f); draw_partial_disk (r, 90.0f, bottomColor, 90.0f, bottomColor); glPopMatrix(); } void draw_button (const real_t left, const real_t right, const real_t bottom, const real_t top, const real_t shift) { draw_rounded_rectangle (left, right, bottom, top, themeBottomColor, themeTopColor); draw_rounded_rectangle (left+shift, right-shift, bottom+shift, top-shift, themeInBottomColor, themeInTopColor); }