2017-06-12 15:35:22 +03:00
|
|
|
//
|
|
|
|
// Fl_Rect header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2022-01-22 20:36:58 +03:00
|
|
|
// Copyright 1998-2022 by Bill Spitzak and others.
|
2017-06-12 15:35:22 +03:00
|
|
|
//
|
|
|
|
// 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:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2017-06-12 15:35:22 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2017-06-12 15:35:22 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2017-06-12 15:35:22 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Fl_Rect_H
|
|
|
|
#define Fl_Rect_H
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
#include <FL/Fl_Widget.H> // for c'tor based on Fl_Widget
|
2017-06-12 15:35:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Rectangle with standard FLTK coordinates (X, Y, W, H).
|
|
|
|
|
|
|
|
This may be used internally, for overloaded widget contructors and other
|
|
|
|
overloaded methods like fl_measure(), fl_text_extents(), fl_rect(),
|
|
|
|
fl_rectf(), and maybe more.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class FL_EXPORT Fl_Rect {
|
|
|
|
|
|
|
|
int x_;
|
|
|
|
int y_;
|
|
|
|
int w_;
|
|
|
|
int h_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** The default constructor creates an empty rectangle (x = y = w = h = 0). */
|
|
|
|
Fl_Rect()
|
2018-03-12 15:57:28 +03:00
|
|
|
: x_(0), y_(0), w_(0), h_(0) {}
|
2017-06-12 15:35:22 +03:00
|
|
|
|
|
|
|
/** This constructor creates a rectangle with x = y = 0 and
|
|
|
|
the given width and height. */
|
|
|
|
Fl_Rect(int W, int H)
|
2018-03-12 15:57:28 +03:00
|
|
|
: x_(0), y_(0), w_(W), h_(H) {}
|
2017-06-12 15:35:22 +03:00
|
|
|
|
|
|
|
/** This constructor creates a rectangle with the given x,y coordinates
|
|
|
|
and the given width and height. */
|
|
|
|
Fl_Rect(int X, int Y, int W, int H)
|
2018-03-12 15:57:28 +03:00
|
|
|
: x_(X), y_(Y), w_(W), h_(H) {}
|
2017-06-12 15:35:22 +03:00
|
|
|
|
2022-01-22 20:36:58 +03:00
|
|
|
/** This constructor creates a rectangle with the given x,y coordinates
|
|
|
|
and the given width and height reduced by the box frame size.
|
|
|
|
|
|
|
|
This is the same as using the constructor w/o \p bt and subsequently
|
|
|
|
calling inset(\p bt).
|
|
|
|
*/
|
|
|
|
Fl_Rect(int X, int Y, int W, int H, Fl_Boxtype bt)
|
|
|
|
: x_(X), y_(Y), w_(W), h_(H) {
|
|
|
|
inset(bt);
|
|
|
|
}
|
|
|
|
|
2018-03-12 23:54:27 +03:00
|
|
|
/** This constructor creates a rectangle based on a widget's position and size. */
|
2017-06-12 15:35:22 +03:00
|
|
|
Fl_Rect (const Fl_Widget& widget)
|
2018-03-12 15:57:28 +03:00
|
|
|
: x_(widget.x()), y_(widget.y()), w_(widget.w()), h_(widget.h()) {}
|
2017-06-12 15:35:22 +03:00
|
|
|
|
2018-03-12 23:54:27 +03:00
|
|
|
/** This constructor creates a rectangle based on a widget's position and size. */
|
2017-06-12 15:35:22 +03:00
|
|
|
Fl_Rect (const Fl_Widget* const widget)
|
2018-03-12 15:57:28 +03:00
|
|
|
: x_(widget->x()), y_(widget->y()), w_(widget->w()), h_(widget->h()) {}
|
2018-03-10 03:46:12 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
int x() const { return x_; } ///< gets the x coordinate (left edge)
|
|
|
|
int y() const { return y_; } ///< gets the y coordinate (top edge)
|
|
|
|
int w() const { return w_; } ///< gets the width
|
|
|
|
int h() const { return h_; } ///< gets the height
|
2017-06-12 15:35:22 +03:00
|
|
|
|
2018-04-10 21:41:34 +03:00
|
|
|
/** gets the right edge (x + w).
|
|
|
|
\note r() and b() are coordinates \b outside the area of the rectangle.
|
|
|
|
*/
|
|
|
|
int r() const { return x_ + w_; }
|
|
|
|
/** gets the bottom edge (y + h).
|
|
|
|
\note r() and b() are coordinates \b outside the area of the rectangle.
|
|
|
|
*/
|
|
|
|
int b() const { return y_ + h_; }
|
2017-06-12 15:35:22 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
void x(int X) { x_ = X; } ///< sets the x coordinate (left edge)
|
|
|
|
void y(int Y) { y_ = Y; } ///< sets the y coordinate (top edge)
|
|
|
|
void w(int W) { w_ = W; } ///< sets the width
|
|
|
|
void h(int H) { h_ = H; } ///< sets the height
|
2017-06-12 15:35:22 +03:00
|
|
|
|
2022-01-22 20:36:58 +03:00
|
|
|
/** Move all edges in by \p d.
|
|
|
|
|
|
|
|
Shrinks the rectangle by \p d at all sides keeping the center of the
|
|
|
|
rectangle at the same spot.
|
|
|
|
|
|
|
|
If \p d is negative, the rectangle is enlarged.
|
|
|
|
|
|
|
|
If \p d \>= w() or h() the result is undefined, i.e. an
|
|
|
|
invalid or empty rectangle.
|
|
|
|
*/
|
|
|
|
void inset(int d) {
|
|
|
|
x_ += d;
|
|
|
|
y_ += d;
|
|
|
|
w_ -= 2 * d;
|
|
|
|
h_ -= 2 * d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Move all edges in by the frame size of box type \p bt.
|
|
|
|
|
|
|
|
Shrinks the rectangle at all sides by the frame width or height of the
|
|
|
|
given box type \p bt.
|
|
|
|
|
|
|
|
This method uses the frame sizes given by the box type \p bt using
|
|
|
|
- Fl::box_dx(bt)
|
|
|
|
- Fl::box_dy(bt)
|
|
|
|
- Fl::box_dw(bt)
|
|
|
|
- Fl::box_dh(bt)
|
|
|
|
|
|
|
|
If the rectangle is smaller than the frame sizes the result is undefined,
|
|
|
|
i.e. an invalid or empty rectangle.
|
|
|
|
*/
|
|
|
|
void inset(Fl_Boxtype bt) {
|
|
|
|
x_ += Fl::box_dx(bt);
|
|
|
|
y_ += Fl::box_dy(bt);
|
|
|
|
w_ -= Fl::box_dw(bt);
|
|
|
|
h_ -= Fl::box_dh(bt);
|
|
|
|
}
|
2017-06-12 15:35:22 +03:00
|
|
|
}; // class Fl_Rect
|
|
|
|
|
|
|
|
#endif // Fl_Rect_H
|