Exposed simple rendering API (can at least render simple icons given a pict now)
Please merge into release
This commit is contained in:
parent
f45843d58e
commit
aa0851bc45
|
@ -14,10 +14,12 @@
|
||||||
plastic-icon-material
|
plastic-icon-material
|
||||||
glass-icon-material
|
glass-icon-material
|
||||||
metal-icon-material
|
metal-icon-material
|
||||||
|
bitmap-render-icon
|
||||||
(activate-contract-out
|
(activate-contract-out
|
||||||
default-icon-height
|
default-icon-height
|
||||||
toolbar-icon-height
|
toolbar-icon-height
|
||||||
default-icon-material)
|
default-icon-material
|
||||||
|
icon-color->outline-color)
|
||||||
(only-doc-out (all-defined-out)))
|
(only-doc-out (all-defined-out)))
|
||||||
|
|
||||||
(defthing light-metal-icon-color (or/c string? (is-a?/c color%)) #:document-value
|
(defthing light-metal-icon-color (or/c string? (is-a?/c color%)) #:document-value
|
||||||
|
@ -64,6 +66,23 @@
|
||||||
|
|
||||||
(defparam default-icon-material deep-flomap-material-value? plastic-icon-material)
|
(defparam default-icon-material deep-flomap-material-value? plastic-icon-material)
|
||||||
|
|
||||||
|
(defproc (bitmap-render-icon [bitmap (is-a?/c bitmap%)]
|
||||||
|
[z-ratio (and rational? (>=/c 0)) 5/8]
|
||||||
|
[material deep-flomap-material-value? (default-icon-material)]
|
||||||
|
) (is-a?/c bitmap%)
|
||||||
|
(let* ([fm (bitmap->flomap bitmap)]
|
||||||
|
[dfm (flomap->deep-flomap fm)]
|
||||||
|
[dfm (deep-flomap-icon-style dfm (* 32 z-ratio))])
|
||||||
|
(flomap->bitmap (deep-flomap-render-icon dfm material))))
|
||||||
|
|
||||||
|
(defproc (icon-color->outline-color [color (or/c string? (is-a?/c color%))]) (is-a?/c color%)
|
||||||
|
(cond [(string? color) (icon-color->outline-color (send the-color-database find-color color))]
|
||||||
|
[else
|
||||||
|
(define r (send color red))
|
||||||
|
(define g (send color green))
|
||||||
|
(define b (send color blue))
|
||||||
|
(make-object color% (quotient r 2) (quotient g 2) (quotient b 2))]))
|
||||||
|
|
||||||
;; ===================================================================================================
|
;; ===================================================================================================
|
||||||
;; Unpublished so far
|
;; Unpublished so far
|
||||||
|
|
||||||
|
@ -76,7 +95,6 @@
|
||||||
draw-short-rendered-icon-flomap
|
draw-short-rendered-icon-flomap
|
||||||
define-icon-wrappers
|
define-icon-wrappers
|
||||||
(activate-contract-out
|
(activate-contract-out
|
||||||
icon-color->outline-color
|
|
||||||
set-icon-pen))
|
set-icon-pen))
|
||||||
|
|
||||||
(defproc (set-icon-pen [dc (is-a?/c dc<%>)]
|
(defproc (set-icon-pen [dc (is-a?/c dc<%>)]
|
||||||
|
@ -85,14 +103,6 @@
|
||||||
[style symbol?]) void?
|
[style symbol?]) void?
|
||||||
(send dc set-pen (make-object pen% color width style 'projecting 'miter)))
|
(send dc set-pen (make-object pen% color width style 'projecting 'miter)))
|
||||||
|
|
||||||
(defproc (icon-color->outline-color [color (or/c string? (is-a?/c color%))]) (is-a?/c color%)
|
|
||||||
(cond [(string? color) (icon-color->outline-color (send the-color-database find-color color))]
|
|
||||||
[else
|
|
||||||
(define r (send color red))
|
|
||||||
(define g (send color green))
|
|
||||||
(define b (send color blue))
|
|
||||||
(make-object color% (quotient r 2) (quotient g 2) (quotient b 2))]))
|
|
||||||
|
|
||||||
(define icon-lighting
|
(define icon-lighting
|
||||||
(deep-flomap-lighting-value
|
(deep-flomap-lighting-value
|
||||||
'(0.0 -1.0 1.0)
|
'(0.0 -1.0 1.0)
|
||||||
|
@ -106,11 +116,11 @@
|
||||||
[deep-flomap-lighting icon-lighting])
|
[deep-flomap-lighting icon-lighting])
|
||||||
(deep-flomap-render dfm)))
|
(deep-flomap-render dfm)))
|
||||||
|
|
||||||
(define (deep-flomap-icon-style dfm)
|
(define (deep-flomap-icon-style dfm [height 20])
|
||||||
(define s (/ (deep-flomap-height dfm) 32))
|
(define s (/ (deep-flomap-height dfm) 32))
|
||||||
(let* ([dfm (deep-flomap-emboss dfm (* s 2) (* s 2))]
|
(let* ([dfm (deep-flomap-emboss dfm (* s 2) (* s 2))]
|
||||||
[dfm (deep-flomap-bulge-round dfm (* s 6))]
|
[dfm (deep-flomap-bulge-round dfm (* s 6))]
|
||||||
[dfm (deep-flomap-raise dfm (* s 20))])
|
[dfm (deep-flomap-raise dfm (* s height))])
|
||||||
dfm))
|
dfm))
|
||||||
|
|
||||||
(define (draw-icon-flomap w h draw-proc scale)
|
(define (draw-icon-flomap w h draw-proc scale)
|
||||||
|
@ -131,23 +141,16 @@
|
||||||
[fm (flomap-render-icon fm material)])
|
[fm (flomap-render-icon fm material)])
|
||||||
fm))
|
fm))
|
||||||
|
|
||||||
;; TODO: make one of the following functions unnecessary
|
|
||||||
|
|
||||||
(define (flomap-render-thin-icon fm material)
|
(define (flomap-render-thin-icon fm material)
|
||||||
(define scale (/ (flomap-height fm) 32))
|
(define scale (/ (flomap-height fm) 32))
|
||||||
(define dfm
|
(define dfm
|
||||||
(let* ([dfm (flomap->deep-flomap fm)]
|
(let* ([dfm (flomap->deep-flomap fm)]
|
||||||
[dfm (deep-flomap-icon-style dfm)]
|
[dfm (deep-flomap-icon-style dfm 8)])
|
||||||
[dfm (deep-flomap-raise dfm (* -12 scale))])
|
|
||||||
dfm))
|
dfm))
|
||||||
(deep-flomap-render-icon dfm material))
|
(deep-flomap-render-icon dfm material))
|
||||||
|
|
||||||
(define (draw-short-rendered-icon-flomap w h proc scale material)
|
(define (draw-short-rendered-icon-flomap w h proc scale material)
|
||||||
(let* ([fm (draw-icon-flomap w h proc scale)]
|
(flomap-render-thin-icon (draw-icon-flomap w h proc scale) material))
|
||||||
[dfm (flomap->deep-flomap fm)]
|
|
||||||
[dfm (deep-flomap-icon-style dfm)]
|
|
||||||
[dfm (deep-flomap-raise dfm (* -12 (/ (flomap-height fm) 32)))])
|
|
||||||
(deep-flomap-render-icon dfm material)))
|
|
||||||
|
|
||||||
;; ===================================================================================================
|
;; ===================================================================================================
|
||||||
;; Syntax for writing icon functions
|
;; Syntax for writing icon functions
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
@defmodule[images/compile-time]
|
@defmodule[images/compile-time]
|
||||||
|
|
||||||
Producing computed bitmaps can take time, especially those computed by the functions in the @racketmodname[images/icons] and @racketmodname[images/logos] collections.
|
Producing computed bitmaps can take time.
|
||||||
To reduce the startup time of programs that use computed bitmaps, use the macros exported by @racketmodname[images/compile-time] to @italic{compile} them: to embed the computed bitmaps in fully expanded, compiled modules.
|
To reduce the startup time of programs that use computed bitmaps, use the macros exported by @racketmodname[images/compile-time] to @italic{compile} them: to embed the computed bitmaps in fully expanded, compiled modules.
|
||||||
|
|
||||||
@margin-note*{This is a form of constant folding, or equivalently a form of @italic{safe} ``3D'' values.}
|
@margin-note*{This is a form of constant folding, or equivalently a form of @italic{safe} ``3D'' values.}
|
||||||
|
|
|
@ -158,7 +158,8 @@ This is because, while plastic and glass mostly reflect light directly, metal mo
|
||||||
(for/list ([material (list plastic-icon-material
|
(for/list ([material (list plastic-icon-material
|
||||||
glass-icon-material
|
glass-icon-material
|
||||||
metal-icon-material)])
|
metal-icon-material)])
|
||||||
(bomb-icon light-metal-icon-color dark-metal-icon-color 32 material))]
|
(bomb-icon light-metal-icon-color dark-metal-icon-color 32
|
||||||
|
material))]
|
||||||
}
|
}
|
||||||
|
|
||||||
@doc-apply[default-icon-material]{
|
@doc-apply[default-icon-material]{
|
||||||
|
@ -166,6 +167,42 @@ The material used for rendering most icons and icon parts.
|
||||||
There are exceptions; for example, the @racket[floppy-disk-icon] always renders the sliding cover in metal.
|
There are exceptions; for example, the @racket[floppy-disk-icon] always renders the sliding cover in metal.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@doc-apply[bitmap-render-icon]{
|
||||||
|
Makes a 3D object out of @racket[bitmap] and renders it as an icon.
|
||||||
|
|
||||||
|
The @racket[z-ratio] argument only makes a difference when @racket[material] is transparent, such as @racket[glass-icon-material].
|
||||||
|
It controls what fraction of @racket[bitmap]'s height the icon is raised, which in turn affects the refracted shadow under the icon:
|
||||||
|
the higher the @racket[z-ratio], the lower the shadow.
|
||||||
|
|
||||||
|
@examples[#:eval icons-eval
|
||||||
|
(define bitmap
|
||||||
|
(pict->bitmap (colorize (filled-ellipse 64 64) "tomato")))
|
||||||
|
(for/list ([z-ratio (in-range 0 2 1/3)])
|
||||||
|
(bitmap-render-icon bitmap z-ratio glass-icon-material))]
|
||||||
|
|
||||||
|
More complex shapes than ``embossed and rounded'' are possible with the full rendering API, which will be made public in a later release.
|
||||||
|
Still, most of the simple icons (such as those in @racketmodname[images/icons/arrow] and @racketmodname[images/icons/control]) can be rendered using only @racket[bitmap-render-icon].
|
||||||
|
}
|
||||||
|
|
||||||
|
@doc-apply[icon-color->outline-color]{
|
||||||
|
For a given icon color, returns the proper outline @racket[color%].
|
||||||
|
|
||||||
|
As an example, here is how to duplicate the @racket[record-icon] using @racketmodname[slideshow/pict]:
|
||||||
|
@interaction[#:eval icons-eval
|
||||||
|
(define outline-color (icon-color->outline-color "forestgreen"))
|
||||||
|
(define brush-pict (colorize (filled-ellipse 62 62) "forestgreen"))
|
||||||
|
(define pen-pict (linewidth 2 (colorize (ellipse 62 62) outline-color)))
|
||||||
|
(bitmap-render-icon
|
||||||
|
(pict->bitmap
|
||||||
|
(inset (cc-superimpose brush-pict pen-pict) 1))
|
||||||
|
5/8 glass-icon-material)
|
||||||
|
|
||||||
|
(record-icon "forestgreen" 64 glass-icon-material)]
|
||||||
|
|
||||||
|
The outline width is usually @racket[(/ height 32)] (in this case, @racket[2]), but not always.
|
||||||
|
(For example, @racket[recycle-icon] is an exception, as are parts of @racket[floppy-disk-icon].)
|
||||||
|
}
|
||||||
|
|
||||||
@;====================================================================================================
|
@;====================================================================================================
|
||||||
|
|
||||||
@section[#:tag "arrows"]{Arrow Icons}
|
@section[#:tag "arrows"]{Arrow Icons}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user