]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/render/render-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / ui / render / render-docs.factor
1 USING: ui.gadgets ui.gestures help.markup help.syntax
2 kernel classes strings opengl opengl.gl models
3 math.geometry.rect ;
4 IN: ui.render
5
6 HELP: gadget
7 { $class-description "An object which displays itself on the screen and acts on user input gestures. Gadgets have the following slots:"
8     { $list
9         { { $snippet "pref-dim" } " - a cached value for " { $link pref-dim } "; do not read or write this slot directly." }
10         { { $snippet "parent" } " - the gadget containing this one, or " { $link f } " if this gadget is not part of the visible gadget hierarchy." }
11         { { $snippet "children" } " - a vector of child gadgets. Do not modify this vector directly, instead use " { $link add-gadget } ", " { $link add-gadgets } ", " { $link unparent } " or " { $link clear-gadget } "." }
12         { { $snippet "orientation" } " - an orientation specifier. This slot is used by layout gadgets." }
13         { { $snippet "layout-state" } " - stores the layout state of the gadget. Do not read or write this slot directly, instead call " { $link relayout } " and " { $link relayout-1 } " if the gadget needs to be re-laid out." }
14         { { $snippet "visible?" } " - a boolean indicating if the gadget should display and receive user input." }
15         { { $snippet "root?" } " - if set to " { $link t } ", layout changes in this gadget will not propagate to the gadget's parent." }
16         { { $snippet "clipped?" } " - a boolean indicating if clipping will be enabled when drawing this gadget's children." }
17         { { $snippet "interior" } " - an object whose class implements the " { $link draw-interior } " generic word." }
18         { { $snippet "boundary" } " - an object whose class implements the " { $link draw-boundary } " generic word." }
19         { { $snippet "model" } " - a " { $link model } " or " { $link f } "; see " { $link "ui-control-impl" } }
20     }
21 "Gadgets subclass the " { $link rect } " class, and thus all instances have " { $snippet "loc" } " and " { $snippet "dim" } " instances holding their location and dimensions." }
22 { $notes
23 "Other classes may inherit from " { $link gadget } " in order to re-implement generic words such as " { $link draw-gadget* } " and " { $link user-input* } ", or to define gestures with " { $link set-gestures } "." } ;
24
25 HELP: clip
26 { $var-description "The current clipping rectangle." } ;
27
28 HELP: draw-gadget*
29 { $values { "gadget" gadget } } 
30 { $contract "Draws the gadget by making OpenGL calls. The top-left corner of the gadget should be drawn at the location stored in the " { $link origin } " variable." }
31 { $notes "This word should not be called directly. To force a gadget to redraw, call " { $link relayout-1 } "." } ;
32
33 HELP: draw-interior
34 { $values { "interior" object } { "gadget" gadget } } 
35 { $contract "Draws the interior of a gadget by making OpenGL calls. The " { $snippet "interior" } " slot may be set to objects implementing this generic word." } ;
36
37 HELP: draw-boundary
38 { $values { "boundary" object } { "gadget" gadget } } 
39 { $contract "Draws the boundary of a gadget by making OpenGL calls. The " { $snippet "boundary" } " slot may be set to objects implementing this generic word." } ;
40
41 HELP: solid
42 { $class-description "A class implementing the " { $link draw-boundary } " and " { $link draw-interior } " generic words to draw a solid outline or a solid fill, respectively. The " { $snippet "color" } " slot stores a color specifier." } ;
43
44 HELP: gradient
45 { $class-description "A class implementing the " { $link draw-interior } " generic word to draw a smoothly shaded transition between colors. The " { $snippet "colors" } " slot stores a sequence of color specifiers and the gradient is drawn in the direction given by the " { $snippet "orientation" } " slot of the gadget." } ;
46
47 HELP: polygon
48 { $class-description "A class implementing the " { $link draw-boundary } " and " { $link draw-interior } " generic words to draw a solid outline or a solid filled polygon, respectively. Instances of " { $link polygon } " have two slots:"
49     { $list
50         { { $snippet "color" } " - a color specifier" }
51         { { $snippet "points" } " - a sequence of points" }
52     }
53 } ;
54
55 HELP: <polygon>
56 { $values { "color" "a color specifier" } { "points" "a sequence of points" } { "polygon" polygon } }
57 { $description "Creates a new instance of " { $link polygon } "." } ;
58
59 HELP: <polygon-gadget>
60 { $values { "color" "a color specifier" } { "points" "a sequence of points" } { "gadget" "a new " { $link gadget } } }
61 { $description "Creates a gadget which is drawn as a solid filled polygon. The gadget's size is the minimum bounding box containing all the points of the polygon." } ;
62
63 HELP: open-font
64 { $values { "font" "a font specifier" } { "open-font" object } }
65 { $description "Loads a font if it has not already been loaded, otherwise outputs the existing font." }
66 { $errors "Throws an error if the font does not exist." } ;
67
68 HELP: string-width
69 { $values { "open-font" "a value output by " { $link open-font } } { "string" string } { "w" "a positive integer" } }
70 { $description "Outputs the width of a string." } ;
71
72 HELP: text-dim
73 { $values { "open-font" "a value output by " { $link open-font } } { "text" "a string or an array of strings" } { "dim" "a pair of integers" } }
74 { $description "Outputs the dimensions of a piece of text, which is either a single-line string or an array of lines." } ;
75
76 HELP: draw-string
77 { $values { "font" "a font specifier" } { "string" string } { "loc" "a pair of integers" } }
78 { $description "Draws a line of text." } ;
79
80 HELP: draw-text
81 { $values { "font" "a font specifier" } { "text" "a string or an array of strings" } { "loc" "a pair of integers" } }
82 { $description "Draws text. Text is either a single-line string or an array of lines." } ;
83
84 ARTICLE: "gadgets-polygons" "Polygon gadgets"
85 "A polygon gadget renders a simple shaded polygon."
86 { $subsection <polygon-gadget> }
87 "Some pre-made polygons:"
88 { $subsection arrow-up }
89 { $subsection arrow-right }
90 { $subsection arrow-down }
91 { $subsection arrow-left }
92 { $subsection close-box }
93 "Polygon gadgets are rendered by the " { $link polygon } " pen protocol implementation." ;
94
95 ARTICLE: "ui-paint" "Customizing gadget appearance"
96 "The UI carries out the following steps when drawing a gadget:"
97 { $list
98     { "The " { $link draw-interior } " generic word is called on the value of the " { $snippet "interior" } " slot." }
99     { "The " { $link draw-gadget* } " generic word is called on the gadget." }
100     { "The gadget's visible children are drawn, determined by calling " { $link visible-children } " on the gadget." }
101     { "The " { $link draw-boundary } " generic word is called on the value of the " { $snippet "boundary" } " slot." }
102 }
103 "Now, each one of these steps will be covered in detail."
104 { $subsection "ui-pen-protocol" }
105 { $subsection "ui-paint-custom" } ;
106
107 ARTICLE: "ui-pen-protocol" "UI pen protocol"
108 "The " { $snippet "interior" } " and " { $snippet "boundary" } " slots of a gadget facilitate easy factoring and sharing of drawing logic. Objects stored in these slots must implement the pen protocol:"
109 { $subsection draw-interior }
110 { $subsection draw-boundary }
111 "The default value of these slots is the " { $link f } " singleton, which implements the above protocol by doing nothing."
112 $nl
113 "Some other pre-defined implementations:"
114 { $subsection solid }
115 { $subsection gradient }
116 { $subsection polygon }
117 "Custom implementations must follow the guidelines set forth in " { $link "ui-paint-custom" } "." ;
118
119 ARTICLE: "text-rendering" "Rendering text"
120 "Unlike OpenGL, Factor's FreeType binding only includes the bare essentials, and there is rarely any need to directly call words in the " { $vocab-link "freetype" } " vocabulary directly. Instead, the UI provides high-level wrappers."
121 $nl
122 "Font objects are never constructed directly, and instead are obtained by calling a word:"
123 { $subsection open-font }
124 "Measuring text:"
125 { $subsection text-dim }
126 { $subsection text-height }
127 { $subsection text-width }
128 "Rendering text:"
129 { $subsection draw-string }
130 { $subsection draw-text } ;
131
132 ARTICLE: "ui-paint-coord" "The UI co-ordinate system"
133 "The UI uses a co-ordinate system where the y axis is oriented down. The OpenGL " { $link GL_MODELVIEW } " matrix is not saved or restored when rendering a gadget. Instead, the origin of the gadget relative to the OpenGL context is stored in a variable:"
134 { $subsection origin }
135 "Custom drawing implementations can translate co-ordinates manually, or save and restore the " { $link GL_MODELVIEW } " matrix using a word such as " { $link with-translation } "."
136 $nl
137 "Gadgets must not draw outside of their bounding box, however clipping is not enforced by default, for performance reasons. This can be changed by setting the " { $slot "clipped?" } " slot to " { $link t } " in the gadget's constructor." ;
138
139 ABOUT: "ui-paint-custom"