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
|
//
// Resize example for use in the Fast Light Tool Kit (FLTK) documentation.
//
// See Article #415: How does resizing work?
// https://www.fltk.org/articles.php?L415
//
// Copyright 1998-2020 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
//
#include "resize-arrows.h"
#include <FL/Fl_Double_Window.H>
// inner box dimensions
int Ax = 0, Bx = 35, Cx = 70, Dx = 105, Nx = 140, Aw = 35, Rw = 70, Mw = 140;
int Ay = 0, Ey = 35, Gy = 70, Iy = 105, My = 140, Ah = 35, Rh = 70, Nh = 175;
// resize box and arrow group dimensions
int TLx = 35, TRx = 245, TGx = 420, TLw = 175, TGw = 140, TAw = 35;
int TLy = 35, BLy = 245, LGy = 420, TLh = 175, LGh = 105, LAh = 35;
// window dimensions
int Ww = 560, Wh = 525;
Fl_Double_Window *window;
class Resizebox : public Fl_Group {
public:
Resizebox(int X, int Y, int W, int H, const char *T);
Fl_Box *m_box;
};
Resizebox::Resizebox(int X, int Y, int W, int H, const char *T)
: Fl_Group(X, Y, W, H, T) {
this->align(FL_ALIGN_TOP_LEFT);
this->box(FL_UP_BOX);
Fl_Box *b;
b = new Fl_Box(FL_FRAME_BOX, X + Ax, Y + Ay, Aw, Ah, "A"); b->color(14);
b = new Fl_Box(FL_FRAME_BOX, X + Bx, Y + Ay, Aw, Ah, "B"); b->color(9);
b = new Fl_Box(FL_FRAME_BOX, X + Cx, Y + Ay, Aw, Ah, "C"); b->color(10);
b = new Fl_Box(FL_FRAME_BOX, X + Dx, Y + Ay, Aw, Ah, "D"); b->color(11);
b = new Fl_Box(FL_FRAME_BOX, X + Ax, Y + Ey, Aw, Ah, "E"); b->color(9);
b = new Fl_Box(FL_FRAME_BOX, X + Bx, Y + Ey, Rw, Rh, "R"); b->color(3);
b->label("resizable");
m_box = b;
b = new Fl_Box(FL_FRAME_BOX, X + Dx, Y + Ey, Aw, Ah, "F"); b->color(12);
b = new Fl_Box(FL_FRAME_BOX, X + Ax, Y + Gy, Aw, Ah, "G"); b->color(10);
b = new Fl_Box(FL_FRAME_BOX, X + Dx, Y + Gy, Aw, Ah, "H"); b->color(13);
b = new Fl_Box(FL_FRAME_BOX, X + Ax, Y + Iy, Aw, Ah, "I"); b->color(11);
b = new Fl_Box(FL_FRAME_BOX, X + Bx, Y + Iy, Aw, Ah, "J"); b->color(12);
b = new Fl_Box(FL_FRAME_BOX, X + Cx, Y + Iy, Aw, Ah, "K"); b->color(13);
b = new Fl_Box(FL_FRAME_BOX, X + Dx, Y + Iy, Aw, Ah, "L"); b->color(14);
b = new Fl_Box(FL_FRAME_BOX, X + Ax, Y + My, Mw, Ah, "M"); b->color(12);
b = new Fl_Box(FL_FRAME_BOX, X + Nx, Y + Ay, Aw, Nh, "N"); b->color(13);
this->end();
this->resizable(m_box);
}
class Resizables : public Fl_Group {
public:
Resizables(int X, int Y, int W, int H, const char *T = 0);
Resizebox *TL, *TR, *BL, *BR; // topleft, topright, bottomleft, bottomright
Harrow *LA, *RA; // left arrow, right arrow
Varrow *TA, *BA; // top arrow, bottom arrow
};
Resizables::Resizables(int X, int Y, int W, int H, const char *T)
: Fl_Group(X, Y, W, H, T) {
this->box(FL_UP_BOX);
this->color(FL_WHITE);
TL = new Resizebox(X + TLx, Y + TLy, TLw, TLh, "Original Size");
TL->resizable(0);
TR = new Resizebox(X + TRx, Y + TLy, TLw, TLh, "Horizontally Resized");
BL = new Resizebox(X + TLx, Y + BLy, TLw, TLh, "Vertically Resized");
BR = new Resizebox(X + TRx, Y + BLy, TLw, TLh, "Horizontally and Vertically Resized");
Fl_Group *LG = new Fl_Group(X + TLx, Y + LGy, TLw, LGh);
LG->box(FL_NO_BOX);
LG->color(FL_WHITE);
LA = new Harrow(BL->m_box->x(), LG->y(), BL->m_box->w(), LAh, "Initial\nwidth");
LG->resizable(LA);
LG->end();
Fl_Group *RG = new Fl_Group(X + TRx, Y + LGy, TLw, LGh);
RG->box(FL_NO_BOX);
RG->color(FL_WHITE);
RA = new Harrow(BR->m_box->x(), LG->y(), BL->m_box->w(), LAh, "Resized\nwidth");
RG->resizable(RA);
RG->end();
Fl_Group *TG = new Fl_Group(X + TGx, Y + TLy, TGw, TLh);
TG->box(FL_NO_BOX);
TG->color(FL_WHITE);
TA = new Varrow(TG->x(), TR->m_box->y(), TAw, TR->m_box->h(), "Initial\nheight");
TG->resizable(TA);
TG->end();
Fl_Group *BG = new Fl_Group(X + TGx, Y + BLy, TGw, TLh);
BG->box(FL_NO_BOX);
BG->color(FL_WHITE);
BA = new Varrow(BG->x(), BR->m_box->y(), TAw, BR->m_box->h(), "Resized\nheight");
BG->resizable(BA);
BG->end();
this->resizable(BR);
this->end();
}
int main(int argc, char **argv) {
window = new Fl_Double_Window(Ww, Wh, "resize-example2");
window->color(FL_WHITE);
Resizables *resizables = new Resizables(0, 0, Ww, Wh);
window->end();
window->resizable(resizables);
window->size_range(Ww, Wh);
window->show(argc, argv);
window->size(Ww + 140, Wh + 35);
return Fl::run();
}
|