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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
//
// "$Id$"
//
// Label test program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 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:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Hor_Value_Slider.H>
#include <FL/Fl_Toggle_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Choice.H>
#include <FL/fl_draw.H>
#include <math.h>
#ifndef M_PI
#define M_PI 3.141592654
#endif
Fl_Toggle_Button *leftb,*rightb,*clipb;
//Fl_Box *text;
Fl_Input *input;
Fl_Hor_Value_Slider *fonts;
Fl_Hor_Value_Slider *sizes;
Fl_Hor_Value_Slider *angles;
Fl_Double_Window *window;
//code taken from fl_engraved_label.cxx
class Rotated_Label_Box : public Fl_Widget{
protected:
void draw(){
draw_box();
fl_font(labelfont(), labelsize());
fl_color(labelcolor());
int dx(0),dy(0);
if(rt_align&FL_ALIGN_CLIP)fl_push_clip(x(),y(),w(),h());
else fl_push_no_clip();
fl_measure(rt_text,dx,dy);
if(rt_align&FL_ALIGN_LEFT){
dx=dy=0;
}else if(rt_align&FL_ALIGN_RIGHT){
dy=(int)(-sin(M_PI*(double)(rt_angle+180)/180.)*(double)dx);
dx=(int)(cos(M_PI*(double)(rt_angle+180)/180.)*(double)dx);
}else{
dy=(int)(sin(M_PI*(double)rt_angle/180.)*(double)dx);
dx=(int)(-cos(M_PI*(double)rt_angle/180.)*(double)dx);
dx/=2;dy/=2;
}
if(labeltype()==FL_SHADOW_LABEL)shadow_label(x()+w()/2+dx,y()+h()/2+dy);
else if(labeltype()==FL_ENGRAVED_LABEL)engraved_label(x()+w()/2+dx,y()+h()/2+dy);
else if(labeltype()==FL_EMBOSSED_LABEL)embossed_label(x()+w()/2+dx,y()+h()/2+dy);
else{
fl_draw(rt_angle,rt_text,x()+w()/2+dx,y()+h()/2+dy);
}
fl_pop_clip();
draw_label();
}
void innards(int X, int Y, int data[][3], int n){
for (int i = 0; i < n; i++) {
fl_color((Fl_Color)(i < n-1 ? data[i][2] : labelcolor()));
fl_draw(rt_angle,rt_text, X+data[i][0], Y+data[i][1]);
}
}
void shadow_label(int X, int Y){
static int data[2][3] = {{2,2,FL_DARK3},{0,0,0}};
innards(X, Y, data, 2);
}
void engraved_label(int X, int Y){
static 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(X, Y, data, 7);
}
void embossed_label(int X, int Y){
static 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(X, Y, data, 7);
}
public:
Rotated_Label_Box(int X, int Y, int W, int H, const char*L=0):
Fl_Widget(X,Y,W,H,L),rt_angle(0),rt_align((Fl_Align)0){
rt_text=input->value();
};
int rt_angle;
const char* rt_text;
Fl_Align rt_align;
}*text;
void button_cb(Fl_Widget *,void *) {
int i = 0;
if (leftb->value()) i |= FL_ALIGN_LEFT;
if (rightb->value()) i |= FL_ALIGN_RIGHT;
if (clipb->value()) i |= FL_ALIGN_CLIP;
text->rt_align=(Fl_Align)i;
window->redraw();
}
void font_cb(Fl_Widget *,void *) {
text->labelfont(int(fonts->value()));
window->redraw();
}
void size_cb(Fl_Widget *,void *) {
text->labelsize(int(sizes->value()));
window->redraw();
}
void angle_cb(Fl_Widget *,void *) {
text->rt_angle=(int)angles->value();
window->redraw();
}
void input_cb(Fl_Widget *,void *) {
text->rt_text=input->value();
window->redraw();
}
void normal_cb(Fl_Widget *,void *) {
text->labeltype(FL_NORMAL_LABEL);
window->redraw();
}
void shadow_cb(Fl_Widget *,void *) {
text->labeltype(FL_SHADOW_LABEL);
window->redraw();
}
void embossed_cb(Fl_Widget *,void *) {
text->labeltype(FL_EMBOSSED_LABEL);
window->redraw();
}
void engraved_cb(Fl_Widget *,void *) {
text->labeltype(FL_ENGRAVED_LABEL);
window->redraw();
}
Fl_Menu_Item choices[] = {
{"FL_NORMAL_LABEL",0,normal_cb},
{"FL_SHADOW_LABEL",0,shadow_cb},
{"FL_ENGRAVED_LABEL",0,engraved_cb},
{"FL_EMBOSSED_LABEL",0,embossed_cb},
{0}};
int main(int argc, char **argv) {
window = new Fl_Double_Window(400,425);
angles= new Fl_Hor_Value_Slider(50,400,350,25,"Angle:");
angles->align(FL_ALIGN_LEFT);
angles->bounds(-360,360);
angles->step(1);
angles->value(0);
angles->callback(angle_cb);
input = new Fl_Input(50,375,350,25);
input->static_value("Rotate Me!!!");
input->when(FL_WHEN_CHANGED);
input->callback(input_cb);
sizes= new Fl_Hor_Value_Slider(50,350,350,25,"Size:");
sizes->align(FL_ALIGN_LEFT);
sizes->bounds(1,64);
sizes->step(1);
sizes->value(14);
sizes->callback(size_cb);
fonts=new Fl_Hor_Value_Slider(50,325,350,25,"Font:");
fonts->align(FL_ALIGN_LEFT);
fonts->bounds(0,15);
fonts->step(1);
fonts->value(0);
fonts->callback(font_cb);
Fl_Group *g = new Fl_Group(50,300,350,25);
leftb = new Fl_Toggle_Button(50,300,50,25,"left");
leftb->callback(button_cb);
rightb = new Fl_Toggle_Button(100,300,50,25,"right");
rightb->callback(button_cb);
clipb = new Fl_Toggle_Button(350,300,50,25,"clip");
clipb->callback(button_cb);
g->resizable(rightb);
g->end();
Fl_Choice *c = new Fl_Choice(50,275,200,25);
c->menu(choices);
text= new Rotated_Label_Box(100,75,200,100,"Widget with rotated text");
text->box(FL_FRAME_BOX);
text->align(FL_ALIGN_BOTTOM);
window->resizable(text);
window->end();
window->show(argc,argv);
return Fl::run();
}
//
// End of "$Id$".
//
|