Blame src/fl_gtk.cxx

Packit Service 9ac617
//
Packit Service 9ac617
// "$Id: fl_gtk.cxx 10781 2015-07-09 00:10:44Z AlbrechtS $"
Packit Service 9ac617
//
Packit Service 9ac617
// "GTK" drawing routines for the Fast Light Tool Kit (FLTK).
Packit Service 9ac617
//
Packit Service 9ac617
// These box types provide a GTK+ look, based on Red Hat's Bluecurve
Packit Service 9ac617
// theme...
Packit Service 9ac617
//
Packit Service 9ac617
// Copyright 2006-2010 by Michael Sweet.
Packit Service 9ac617
//
Packit Service 9ac617
// This library is free software. Distribution and use rights are outlined in
Packit Service 9ac617
// the file "COPYING" which should have been included with this file.  If this
Packit Service 9ac617
// file is missing or damaged, see the license at:
Packit Service 9ac617
//
Packit Service 9ac617
//     http://www.fltk.org/COPYING.php
Packit Service 9ac617
//
Packit Service 9ac617
// Please report all bugs and problems on the following page:
Packit Service 9ac617
//
Packit Service 9ac617
//     http://www.fltk.org/str.php
Packit Service 9ac617
//
Packit Service 9ac617
Packit Service 9ac617
// Box drawing code for an obscure box type.
Packit Service 9ac617
// These box types are in separate files so they are not linked
Packit Service 9ac617
// in if not used.
Packit Service 9ac617
Packit Service 9ac617
#include <FL/Fl.H>
Packit Service 9ac617
#include <FL/fl_draw.H>
Packit Service 9ac617
Packit Service 9ac617
extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_color(Fl_Color c) {
Packit Service 9ac617
  Fl::set_box_color(c);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
static void gtk_up_frame(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.5));
Packit Service 9ac617
  fl_xyline(x + 2, y + 1, x + w - 3);
Packit Service 9ac617
  fl_yxline(x + 1, y + 2, y + h - 3);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.5));
Packit Service 9ac617
  fl_begin_loop();
Packit Service 9ac617
    fl_vertex(x, y + 2);
Packit Service 9ac617
    fl_vertex(x + 2, y);
Packit Service 9ac617
    fl_vertex(x + w - 3, y);
Packit Service 9ac617
    fl_vertex(x + w - 1, y + 2);
Packit Service 9ac617
    fl_vertex(x + w - 1, y + h - 3);
Packit Service 9ac617
    fl_vertex(x + w - 3, y + h - 1);
Packit Service 9ac617
    fl_vertex(x + 2, y + h - 1);
Packit Service 9ac617
    fl_vertex(x, y + h - 3);
Packit Service 9ac617
  fl_end_loop();
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_up_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_up_frame(x, y, w, h, c);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
Packit Service 9ac617
  fl_xyline(x + 2, y + 2, x + w - 3);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
Packit Service 9ac617
  fl_xyline(x + 2, y + 3, x + w - 3);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
Packit Service 9ac617
  fl_xyline(x + 2, y + 4, x + w - 3);
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  fl_rectf(x + 2, y + 5, w - 4, h - 7);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
Packit Service 9ac617
  fl_xyline(x + 2, y + h - 4, x + w - 3);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
Packit Service 9ac617
  fl_xyline(x + 2, y + h - 3, x + w - 3);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
Packit Service 9ac617
  fl_xyline(x + 2, y + h - 2, x + w - 3);
Packit Service 9ac617
  fl_yxline(x + w - 2, y + 2, y + h - 3);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_down_frame(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.5));
Packit Service 9ac617
  fl_begin_loop();
Packit Service 9ac617
    fl_vertex(x, y + 2);
Packit Service 9ac617
    fl_vertex(x + 2, y);
Packit Service 9ac617
    fl_vertex(x + w - 3, y);
Packit Service 9ac617
    fl_vertex(x + w - 1, y + 2);
Packit Service 9ac617
    fl_vertex(x + w - 1, y + h - 3);
Packit Service 9ac617
    fl_vertex(x + w - 3, y + h - 1);
Packit Service 9ac617
    fl_vertex(x + 2, y + h - 1);
Packit Service 9ac617
    fl_vertex(x, y + h - 3);
Packit Service 9ac617
  fl_end_loop();
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
Packit Service 9ac617
  fl_xyline(x + 2, y + 1, x + w - 3);
Packit Service 9ac617
  fl_yxline(x + 1, y + 2, y + h - 3);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
Packit Service 9ac617
  fl_yxline(x + 2, y + h - 2, y + 2, x + w - 2);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_down_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_down_frame(x, y, w, h, c);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  fl_rectf(x + 3, y + 3, w - 5, h - 4);
Packit Service 9ac617
  fl_yxline(x + w - 2, y + 3, y + h - 3);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_thin_up_frame(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.6f));
Packit Service 9ac617
  fl_xyline(x + 1, y, x + w - 2);
Packit Service 9ac617
  fl_yxline(x, y + 1, y + h - 2);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.4f));
Packit Service 9ac617
  fl_xyline(x + 1, y + h - 1, x + w - 2);
Packit Service 9ac617
  fl_yxline(x + w - 1, y + 1, y + h - 2);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_thin_up_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_thin_up_frame(x, y, w, h, c);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
Packit Service 9ac617
  fl_xyline(x + 1, y + 1, x + w - 2);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
Packit Service 9ac617
  fl_xyline(x + 1, y + 2, x + w - 2);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
Packit Service 9ac617
  fl_xyline(x + 1, y + 3, x + w - 2);
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  fl_rectf(x + 1, y + 4, w - 2, h - 8);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
Packit Service 9ac617
  fl_xyline(x + 1, y + h - 4, x + w - 2);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
Packit Service 9ac617
  fl_xyline(x + 1, y + h - 3, x + w - 2);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
Packit Service 9ac617
  fl_xyline(x + 1, y + h - 2, x + w - 2);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_thin_down_frame(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.4f));
Packit Service 9ac617
  fl_xyline(x + 1, y, x + w - 2);
Packit Service 9ac617
  fl_yxline(x, y + 1, y + h - 2);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.6f));
Packit Service 9ac617
  fl_xyline(x + 1, y + h - 1, x + w - 2);
Packit Service 9ac617
  fl_yxline(x + w - 1, y + 1, y + h - 2);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_thin_down_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_thin_down_frame(x, y, w, h, c);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  fl_rectf(x + 1, y + 1, w - 2, h - 2);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
//------------------------
Packit Service 9ac617
// new GTK+ style for round buttons
Packit Service 9ac617
#if 1
Packit Service 9ac617
Packit Service 9ac617
static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
Packit Service 9ac617
  fl_arc(x,y,w,h,a1,a2);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
Packit Service 9ac617
Packit Service 9ac617
static void draw(int which, int x,int y,int w,int h, int inset)
Packit Service 9ac617
{
Packit Service 9ac617
  if (inset*2 >= w) inset = (w-1)/2;
Packit Service 9ac617
  if (inset*2 >= h) inset = (h-1)/2;
Packit Service 9ac617
  x += inset;
Packit Service 9ac617
  y += inset;
Packit Service 9ac617
  w -= 2*inset;
Packit Service 9ac617
  h -= 2*inset;
Packit Service 9ac617
  int d = w <= h ? w : h;
Packit Service 9ac617
  if (d <= 1) return;
Packit Service 9ac617
  void (*f)(int,int,int,int,double,double);
Packit Service 9ac617
  f = (which==FILL) ? fl_pie : fl_arc_i;
Packit Service 9ac617
  if (which >= CLOSED) {
Packit Service 9ac617
    f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
Packit Service 9ac617
    f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
Packit Service 9ac617
  } else if (which == UPPER_LEFT) {
Packit Service 9ac617
    f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
Packit Service 9ac617
    f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
Packit Service 9ac617
  } else { // LOWER_RIGHT
Packit Service 9ac617
    f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
Packit Service 9ac617
    f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
Packit Service 9ac617
  }
Packit Service 9ac617
  if (which == FILL) {
Packit Service 9ac617
    if (w < h)
Packit Service 9ac617
      fl_rectf(x, y+d/2, w, h-(d&-2));
Packit Service 9ac617
    else if (w > h)
Packit Service 9ac617
      fl_rectf(x+d/2, y, w-(d&-2), h);
Packit Service 9ac617
  } else {
Packit Service 9ac617
    if (w < h) {
Packit Service 9ac617
      if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
Packit Service 9ac617
      if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
Packit Service 9ac617
    } else if (w > h) {
Packit Service 9ac617
      if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
Packit Service 9ac617
      if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
Packit Service 9ac617
    }
Packit Service 9ac617
  }
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  draw(FILL,	    x,   y, w,   h, 2);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.025f));
Packit Service 9ac617
  draw(LOWER_RIGHT, x+1, y, w-2, h, 2);
Packit Service 9ac617
  draw(LOWER_RIGHT, x,   y, w,   h, 3);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
Packit Service 9ac617
  draw(LOWER_RIGHT, x+1, y, w-2, h, 1);
Packit Service 9ac617
  draw(LOWER_RIGHT, x,   y, w,   h, 2);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
Packit Service 9ac617
  draw(LOWER_RIGHT, x+1, y, w-2, h, 0);
Packit Service 9ac617
  draw(LOWER_RIGHT, x,   y, w,   h, 1);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.1f));
Packit Service 9ac617
  draw(UPPER_LEFT,  x,   y, w,   h, 4);
Packit Service 9ac617
  draw(UPPER_LEFT,  x+1, y, w-2, h, 3);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.2f));
Packit Service 9ac617
  draw(UPPER_LEFT,  x,   y, w,   h, 3);
Packit Service 9ac617
  draw(UPPER_LEFT,  x+1, y, w-2, h, 2);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.4f));
Packit Service 9ac617
  draw(UPPER_LEFT,  x,   y, w,   h, 2);
Packit Service 9ac617
  draw(UPPER_LEFT,  x+1, y, w-2, h, 1);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.5f));
Packit Service 9ac617
  draw(UPPER_LEFT,  x,   y, w,   h, 1);
Packit Service 9ac617
  draw(UPPER_LEFT,  x+1, y, w-2, h, 0);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
Packit Service 9ac617
  draw(CLOSED,	    x,   y, w,   h, 0);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  draw(FILL,	    x,   y, w,   h, 2);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.05f));
Packit Service 9ac617
  draw(UPPER_LEFT,  x,   y, w,   h, 2);
Packit Service 9ac617
  draw(UPPER_LEFT,  x+1, y, w-2, h, 1);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.1f));
Packit Service 9ac617
  draw(UPPER_LEFT,  x,   y, w,   h, 1);
Packit Service 9ac617
  draw(UPPER_LEFT,  x+1, y, w-2, h, 0);
Packit Service 9ac617
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
Packit Service 9ac617
  draw(CLOSED,	    x,   y, w,   h, 0);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
#else
Packit Service 9ac617
Packit Service 9ac617
static void gtk_round_up_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  fl_pie(x, y, w, h, 0.0, 360.0);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.5f));
Packit Service 9ac617
  fl_arc(x, y, w, h, 45.0, 180.0);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_WHITE, c, 0.25f));
Packit Service 9ac617
  fl_arc(x, y, w, h, 180.0, 405.0);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.5f));
Packit Service 9ac617
  fl_arc(x, y, w, h, 225.0, 360.0);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
static void gtk_round_down_box(int x, int y, int w, int h, Fl_Color c) {
Packit Service 9ac617
  gtk_color(c);
Packit Service 9ac617
  fl_pie(x, y, w, h, 0.0, 360.0);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.2));
Packit Service 9ac617
  fl_arc(x + 1, y, w, h, 90.0, 210.0);
Packit Service 9ac617
  gtk_color(fl_color_average(FL_BLACK, c, 0.6));
Packit Service 9ac617
  fl_arc(x, y, w, h, 0.0, 360.0);
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
#endif
Packit Service 9ac617
Packit Service 9ac617
Fl_Boxtype fl_define_FL_GTK_UP_BOX() {
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_UP_BOX, gtk_up_box);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_DOWN_BOX, gtk_down_box);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_UP_FRAME, gtk_up_frame);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_DOWN_FRAME, gtk_down_frame);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_THIN_UP_BOX, gtk_thin_up_box);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_THIN_DOWN_BOX, gtk_thin_down_box);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_THIN_UP_FRAME, gtk_thin_up_frame);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_THIN_DOWN_FRAME, gtk_thin_down_frame);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_ROUND_UP_BOX, gtk_round_up_box);
Packit Service 9ac617
  fl_internal_boxtype(_FL_GTK_ROUND_DOWN_BOX, gtk_round_down_box);
Packit Service 9ac617
Packit Service 9ac617
  return _FL_GTK_UP_BOX;
Packit Service 9ac617
}
Packit Service 9ac617
Packit Service 9ac617
Packit Service 9ac617
//
Packit Service 9ac617
// End of "$Id: fl_gtk.cxx 10781 2015-07-09 00:10:44Z AlbrechtS $".
Packit Service 9ac617
//