-
Notifications
You must be signed in to change notification settings - Fork 2
Gob!
Rebol 3 has a new type: gob!
GOB stands for Grafical Object, before using this guide, remember to launch load-gui
gob1: make gob! [text: "Example" size: 400x40]
view gob1
logo-image: load %reb-logo.gif
gob2: make gob! [offset: 10x20 image: logo-image]
view gob2
You may use also the Rebol 2 Draw commands, but at the moment you can't access directly, you have to use the stylize function:
stylize [
circle: [
about: "A circle style"
facets: [init-size: 100x100]
draw: [
pen black
line-width 2.7
fill-pen maroon
circle 50x50 40
]
]
]
view [a: circle]
If inspect a/gob/draw you you'll find the DRAW commands, but don't try to modify directly it!
>> ? a/gob
== A/GOB is a gob of value: make gob! [
offset: 5x5
size: 105x104
alpha: 0
draw: [translate 0x0 clip 0x0 105x104 anti-alias false pen false
line-width 1.0 variable
pen 255.255.255 fill-pen false anti-alias true pen 0.0.0 line-width 2.7
variable fill-pen 128.0.0 circle 50x50 40x40
]
]
A solution proposed by Boleslav Březovský to access to /draw directly it so use the to-draw function; example:
>> gob: make gob! [draw: []]
== make gob! [offset: 0x0 size: 100x100 alpha: 0 draw: []]
>> to-draw [pen black fill-pen red circle 50x50 40] gob/draw
== [pen 0.0.0 fill-pen 255.0.0 circle 50x50 40x40]
>> view gob
Note that the specification block is not reduced and only valid field names are allowed (see list below.) You can also create a GOB from another GOB, inheriting its settings:
gob4: make gob1 [text: "Another example"]
Type | Description |
---|---|
color | An RGBA color to fill the specified area. |
image | An RGBA image. The size of the GOB is determined by the size of the image. |
draw | A block of scalar vector graphic (SVG) commands, such as line, box, and circle. |
effect | A block of special effect commands, such as blur or colorize, etc. |
text | A block of rich-text commands including special modes such as bold, italic, color, etc. |
Field | Datatype | Description |
---|---|---|
offset | pair! | the x-y coordinate relative to parent |
size | pair! | width and height of gob canvas or coordinate space |
pane | block! | a block of child gobs (see below) |
parent | gob! | the parent gob (in its pane) |
data | object! block! string! binary! integer! none! | normally used to reference data related to the gob, such as the VID face object |
flags | block! | special flags, see section below |
alpha | integer! | alpha transparency for the gob overall |
owner | gob! | a temporary field used for popup windows to specify the owning parent window |
agob/offset: 100x100
print agob/size
bgob: agob/parent
In addition, these fields are used to access the content of a GOB, depending on its type:
Field | Datatype | Description |
---|---|---|
color | tuple! | the color of the gob |
image | image! | an image within the gob |
draw | block! | a DRAW dialect block |
effect | block! | an EFFECT dialect block |
text | block! string! | a richtext dialect block |
agob/color: blue
agob/image: load %photo.jpg
Note that you can only specify one content field per GOB. If you attempt to set a second field, it overwrites the earlier one.
Spatial information about the GOB can be accessed with:Name | Description |
---|---|
offset | The x-y offset of the GOB relative to its parent. Either value (or both) can be negative and clipping will occur. |
size | The width and height of GOB content area. Any graphics that extends outside this area will be clipped. |
gob/offset: 100x20
print gob/offset
gob/size: 150x50
gob1: make gob! [size: 200x200 color: white]
gob2: make gob! [offset: 20x20 size: 40x30 color: red]
gob3: make gob! [offset: 120x80 size: 50x40 color: blue]
this line will add gob2 to the gob1 pane:
append gob1 gob2
view gob1
Or, you can add several GOBs at the same time:
append gob1 [gob2 gob3]
view gob1
Note that the block of words is not reduced, but words will be looked up.
You can use other series-like functions, such as getting the length:length? gob1
Or clearing the pane, or specific parts of the pane:
clear gob1
clear at gob1 2
You can also remove from the pane:
remove find gob1 gob2
As well as use indexing refinements:
gob1/1: gob4
gob1/2/image: new-image
Action | Description |
---|---|
append | Inserts a value at tail of series and returns the series at head. (Modifies) |
at | Returns the series at the specified index. |
back | Returns the series at its previous position. |
clear | Removes all values. For series, removes from current index to tail and returns tail. (Modifies) |
find | Finds a value in a series and returns the series at the start of it. |
head | Returns the series at its head. |
head? | Returns TRUE if a series is at its head. |
index? | Returns the index number of the current position in the series. |
insert | Inserts into a series and returns the series after the insert. (Modifies) |
length? | Returns the length of the series from the current position. |
next | Returns the series at its next position. |
past? | Returns TRUE if a series index is past its tail. |
pick | Returns the value at the specified position in a series. |
poke | Returns value after changing its data at the given index. (Modifies) |
remove | Removes value(s) from a series and returns after the remove. (Modifies) |
reverse | Reverses a series and similar types. (Modifies) |
skip | Returns the series forward or backward from the current position. |
tail | Returns the series at the position after the last value. |
tail? | Returns TRUE if empty, or for series, if index is at or beyond its tail. |
take | Copies and removes from series. (Typically, removes last GOB.) |
Function | Description |
---|---|
map-gob-offset | Translates a gob and offset to the deepest gob and offset in it, returned as a block: the gob and offset. Also supports the reverse operation: given a GOB and offset, provide the GOB and offset within its top-most GOB. |
map-event | Within an event datatype that has a GOB and offset position, modify the event by mapping to its terminal (lowest) GOB and offset. |
print system/view/screen-gob/size
== 1440x900
Each GOB within the screen-gob/pane is a window.
Note: See R3 View - Windowing System for more information about windows. Normally, windows are created by the view function. Internally, it creates a new GOB for the window. The offset provides the position of the window, and the size provides its width and height. If text is provided, it will become the window caption. (Window GOBs do not allow color, image, draw, or effect content types, only text for the caption.) For example, if you create a GOB:win: make gob! [text: "Test Window" offset: 100x100 size: 300x200]
You can use that for a window by calling view this way:
view/as-is win ; use the argument as the window itself
Or, you could open the window on screen with this:
append system/view/screen-gob win
show win
However, this method should be avoided. You should use the view function, which handles many other features.
Window GOBs accept these special flags:Flag | Description |
---|---|
dropable | allow drag and drop of files |
hidden | window is hidden |
modal | modal event handling (for requestors) |
no-border | do not draw window borders (or title) |
no-title | do not show window title |
on-top | keep window on top |
popup | a popup window (has owning parent window) |
resize | allow the window to be resized |
transparent | let the window be transparent |
win/flags: [resize dropable]
or during the MAKE with:
win: make gob! [size: 100x200 flags: [resize]]
You can obtain the flags block with:
probe win/flags
show gob1
Render gob1 as well as all sub-gobs in its pane, if it has one. If the GOB is already being displayed, it's display would be refreshed. This same function is true for window GOBs:
show win
renders all of the graphics in the window and redisplays it. The show function also allows a block of GOBs:
show [gob1 gob2 gob3]
As you can see, if the gobs are words, their values will be used. Here are a few important notes about rendering:
- Rendering order is first to last For GOB panes, each GOB is rendered in the order it appears in the pane, with each successive GOB on top of the others, with the last GOB on top.
- Background refresh When a GOB offset is moved relative to its parent GOB, or when it changes size, any background behind the GOB is re-rendered. (Internally a GOB stores its old-offset and old-size information for use in this process.)
- Optimized show If a gob appears more than once within a show block (and the panes of gobs in that block) the second case of the GOB will be ignored (an optimization).
- Delayed show If you are changing several GOBs during a single event, it is more efficient to keep a list of changes then render all the changes together with a single call to show. In the R3 GUI, this is done by defining a show-later that queues the requests to a block, then calls show-now to refresh the display.
- Images or colors may specify transparency. For example, an image with transparent rounded edges.
- The transparency of a GOB can be controlled with /alpha. This setting affects the entire GOB (and all subGOBs within it). The range is 0 to 255.
gob1: make gob! [size: 200x100 text: "Example of transapency"]
gob2: make gob! [size: 180x50]
gob2/image: load %logo.gif
gob2/alpha: 200
append gob1 gob2
view gob1
Rebol []
;-- Background image
gobb: make gob! [offset: 0x0]
gobb/image: load %rebol-3d.png
;-- Top image:
gobi: make gob! [offset: 10x10]
gobi/image: load %icon.png
;-- The window:
win: make gob! [] ;[text: "Test Window"]
win/size: gobb/size
append win gobb
append win gobi
view win