FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_Rect.H
1//
2// Fl_Rect header file for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 1998-2023 by Bill Spitzak and others.
5//
6// This library is free software. Distribution and use rights are outlined in
7// the file "COPYING" which should have been included with this file. If this
8// file is missing or damaged, see the license at:
9//
10// https://www.fltk.org/COPYING.php
11//
12// Please see the following page on how to report bugs and issues:
13//
14// https://www.fltk.org/bugs.php
15//
16
17#ifndef Fl_Rect_H
18#define Fl_Rect_H
19
20#include <FL/Fl_Widget.H> // for c'tor based on Fl_Widget
21
29
30 class FL_EXPORT Fl_Rect {
31
32 int x_;
33 int y_;
34 int w_;
35 int h_;
36
37 public:
38
40 Fl_Rect()
41 : x_(0), y_(0), w_(0), h_(0) {}
42
45 Fl_Rect(int W, int H)
46 : x_(0), y_(0), w_(W), h_(H) {}
47
50 Fl_Rect(int X, int Y, int W, int H)
51 : x_(X), y_(Y), w_(W), h_(H) {}
52
59 Fl_Rect(int X, int Y, int W, int H, Fl_Boxtype bt)
60 : x_(X), y_(Y), w_(W), h_(H) {
61 inset(bt);
62 }
63
65 Fl_Rect (const Fl_Widget& widget)
66 : x_(widget.x()), y_(widget.y()), w_(widget.w()), h_(widget.h()) {}
67
69 Fl_Rect (const Fl_Widget* const widget)
70 : x_(widget->x()), y_(widget->y()), w_(widget->w()), h_(widget->h()) {}
71
72 int x() const { return x_; }
73 int y() const { return y_; }
74 int w() const { return w_; }
75 int h() const { return h_; }
76
80 int r() const { return x_ + w_; }
84 int b() const { return y_ + h_; }
85
86 void x(int X) { x_ = X; }
87 void y(int Y) { y_ = Y; }
88 void w(int W) { w_ = W; }
89 void h(int H) { h_ = H; }
90
91 void r(int R) { w_ = R - x_; }
92 void b(int B) { h_ = B - y_; }
93
104 void inset(int d) {
105 x_ += d;
106 y_ += d;
107 w_ -= 2 * d;
108 h_ -= 2 * d;
109 }
110
125 void inset(Fl_Boxtype bt) {
126 x_ += Fl::box_dx(bt);
127 y_ += Fl::box_dy(bt);
128 w_ -= Fl::box_dw(bt);
129 h_ -= Fl::box_dh(bt);
130 }
131
142 void inset(int left, int top, int right, int bottom) {
143 x_ += left;
144 y_ += top;
145 w_ -= (left + right);
146 h_ -= (top + bottom);
147 }
148
149 friend bool operator==(const Fl_Rect& lhs, const Fl_Rect& rhs) {
150 return (lhs.x_==rhs.x_) && (lhs.y_==rhs.y_) && (lhs.w_==rhs.w_) && (lhs.h_==rhs.h_);
151 }
152
153 friend bool operator!=(const Fl_Rect& lhs, const Fl_Rect& rhs) {
154 return !(lhs==rhs);
155 }
156
157}; // class Fl_Rect
158
159#endif // Fl_Rect_H
Fl_Boxtype
Fl_Boxtype
FLTK standard box types.
Definition Enumerations.H:644
Fl_Widget.H
Fl_Widget and Fl_Label classes.
Fl_Rect
Rectangle with standard FLTK coordinates (X, Y, W, H).
Definition Fl_Rect.H:30
Fl_Rect::r
int r() const
gets the right edge (x + w).
Definition Fl_Rect.H:80
Fl_Rect::y
int y() const
gets the y coordinate (top edge)
Definition Fl_Rect.H:73
Fl_Rect::b
int b() const
gets the bottom edge (y + h).
Definition Fl_Rect.H:84
Fl_Rect::Fl_Rect
Fl_Rect(int W, int H)
This constructor creates a rectangle with x = y = 0 and the given width and height.
Definition Fl_Rect.H:45
Fl_Rect::Fl_Rect
Fl_Rect(const Fl_Widget &widget)
This constructor creates a rectangle based on a widget's position and size.
Definition Fl_Rect.H:65
Fl_Rect::Fl_Rect
Fl_Rect(const Fl_Widget *const widget)
This constructor creates a rectangle based on a widget's position and size.
Definition Fl_Rect.H:69
Fl_Rect::x
void x(int X)
sets the x coordinate (left edge)
Definition Fl_Rect.H:86
Fl_Rect::r
void r(int R)
sets the width based on R and x
Definition Fl_Rect.H:91
Fl_Rect::w
int w() const
gets the width
Definition Fl_Rect.H:74
Fl_Rect::Fl_Rect
Fl_Rect(int X, int Y, int W, int H, Fl_Boxtype bt)
This constructor creates a rectangle with the given x,y coordinates and the given width and height re...
Definition Fl_Rect.H:59
Fl_Rect::h
int h() const
gets the height
Definition Fl_Rect.H:75
Fl_Rect::b
void b(int B)
sets the height based on B and y
Definition Fl_Rect.H:92
Fl_Rect::Fl_Rect
Fl_Rect(int X, int Y, int W, int H)
This constructor creates a rectangle with the given x,y coordinates and the given width and height.
Definition Fl_Rect.H:50
Fl_Rect::Fl_Rect
Fl_Rect()
The default constructor creates an empty rectangle (x = y = w = h = 0).
Definition Fl_Rect.H:40
Fl_Rect::inset
void inset(Fl_Boxtype bt)
Move all edges in by the frame size of box type bt.
Definition Fl_Rect.H:125
Fl_Rect::y
void y(int Y)
sets the y coordinate (top edge)
Definition Fl_Rect.H:87
Fl_Rect::x
int x() const
gets the x coordinate (left edge)
Definition Fl_Rect.H:72
Fl_Rect::w
void w(int W)
sets the width
Definition Fl_Rect.H:88
Fl_Rect::h
void h(int H)
sets the height
Definition Fl_Rect.H:89
Fl_Rect::inset
void inset(int left, int top, int right, int bottom)
Move all edges in by left, top, right, bottom.
Definition Fl_Rect.H:142
Fl_Rect::inset
void inset(int d)
Move all edges in by d.
Definition Fl_Rect.H:104
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
Fl::box_dx
static int box_dx(Fl_Boxtype)
Returns the X offset for the given boxtype.
Definition fl_boxtype.cxx:379
Fl::box_dw
static int box_dw(Fl_Boxtype)
Returns the width offset for the given boxtype.
Definition fl_boxtype.cxx:410
Fl::box_dy
static int box_dy(Fl_Boxtype)
Returns the Y offset for the given boxtype.
Definition fl_boxtype.cxx:404
Fl::box_dh
static int box_dh(Fl_Boxtype)
Returns the height offset for the given boxtype.
Definition fl_boxtype.cxx:416