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
|
//
// Engraved label drawing routines for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2011 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
//
// Drawing code for XForms style engraved & embossed labels
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/fl_draw.H>
// data[] is dx, dy, color triples
static void innards(const char *str, int len, int X, int Y, const int data[][3], int n)
{
Fl_Color c = fl_color();
for (int i = 0; i < n; i++) {
fl_color((Fl_Color)(i < n-1 ? data[i][2] : c));
fl_draw(str, len, X+data[i][0], Y+data[i][1]);
}
fl_color(c);
}
static void dispatch(const Fl_Label* o,
int x, int y, int w, int h, Fl_Align align,
void (*callthis)(const char*,int,int,int))
{
if ((!o->value || !*(o->value)) && !o->image) return;
if (w && h && !fl_not_clipped(x, y, w, h) && (align & FL_ALIGN_INSIDE)) return;
if (align & FL_ALIGN_CLIP)
fl_push_clip(x, y, w, h);
fl_font(o->font, o->size);
fl_color((Fl_Color)o->color);
fl_draw(o->value, x, y, w, h, align, callthis, o->image, 1, o->spacing);
if (align & FL_ALIGN_CLIP)
fl_pop_clip();
}
// Draw text with shadow
static void fl_shadow_label_draw(const char *str, int len, int x, int y) {
static const int data[2][3] = {{2,2,FL_DARK3},{0,0,0}};
innards(str, len, x, y, data, 2);
}
// Implement shadowed text label type
static void fl_shadow_label(
const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align)
{
dispatch(o, X, Y, W, H, align, fl_shadow_label_draw);
}
// Draw text engraved
static void fl_engraved_label_draw(const char *str, int len, int x, int y) {
static const int data[7][3] = {
{1,0,FL_LIGHT3},{1,1,FL_LIGHT3},{0,1,FL_LIGHT3},
{-1,0,FL_DARK3},{-1,-1,FL_DARK3},{0,-1,FL_DARK3},
{0,0,0}};
innards(str, len, x, y, data, 7);
}
// Implement engraved text label type
static void fl_engraved_label(
const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align)
{
dispatch(o, X, Y, W, H, align, fl_engraved_label_draw);
}
// Draw text embossed
static void fl_embossed_label_draw(const char *str, int len, int x, int y) {
static const int data[7][3] = {
{-1,0,FL_LIGHT3},{-1,-1,FL_LIGHT3},{0,-1,FL_LIGHT3},
{1,0,FL_DARK3},{1,1,FL_DARK3},{0,1,FL_DARK3},
{0,0,0}};
innards(str, len, x, y, data, 7);
}
// Implement embossed text label type
static void fl_embossed_label(
const Fl_Label* o, int X, int Y, int W, int H, Fl_Align align)
{
dispatch(o, X, Y, W, H, align, fl_embossed_label_draw);
}
Fl_Labeltype fl_define_FL_SHADOW_LABEL() {
Fl::set_labeltype(_FL_SHADOW_LABEL, fl_shadow_label, 0);
return _FL_SHADOW_LABEL;
}
Fl_Labeltype fl_define_FL_ENGRAVED_LABEL() {
Fl::set_labeltype(_FL_ENGRAVED_LABEL, fl_engraved_label, 0);
return _FL_ENGRAVED_LABEL;
}
Fl_Labeltype fl_define_FL_EMBOSSED_LABEL() {
Fl::set_labeltype(_FL_EMBOSSED_LABEL, fl_embossed_label, 0);
return _FL_EMBOSSED_LABEL;
}
|