summaryrefslogtreecommitdiff
path: root/src/fl_round_box.cxx
blob: aae5ef5b187f93317e54614c405ecbbaffda4265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Round box drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
//     https://www.fltk.org/bugs.php
//

// Box drawing code for an obscure box type.
// These box types are in separate files so they are not linked
// in if not used.

#include <FL/Fl.H>
#include <FL/fl_draw.H>

// A compiler from a certain very large software company will not compile
// the function pointer assignment due to the name conflict with fl_arc.
// This function is to fix that:
static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
  fl_arc(x,y,w,h,a1,a2);
}

enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};

static void draw(int which, int x,int y,int w,int h, int inset, Fl_Color color)
{
  if (inset*2 >= w) inset = (w-1)/2;
  if (inset*2 >= h) inset = (h-1)/2;
  x += inset;
  y += inset;
  w -= 2*inset;
  h -= 2*inset;
  int d = w <= h ? w : h;
  if (d <= 1) return;
  fl_color(color);
  void (*f)(int,int,int,int,double,double);
  f = (which==FILL) ? fl_pie : fl_arc_i;
  if (which >= CLOSED) {
    if (w == h) f(x, y, d, d, 0, 360);
    else {
      f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
      f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
    }
  } else if (which == UPPER_LEFT) {
    if (w == h) f(x, y, d, d, 45, 225);
    else {
      f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
      f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
    }
  } else { // LOWER_RIGHT
    if (w == h) f(x, y, d, d, 225, 405);
    else {
      f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
      f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
    }
  }
  if (which == FILL) {
    if (w < h)
      fl_rectf(x, y+d/2, w, h-(d&-2)+1);
    else if (w > h)
      fl_rectf(x+d/2, y, w-(d&-2)+1, h);
  } else {
    if (w < h) {
      if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
      if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
    } else if (w > h) {
      if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
      if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
    }
  }
}

extern const uchar* fl_gray_ramp();

void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
  const uchar *g = fl_gray_ramp();
  draw(FILL,        x,   y, w,   h, 2, Fl::box_color(bgcolor));
  draw(UPPER_LEFT,  x+1, y, w-2, h, 0, (Fl_Color)g[(int)'N']);
  draw(UPPER_LEFT,  x+1, y, w-2, h, 1, (Fl_Color)g[(int)'H']);
  draw(UPPER_LEFT,  x,   y, w,   h, 0, (Fl_Color)g[(int)'N']);
  draw(UPPER_LEFT,  x,   y, w,   h, 1, (Fl_Color)g[(int)'H']);
  draw(LOWER_RIGHT, x,   y, w,   h, 0, (Fl_Color)g[(int)'S']);
  draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'U']);
  draw(LOWER_RIGHT, x,   y, w,   h, 1, (Fl_Color)g[(int)'U']);
  draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'W']);
  draw(CLOSED,      x,   y, w,   h, 2, (Fl_Color)g[(int)'A']);
}

void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor) {
  const uchar *g = fl_gray_ramp();
  draw(FILL,        x,   y, w,   h, 2, Fl::box_color(bgcolor));
  draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'H']);
  draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'N']);
  draw(LOWER_RIGHT, x,   y, w,   h, 1, (Fl_Color)g[(int)'H']);
  draw(LOWER_RIGHT, x,   y, w,   h, 2, (Fl_Color)g[(int)'N']);
  draw(UPPER_LEFT,  x,   y, w,   h, 2, (Fl_Color)g[(int)'U']);
  draw(UPPER_LEFT,  x+1, y, w-2, h, 1, (Fl_Color)g[(int)'S']);
  draw(UPPER_LEFT,  x,   y, w,   h, 1, (Fl_Color)g[(int)'W']);
  draw(UPPER_LEFT,  x+1, y, w-2, h, 0, (Fl_Color)g[(int)'U']);
  draw(CLOSED,      x,   y, w,   h, 0, (Fl_Color)g[(int)'A']);
}

void fl_round_focus(Fl_Boxtype bt, int x, int y, int w, int h, Fl_Color fg, Fl_Color bg) {
  x += Fl::box_dx(bt);
  y += Fl::box_dy(bt);
  w -= Fl::box_dw(bt);
  h -= Fl::box_dh(bt);
  Fl_Color savecolor = fl_color();
  fl_line_style(FL_DOT);
  draw(CLOSED, x, y, w, h, 0, fl_contrast(fg, bg));
  fl_line_style(FL_SOLID);
  fl_color(savecolor);
}