source: NonGTP/include/fltk/Rectangle.h @ 769

Revision 769, 4.0 KB checked in by gumbau, 18 years ago (diff)

FLTK imported to SVN repository to be linked agains the GeoTool? application

Line 
1// "$Id: Rectangle.h 4306 2005-05-02 06:39:46Z spitzak $"
2//
3// Copyright 1998-2004 by Bill Spitzak and others.
4//
5// This library is free software; you can redistribute it and/or
6// modify it under the terms of the GNU Library General Public
7// License as published by the Free Software Foundation; either
8// version 2 of the License, or (at your option) any later version.
9//
10// This library is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13// Library General Public License for more details.
14//
15// You should have received a copy of the GNU Library General Public
16// License along with this library; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18// USA.
19//
20// Please report all bugs and problems to "fltk-bugs@fltk.org".
21
22#ifndef fltk_Rectangle_h
23#define fltk_Rectangle_h
24
25#include "FL_API.h"
26
27namespace fltk {
28
29class FL_API Rectangle {
30  int x_, y_, w_, h_;
31
32 public:
33
34  /*! Left edge */
35  int x() const {return x_;}
36  /*! Top edge */
37  int y() const {return y_;}
38  /*! Distance between left and right edges */
39  int w() const {return w_;}
40  /*! Distance between top and bottom edges */
41  int h() const {return h_;}
42  /*! Return x()+w(), the right edge of the rectangle. */
43  int r() const {return x_+w_;}
44  /*! Return y()+h(), the bottom edge of the rectangle. */
45  int b() const {return y_+h_;}
46  /*! Move the rectangle so the left edge is at \a v. */
47  void x(int v) {x_ = v;}
48  /*! Move the rectangle so the top edge is at \a v. */
49  void y(int v) {y_ = v;}
50  /*! Change w() by moving the right edge. x() does not change. */
51  void w(int v) {w_ = v;}
52  /*! Change h() by moving the bottom edge. y() does not change. */
53  void h(int v) {h_ = v;}
54  /*! Change x() without changing r(), by changing the width. */
55  void set_x(int v) {w_ -= v-x_; x_ = v;}
56  /*! Change y() without changing b(), by changing the height. */
57  void set_y(int v) {h_ -= v-y_; y_ = v;}
58  /*! Change r() without changing x(), by changine the width. */
59  void set_r(int v) {w_ = v-x_;}
60  /*! Change b() without changing y(), by changine the height. */
61  void set_b(int v) {h_ = v-y_;}
62  /*! Set x(), y(), w(), and h() all at once. */
63  void set(int x, int y, int w, int h) {x_=x; y_=y; w_=w; h_=h;}
64  /*! Add \a d to x() without changing r() (it reduces w() by \a d). */
65  void move_x(int d) {x_ += d; w_ -= d;}
66  /*! Add \a d to y() without changing b() (it reduces h() by \a d). */
67  void move_y(int d) {y_ += d; h_ -= d;}
68  /*! Add \a d to r() and w(). */
69  void move_r(int d) {w_ += d;}
70  /*! Add \a d to b() and h(). */
71  void move_b(int d) {h_ += d;}
72  /*! Move all edges in by \a d. See also Symbol::inset() */
73  void inset(int d) {x_ += d; y_ += d; w_ -= 2*d; h_ -= 2*d;}
74  /*! Move entire rectangle by given distance in x and y. */
75  void move(int dx, int dy) {x_ += dx; y_ += dy;}
76  /*! True if w() or h() are less or equal to zero. */
77  bool empty() const {return w_ <= 0 || h_ <= 0;}
78  /*! Same as !empty(), true if w() and h() are both greater than zero. */
79  bool not_empty() const {return w_ > 0 && h_ > 0;}
80  /*! Integer center position. Rounded to the left if w() is odd. */
81  int center_x() const {return x_+(w_>>1);}
82  /*! Integer center position. Rounded to lower y if h() is odd. */
83  int center_y() const {return y_+(h_>>1);}
84  /*! Where to put baseline to center current font nicely */
85  int baseline_y() const;
86
87  Rectangle() {}
88
89  /*! Constructor that sets x(), y(), w(), and h(). */
90  Rectangle(int x, int y, int w, int h) : x_(x), y_(y), w_(w), h_(h) {}
91
92  /*! Constructor that sets x() and y() to zero, and sets w() and h(). */
93  Rectangle(int w, int h) : x_(0), y_(0), w_(w), h_(h) {}
94
95  /*! Copy constructor. */
96  Rectangle(const Rectangle& r) : x_(r.x_),y_(r.y_),w_(r.w_),h_(r.h_) {}
97
98  Rectangle(const Rectangle& r, int w, int h, int flags = 0);
99
100  /*! True if rectangle contains the pixel who's upper-left corner is at x,y */
101  bool contains(int x, int y) const {return x>=x_ && y>=y_ && x<x_+w_ && y<y_+h_;}
102 
103};
104
105}
106
107#endif
108
109
Note: See TracBrowser for help on using the repository browser.