[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'fpg_base' (#fpgui)

TfpgRect

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

A graphical (pixel based) rectangle structure used throughout fpGUI.

Declaration

Source position: fpg_base.pas line 146

type TfpgRect = object

  Top: TfpgCoord;

  Left: TfpgCoord;

  Width: TfpgCoord;

  Height: TfpgCoord;

  procedure SetRect();

  

A convenience function to quickly set a rectangle structure.

  function Bottom;

  

Calculates and returns the bottom position of the rectangle.

  function Right;

  

Calculates and returns the Right most position of the rectangle.

  procedure SetBottom();

  

Sets the bottom value and recalculates the Height value.

  procedure SetRight();

  

Sets the Right value and recalculates the Width value.

end;

Inheritance

TfpgRect

  

A graphical (pixel based) rectangle structure used throughout fpGUI.

Description

Note that this structure is not a class, so static allocations are allowed. This makes it much easier to use in Widgets and in fpGUI internal messages.

Think of the pixel screen/grid like the grid of a spreadsheet (or as a magnified look of the top corner of your screen).

.
     0   1
   +---+---+---
0  | x |   |
   +---+---+---
1  |   |   |
   +---+---+---
2  |   |   |
   +---+---+---
   |   |   |

x is at (0,0). A pixel is always 1x1, you don't get smaller (we are not using sub-pixels like on LCD screens, because they don't apply to all screens).

So with that example, Width = 1 pixel and Height = 1 pixel. In the case of Classes.Bounds() the Right and Bottom values are (1,1) which looking at the above image will be wrong, the pixel only covers one block, so in a screen/pixel environment, Right, Bottom is also (0,0), the same as Top/Left. This is what TfpgRect.Right and TfpgRect.Bottom will report.

.
     0   1
   +---+---+---
0  | x | x |
   +---+---+---
1  | x | x |
   +---+---+---
2  |   |   |
   +---+---+---
   |   |   |

In this example we have a rectangle. Top/Left = (0,0) and Bottom/Right = (1,1). This means Width = 2 pixels and Height = 2 pixels. Clearly visible in the image above.

But if we call Classes.Bounds(0,0,2,2) it reports Bottom/Right as (2,2) which is wrong (again looking at the image above as reference). This is my point. Bounds() cannot be used in this case in a graphical environment.

The reason I don't use a grid layout as shown below, is because if the mouse is over the rectangle containing x, the OS (graphics system) reports its position as (0,0). You don't have to have the mouse pointer over the intersecting lines at (0,0) as indicated in the image below. The whole square containing the x is referenced as (0,0), hence the grid layout as show in the images above, and what fpGUI uses. The same grid layout as used in TfpgStringGrid or any Spreadsheet program etc.

.
   0   1   2
0  +---+---+---
   | x |   |
1  +---+---+---
   |   |   |
2  +---+---+---
   |   |   |
3  +---+---+---
   |   |   |

Documentation generated on: 2013-04-29