TIP: "You can write graphical applications using the " { $link "ui" } "." ;
TIP: "Power tools: " { $links see edit help about apropos time infer. } ;
-
+
+TIP: "Tips of the day implement the " { $link "definition-protocol" } " and new tips of the day can be defined using the " { $link POSTPONE: TIP: } " parsing word." ;
+
+HELP: TIP:
+{ $syntax "TIP: content ;" }
+{ $values { "content" "a markup element" } }
+{ $description "Defines a new tip of the day." } ;
+
ARTICLE: "all-tips-of-the-day" "All tips of the day"
{ $tips-of-the-day } ;
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: parser arrays namespaces sequences random help.markup kernel io
-io.styles colors.constants ;
+USING: parser arrays namespaces sequences random help.markup help.stylesheet
+kernel io io.styles colors.constants definitions accessors ;
IN: help.tips
SYMBOL: tips
tips [ V{ } clone ] initialize
-SYNTAX: TIP: parse-definition >array tips get push ;
+TUPLE: tip < identity-tuple content loc ;
+
+M: tip forget* tips get delq ;
+
+M: tip where loc>> ;
+
+M: tip set-where (>>loc) ;
+
+: <tip> ( content -- tip ) f tip boa ;
+
+: add-tip ( tip -- ) tips get push ;
+
+SYNTAX: TIP:
+ parse-definition >array <tip>
+ [ save-location ] [ add-tip ] bi ;
: a-tip ( -- tip ) tips get random ;
{ wrap-margin 500 }
} tip-of-the-day-style set-global
+: $tip-title ( tip -- )
+ [
+ heading-style get [
+ [ "Tip of the day" ] dip write-object
+ ] with-style
+ ] ($block) ;
+
: $tip-of-the-day ( element -- )
drop
[
tip-of-the-day-style get
[
last-element off
- "Tip of the day" $heading a-tip print-element nl
+ a-tip [ $tip-title ] [ content>> print-element nl ] bi
"— " print-element "all-tips-of-the-day" ($link)
]
with-nesting
: tip-of-the-day. ( -- ) { $tip-of-the-day } print-content nl ;
: $tips-of-the-day ( element -- )
- drop tips get [ nl nl ] [ print-element ] interleave ;
\ No newline at end of file
+ drop tips get [ nl nl ] [ content>> print-element ] interleave ;
+
+INSTANCE: tip definition
\ No newline at end of file
TUPLE: link name ;
+INSTANCE: link definition
+
MIXIN: topic
+
INSTANCE: link topic
+
INSTANCE: word topic
GENERIC: >link ( obj -- obj )
[ specializer-declaration ] map '[ _ declare ] pick append
] { } map>assoc ;
+: specialize-quot ( quot specializer -- quot' )
+ specializer-cases alist>quot ;
+
: method-declaration ( method -- quot )
[ "method-generic" word-prop dispatch# object <array> ]
[ "method-class" word-prop ]
bi prefix ;
: specialize-method ( quot method -- quot' )
- method-declaration '[ _ declare ] prepend ;
-
-: specialize-quot ( quot specializer -- quot' )
- specializer-cases alist>quot ;
+ [ method-declaration '[ _ declare ] prepend ]
+ [ "method-generic" word-prop "specializer" word-prop ] bi
+ [ specialize-quot ] when* ;
: standard-method? ( method -- ? )
dup method-body? [
: specialized-def ( word -- quot )
[ def>> ] keep
- [ dup standard-method? [ specialize-method ] [ drop ] if ]
- [ "specializer" word-prop [ specialize-quot ] when* ]
- bi ;
+ dup generic? [ drop ] [
+ [ dup standard-method? [ specialize-method ] [ drop ] if ]
+ [ "specializer" word-prop [ specialize-quot ] when* ]
+ bi
+ ] if ;
: specialized-length ( specializer -- n )
dup [ array? ] all? [ first ] when length ;
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel accessors grouping sequences combinators
-math specialized-arrays.direct.uint byte-arrays fry
-specialized-arrays.direct.ushort specialized-arrays.uint
-specialized-arrays.ushort specialized-arrays.float ;
+USING: combinators kernel ;
IN: images
-SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
+SINGLETONS: L BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
R16G16B16 R32G32B32 R16G16B16A16 R32G32B32A32 ;
: bytes-per-pixel ( component-order -- n )
{
+ { L [ 1 ] }
{ BGR [ 3 ] }
{ RGB [ 3 ] }
{ BGRA [ 4 ] }
: <image> ( -- image ) image new ; inline
-GENERIC: load-image* ( path tuple -- image )
-
-: add-dummy-alpha ( seq -- seq' )
- 3 <groups> [ 255 suffix ] map concat ;
-
-: normalize-floats ( byte-array -- byte-array )
- byte-array>float-array [ 255.0 * >integer ] B{ } map-as ;
-
-GENERIC: normalize-component-order* ( image component-order -- image )
-
-: normalize-component-order ( image -- image )
- dup component-order>> '[ _ normalize-component-order* ] change-bitmap ;
-
-M: RGBA normalize-component-order* drop ;
-
-M: R32G32B32A32 normalize-component-order*
- drop normalize-floats ;
-
-M: R32G32B32 normalize-component-order*
- drop normalize-floats add-dummy-alpha ;
-
-: RGB16>8 ( bitmap -- bitmap' )
- byte-array>ushort-array [ -8 shift ] B{ } map-as ; inline
-
-M: R16G16B16A16 normalize-component-order*
- drop RGB16>8 ;
-
-M: R16G16B16 normalize-component-order*
- drop RGB16>8 add-dummy-alpha ;
-
-: BGR>RGB ( bitmap -- pixels )
- 3 <sliced-groups> [ <reversed> ] map B{ } join ; inline
-
-: BGRA>RGBA ( bitmap -- pixels )
- 4 <sliced-groups>
- [ unclip-last-slice [ <reversed> ] dip suffix ] map concat ; inline
-
-M: BGRA normalize-component-order*
- drop BGRA>RGBA ;
-
-M: RGB normalize-component-order*
- drop add-dummy-alpha ;
-
-M: BGR normalize-component-order*
- drop BGR>RGB add-dummy-alpha ;
-
-: ARGB>RGBA ( bitmap -- bitmap' )
- 4 <groups> [ unclip suffix ] map B{ } join ; inline
-
-M: ARGB normalize-component-order*
- drop ARGB>RGBA ;
-
-M: ABGR normalize-component-order*
- drop ARGB>RGBA BGRA>RGBA ;
-
-: normalize-scan-line-order ( image -- image )
- dup upside-down?>> [
- dup dim>> first 4 * '[
- _ <groups> reverse concat
- ] change-bitmap
- f >>upside-down?
- ] when ;
-
-: normalize-image ( image -- image )
- [ >byte-array ] change-bitmap
- normalize-component-order
- normalize-scan-line-order
- RGBA >>component-order ;
+GENERIC: load-image* ( path tuple -- image )
\ No newline at end of file
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: constructors kernel splitting unicode.case combinators
-accessors images.bitmap images.tiff images io.backend
+accessors images.bitmap images.tiff images images.normalization
io.pathnames ;
IN: images.loader
--- /dev/null
+Doug Coleman
--- /dev/null
+! Copyright (C) 2009 Doug Coleman
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel accessors grouping sequences combinators
+math specialized-arrays.direct.uint byte-arrays fry
+specialized-arrays.direct.ushort specialized-arrays.uint
+specialized-arrays.ushort specialized-arrays.float images ;
+IN: images.normalization
+
+<PRIVATE
+
+: add-dummy-alpha ( seq -- seq' )
+ 3 <groups> [ 255 suffix ] map concat ;
+
+: normalize-floats ( byte-array -- byte-array )
+ byte-array>float-array [ 255.0 * >integer ] B{ } map-as ;
+
+GENERIC: normalize-component-order* ( image component-order -- image )
+
+: normalize-component-order ( image -- image )
+ dup component-order>> '[ _ normalize-component-order* ] change-bitmap ;
+
+M: RGBA normalize-component-order* drop ;
+
+M: R32G32B32A32 normalize-component-order*
+ drop normalize-floats ;
+
+M: R32G32B32 normalize-component-order*
+ drop normalize-floats add-dummy-alpha ;
+
+: RGB16>8 ( bitmap -- bitmap' )
+ byte-array>ushort-array [ -8 shift ] B{ } map-as ; inline
+
+M: R16G16B16A16 normalize-component-order*
+ drop RGB16>8 ;
+
+M: R16G16B16 normalize-component-order*
+ drop RGB16>8 add-dummy-alpha ;
+
+: BGR>RGB ( bitmap -- pixels )
+ 3 <sliced-groups> [ <reversed> ] map B{ } join ; inline
+
+: BGRA>RGBA ( bitmap -- pixels )
+ 4 <sliced-groups>
+ [ unclip-last-slice [ <reversed> ] dip suffix ] map concat ; inline
+
+M: BGRA normalize-component-order*
+ drop BGRA>RGBA ;
+
+M: RGB normalize-component-order*
+ drop add-dummy-alpha ;
+
+M: BGR normalize-component-order*
+ drop BGR>RGB add-dummy-alpha ;
+
+: ARGB>RGBA ( bitmap -- bitmap' )
+ 4 <groups> [ unclip suffix ] map B{ } join ; inline
+
+M: ARGB normalize-component-order*
+ drop ARGB>RGBA ;
+
+M: ABGR normalize-component-order*
+ drop ARGB>RGBA BGRA>RGBA ;
+
+: normalize-scan-line-order ( image -- image )
+ dup upside-down?>> [
+ dup dim>> first 4 * '[
+ _ <groups> reverse concat
+ ] change-bitmap
+ f >>upside-down?
+ ] when ;
+
+PRIVATE>
+
+: normalize-image ( image -- image )
+ [ >byte-array ] change-bitmap
+ normalize-component-order
+ normalize-scan-line-order
+ RGBA >>component-order ;
! flags
MACRO: flags ( values -- )
- [ 0 ] [ [ dup word? [ execute ] when bitor ] curry compose ] reduce ;
+ [ 0 ] [ [ ?execute bitor ] curry compose ] reduce ;
! bitfield
<PRIVATE
over glEnableClientState dip glDisableClientState ; inline
: words>values ( word/value-seq -- value-seq )
- [ dup word? [ execute ] when ] map ;
+ [ ?execute ] map ;
: (all-enabled) ( seq quot -- )
over [ glEnable ] each dip [ glDisable ] each ; inline
IN: specialized-vectors.tests
-USING: specialized-vectors.double tools.test kernel sequences ;
+USING: specialized-arrays.float
+specialized-vectors.float
+specialized-vectors.double
+tools.test kernel sequences ;
[ 3 ] [ double-vector{ 1 2 } 3 over push length ] unit-test
+[ t ] [ 10 float-array{ } new-resizable float-vector? ] unit-test
\ No newline at end of file
{ +listener+ t }
} define-operation
-UNION: definition word method-spec link vocab vocab-link ;
-
[ definition? ] \ edit H{
{ +keyboard+ T{ key-down f { C+ } "e" } }
{ +listener+ t }
: finish-table ( -- table )
table get [ [ 1 = ] map ] map ;
-: eval-seq ( seq -- seq ) [ dup word? [ execute ] when ] map ;
+: eval-seq ( seq -- seq ) [ ?execute ] map ;
: (set-table) ( class1 class2 val -- )
[ table get nth ] dip '[ _ or ] change-nth ;
USING: kernel sequences namespaces assocs graphs math math.order ;
IN: definitions
+MIXIN: definition
+
ERROR: no-compilation-unit definition ;
SYMBOLS: inlined-dependency flushed-dependency called-dependency ;
-! Copyright (C) 2006, 2008 Slava Pestov.
+! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors words kernel sequences namespaces make assocs
hashtables definitions kernel.private classes classes.private
PREDICATE: method-spec < pair
first2 generic? swap class? and ;
+INSTANCE: method-spec definition
+
: order ( generic -- seq )
"methods" word-prop keys sort-classes ;
GENERIC: execute ( word -- )
+GENERIC: ?execute ( word -- value )
+
+M: object ?execute ;
+
DEFER: if
: ? ( ? true false -- true/false )
{ $description "Defines a new generic word which dispatches on the " { $snippet "n" } "th most element from the top of the stack in the current vocabulary. Initially, it contains no methods, and thus will throw a " { $link no-method } " error when called." }
{ $notes
"The following two definitions are equivalent:"
- { $code "GENERIC: foo" }
- { $code "GENERIC# foo 0" }
+ { $code "GENERIC: foo ( obj -- )" }
+ { $code "GENERIC# foo 0 ( obj -- )" }
} ;
HELP: MATH:
: load-vocab ( name -- vocab ) load-vocab-hook get call( name -- vocab ) ;
PREDICATE: runnable-vocab < vocab
- vocab-main >boolean ;
\ No newline at end of file
+ vocab-main >boolean ;
+
+INSTANCE: vocab-spec definition
\ No newline at end of file
M: word execute (execute) ;
+M: word ?execute execute( -- value ) ;
+
M: word <=>
[ [ name>> ] [ vocabulary>> ] bi 2array ] compare ;
M: word literalize <wrapper> ;
: xref-words ( -- ) all-words [ xref ] each ;
+
+INSTANCE: word definition
\ No newline at end of file