Class: SMap_Object_Area_Label
Source Location: /SMap/Object.php
Class SMap_Object_Area_Label
Inherited Properties, Constants, and Methods
Property Summary
| static array |
$avoid |
Labels should avoid these places. |
| static mixed |
$cached |
What have we cached in the DB? |
| static object |
$data |
Store a reference to the data object |
| static array |
$labels |
Label's text should be drawn last so it isn't covered |
| array |
$col |
Define the colors of the label |
| integer |
$copyDir |
The label was copied in this direction |
| mixed |
$font |
Define the string |
| string |
$label |
The label's string |
| array |
$layout |
Save the layout that we have found for this label |
Method Summary
| static
void
|
avoid() |
Mark an area in a view to be avoided |
| static
boolean
|
collide() |
Is there a collision? |
| static
void
|
drawBegin() |
Draw the background for a label |
| static
void
|
drawFin() |
Draw the rest of the label (ideally, on top of anything else that has |
| static
void
|
drawLabels() |
Finish drawing the labels |
| static
void
|
flushNotCached() |
On destruct flush the uncached label bounds into the DB (to cache them) |
| SMap_Object_Area_Label |
__construct() |
Give the object a context |
| boolean |
applyTile() |
Apply the layout after the bounds |
| void |
copyOver() |
Copy this object over a given bounds |
| array |
draw() |
Draw a label for an object |
| string |
genKey() |
Generate a key for this label |
| void |
layoutBegin() |
Layout this label in a manner such that it isn't covering something up |
| void |
layoutFin() |
Finish the layout of a label; save any info so it can be drawn or mapped |
Properties
Labels should avoid these places.
Maybe because there is already something there... API Tags:
What have we cached in the DB?
API Tags:
Store a reference to the data object
API Tags:
Label's text should be drawn last so it isn't covered
API Tags:
Define the colors of the label
API Tags:
The label was copied in this direction
API Tags:
Define the string
API Tags:
What object are we attached to?
API Tags:
Save the layout that we have found for this label
API Tags:
Is this label transient?
API Tags:
Methods
static void avoid(
SMap_View
$view, array
$bounds
)
|
|
Mark an area in a view to be avoided
Creates a list of areas that are "off limits" for drawing labels. Keeps track of the view an area is in, because views are drawn sepeartely.
Parameters:
|
object The |
$view: |
view that contains the bounds |
|
array |
$bounds: |
The bounds to avoid. |
API Tags:
static boolean collide(
SMap_View
$view, array
$rB
)
|
|
Is there a collision?
Check for a collision between the given bounds and the ones already marked off by avoid(). Returns true if there is a collision or the bounds are out of the view.
Parameters:
|
object The |
$view: |
containing view. |
|
array |
$rB: |
The bounds to test |
API Tags:
| Return: | Was a collision detected? |
| Access: | public |
static void drawBegin(
SMap_Canvas
$canvas,
$layout,
$vB,
$scale
)
|
|
Draw the background for a label
Parameters:
API Tags:
static void drawFin(
SMap_Canvas
$canvas,
$xy,
$color,
$borderColor,
$col,
$label,
$font,
$x,
$y,
$ang
)
|
|
Draw the rest of the label (ideally, on top of anything else that has
been drawn)
Parameters:
|
SMap_Canvas |
$canvas: |
|
|
|
$xy: |
|
|
|
$color: |
|
|
|
$borderColor: |
|
|
|
$col: |
|
|
|
$label: |
|
|
|
$font: |
|
|
|
$x: |
|
|
|
$y: |
|
|
|
$ang: |
|
API Tags:
static void drawLabels(
SMap_Tile
$tile, boolean
$fetchCached
)
|
|
Finish drawing the labels
This is called after draw() is called on all objects in the tile. It draws the meat of each label, and ensures that all labels get drawn (including those in the DB). For future reference, flushNotCached() can't be called from here because this function is only called when an image is drawn (duh).
Parameters:
|
object The |
$tile: |
containing tile |
|
boolean |
$fetchCached: |
Should we look for cached labels? |
API Tags:
static void flushNotCached(
)
|
|
On destruct flush the uncached label bounds into the DB (to cache them)
API Tags:
Apply the layout after the bounds
Applying a tile to a label is a somewhat tricky matter. The tile must layout(), taking into account any previously laid out labels. After we have determined the layout of the label, we must detect if it overlaps with any ajacent tiles. If it does, we need to pass a copy of the label to said tile, so it is drawn as needed.
Parameters:
|
object Tile |
$tile: |
to apply |
API Tags:
Redefinition of:
- SMap_Object_Area_Rec::applyTile()
void copyOver(
integer
$dir, integer
$newX, integer
$newY
)
|
|
Copy this object over a given bounds
Copy this object using SMap_View::sendObj(). We must also ensure that we aren't copying a label back in the direction of its original tile.
Parameters:
|
integer |
$dir: |
Direction to send the object |
|
integer |
$newX: |
New tile X |
|
integer |
$newY: |
New tile Y |
API Tags:
Draw a label for an object
This gets complex. First, we decide what type of label to draw, is it along a line, point, or in an area? Then we lay out the label taking into account any other labels that may be nearby. This processing happens in layout(). The labels are actually drawn in two stages. The first stage is drawn now in drawBegin(), and the second stage is drawn later in drawFin(). It is done this way so we can draw shadows behind the labels, without drawing the shadows over other labels. The shadows aren't that important.
Parameters:
|
object Draw |
$canvas: |
onto this canvas |
API Tags:
Redefinition of:
- SMap_Object_Area_Rec::draw()
- Draw this rectangle on an image
Get cached layout info
First, all cached data for these view bounds is retrieved from the database. All bounds retuned in this way are marked to be avoided. Then the key is generated. This key is compared to the keys returned in the previous step. Any matching rows are unserialized and processed. The processed data is placed in $overlaps and the unserialized data placed in $layout.
Parameters:
|
object The |
$tile: |
containing tile |
API Tags:
Generate a key for this label
Create a distinct ID for this label. This will be used in the database to save the calculated bounds.
API Tags:
void layoutArea(
SMap_Tile
$tile, array
$pB, integer
$fWidth, integer
$fHeight
)
|
|
Layout the label in an area
Position the label in an area
Parameters:
|
object The |
$tile: |
containing tile |
|
array |
$pB: |
The parent's bounds |
|
integer |
$fWidth: |
Font width in pixels |
|
integer |
$fHeight: |
Font height in pixels |
API Tags:
Layout this label in a manner such that it isn't covering something up
We only do layout once, if anything is added after this label has been laid out, it is ignored. We also check for a previous layout via fetchCachedLayout(). If this label has already been laid out and stored in the database, then that info is used. If the work hasn't already been done for us, the label must be laid out. Some commonly used dimensions are calculated, such as those of the space used by the font. Then the overlaps which were calculated by SMap_Object_Area_Rec::findOverlap() each have the label applied to them. Here the approximate dimension of the area is found, compared to the font, and an appropriate solution is used to layout the label. If the label fits in the area, layoutArea() is used. If the area is a line, then layoutLine() is used. Otherwise, layoutPoint() is used, and we get a nice label with a pointer. The final layout is saved in $layout and used by map() or draw().
Parameters:
|
object The |
$tile: |
containing tile |
API Tags:
void layoutFin(
SMap_Tile
$tile, integer
$fWidth, integer
$fHeight, float
$ang, array
$B, array
$pB, boolean
$hasPtr
)
|
|
Finish the layout of a label; save any info so it can be drawn or mapped
Now that the layout bounds have been defined and passed as a parameter, we must do some cleanup. First we set appropriate $overlaps so this label's rectangle will be drawn at an appropriate place. Then we avoid() this location in future layouts. After that we set $layout and $notCached to contain the appropriate arrays.
Parameters:
|
object The |
$tile: |
containing tile |
|
integer |
$fWidth: |
Font width in pixels |
|
integer |
$fHeight: |
Font height in pixels |
|
float |
$ang: |
Angle of the text |
|
array |
$B: |
Bounds of the label |
|
array |
$pB: |
Bounds of the parent object |
|
boolean |
$hasPtr: |
Does the label have a pointer? |
API Tags:
void layoutLine(
SMap_Tile
$tile, array
$pB, integer
$fWidth, integer
$fHeight
)
|
|
Layout the label on a line
Position the label on a line. Move the label around if it collides with anything. You can set the approximate position of a label by adjusting its alignment.
Parameters:
|
object The |
$tile: |
containing tile |
|
array |
$pB: |
The parent's bounds |
|
integer |
$fWidth: |
Font width in pixels |
|
integer |
$fHeight: |
Font height in pixels |
API Tags:
void layoutPoint(
SMap_Tile
$tile, array
$pB, integer
$fWidth, integer
$fHeight
)
|
|
Layout a label around a point
Positions a label around a point (or small rectangle), with a pointer from the label to the point itself. It works by moving the label in a circular pattern until a position is found
Parameters:
|
object The |
$tile: |
containing tile |
|
array |
$pB: |
The parent's bounds |
|
integer |
$fWidth: |
Font width in pixels |
|
integer |
$fHeight: |
Font height in pixels |
API Tags:
void setFontColor(
$r,
$g,
$b, [
$a = null]
)
|
|
Set the font color of the label
Parameters:
API Tags:
|
|