USING: accessors assocs cache colors combinators
combinators.short-circuit concurrency.promises continuations
destructors fry kernel literals math models namespaces opengl
-opengl.capabilities opengl.textures sequences strings ui.backend
-ui.gadgets ui.gadgets.tracks ui.gestures ui.pixel-formats
+opengl.capabilities opengl.gl opengl.textures sequences strings
+ui.backend ui.gadgets ui.gadgets.tracks ui.gestures ui.pixel-formats
ui.render ;
IN: ui.gadgets.worlds
GENERIC: draw-world* ( world -- )
M: world draw-world*
- check-extensions
- "1.0" require-gl-version
{
- [ init-gl ]
+ [ gl-draw-init ]
[ draw-gadget ]
[ text-handle>> [ purge-cache ] when* ]
[ images>> [ purge-cache ] when* ]
-USING: ui.gadgets ui.pens ui.gestures help.markup help.syntax
-kernel classes strings opengl opengl.gl models
-math.rectangles math colors ;
+USING: help.markup help.syntax math.rectangles models opengl.gl
+ui.gadgets ui.gadgets.worlds ui.gestures ui.pens ;
IN: ui.render
+HELP: clip
+{ $var-description "The current clipping rectangle." } ;
+
+HELP: draw-gadget*
+{ $values { "gadget" gadget } }
+{ $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." }
+{ $notes "This word should not be called directly. To force a gadget to redraw, call " { $link relayout-1 } "." } ;
+
HELP: gadget
{ $class-description "An object which displays itself on the screen and acts on user input gestures. Gadgets have the following slots:"
{ $list
{ { $snippet "pref-dim" } " - a cached value for " { $link pref-dim } "; do not read or write this slot directly." }
{ { $snippet "parent" } " - the gadget containing this one, or " { $link f } " if this gadget is not part of the visible gadget hierarchy." }
{ { $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 } "." }
+ { { $snippet "graft-state" } { "This two tuple represents the current graft state of the gadget and what its next state will become." } }
{ { $snippet "orientation" } " - an orientation specifier. This slot is used by layout gadgets." }
{ { $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." }
{ { $snippet "visible?" } " - a boolean indicating if the gadget should display and receive user input." }
{ $notes
"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 } "." } ;
-HELP: clip
-{ $var-description "The current clipping rectangle." } ;
-
-HELP: draw-gadget*
-{ $values { "gadget" gadget } }
-{ $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." }
-{ $notes "This word should not be called directly. To force a gadget to redraw, call " { $link relayout-1 } "." } ;
+HELP: gl-draw-init
+{ $values { "world" world } }
+{ $description "Does some OpenGL setup that is required each time the world is to be redrawn." } ;
ARTICLE: "ui-paint" "Customizing gadget appearance"
"The UI carries out the following steps when drawing a gadget:"
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: math.rectangles math.vectors namespaces kernel accessors
-assocs combinators sequences sets opengl opengl.gl colors
-colors.constants ui.gadgets ui.pens ;
+USING: accessors colors colors.constants combinators kernel
+math.rectangles math.vectors namespaces opengl opengl.capabilities
+opengl.gl opengl.textures sequences sets ui.gadgets ui.pens ;
IN: ui.render
SYMBOL: clip
: do-clip ( -- ) clip get flip-rect gl-set-clip ;
-: init-clip ( clip-rect -- )
+: init-clip ( gadget -- )
[
dim>>
[ { 0 1 } v* viewport-translation set ]
SLOT: background-color
-: init-gl ( world -- )
+: gl-init ( -- )
+ check-extensions "1.0" require-gl-version
GL_SMOOTH glShadeModel
- GL_SCISSOR_TEST glEnable
GL_BLEND glEnable
GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA glBlendFunc
GL_VERTEX_ARRAY glEnableClientState
GL_PACK_ALIGNMENT 1 glPixelStorei
- GL_UNPACK_ALIGNMENT 1 glPixelStorei
+ GL_UNPACK_ALIGNMENT 1 glPixelStorei ;
+
+: gl-draw-init ( world -- )
+ GL_SCISSOR_TEST glEnable
init-matrices
[ init-clip ]
[
{ $values { "gadget" gadget } { "?" boolean } }
{ $description "Sets and unsets fullscreen mode for the gadget's world." } ;
+HELP: set-up-window
+{ $values { "world" world } }
+{ $description "Initializes the window that shows the world." } ;
+
HELP: fullscreen?
{ $values { "gadget" gadget } { "?" boolean } }
{ $description "Queries the gadget's world to see if it is running in fullscreen mode." } ;
USING: accessors arrays assocs boxes classes.tuple
classes.tuple.parser combinators combinators.short-circuit
concurrency.flags concurrency.promises continuations deques
-destructors dlists fry init kernel lexer make math namespaces parser
-sequences sets strings threads ui.backend ui.gadgets
-ui.gadgets.private ui.gadgets.worlds ui.gestures vectors vocabs.parser
-words ;
+destructors dlists fry init io.streams.c kernel lexer make math
+namespaces parser sequences sets strings threads ui.backend ui.gadgets
+ui.gadgets.private ui.gadgets.worlds ui.gestures ui.render vectors
+vocabs.parser words ;
IN: ui
<PRIVATE
[ begin-world ]
[ resize-world ]
[ request-focus ]
- } cleave ;
+ } cleave gl-init ;
: clean-up-broken-window ( world -- )
[