rebol [ Title: "AGG button style" File: %agg-button.r Date: 6-May-2007 Version: 1.0.5 Progress: 0.1 Status: "working on View versions >= 1.2.115, not fully implemented" Needs: [View] Author: "Anton Rolls" Language: "English" Purpose: {Reengineered button style} Usage: {} History: [ 1.0.0 [29-Nov-2006 {First version, incorporating code from button.r and view/draw/agg/rounded-button.r} "Anton"] 1.0.1 [7-Dec-2006 {reimplemented face/ghost? as a GHOSTED face flag, reimplemented rounded box using just BOX ... ROUNDED instead of a SHAPE of LINEs and ARCs, which also means the focal highlight box is now the same shape as the edge} "Anton"] 1.0.2 [2-Jan-2007 {patched to support older View versions < 2.7.4.3.1, which use ROUND instead of ROUNDED, moved setting effect block into WITH block to make that easier} "Anton"] 1.0.3 [20-Jan-2007 {added GHOSTABLE face flag} "Anton"] 1.0.4 [5-May-2007 {engage SHOWs parent-face when face/show? = false, like self-hider-btn} "Anton"] 1.0.5 [6-May-2007 {engage does not SHOW parent-face when face/show? = false} "Anton"] ] ToDo: { - text size sensitive resizing - min-size, max-size - this feeds back into resizing system - probably changing the "key-focus?" state to a "default-button?" state (see style-gallery.r) - also a face flag just like GHOSTED ? - the ghosted state affects the whole face (doesn't care that the corners are rounded). because it uses face/effect. It should be the same shape as the edge. - now, how to do that ? - restrict values of corner-radius and inner-gap. Since CORNER-RADIUS and INNER-GAP are now being referred to directly, there are no restrictions on their values. - the corner radius for the inner focal highlight would probably look better a bit smaller, but it's simpler to keep just using 'corner-radius as is... - name the colors and move to svvc (see patch/vid-colours.r) - up - down - down+working - ghosted colorization (?) - lots of other functionalities to check/implement - face/color - apply a "gradient colorization block" (of four tuples) to face/color to derive the final gradient colours ? - font/colors/2 - face/image - instead of completely skinning the button face as default BUTTON style does, how about just interpreting the image as a little icon, drawing it positioned at a small offset. - different outline shapes - See Henrik's cool buttons http://hmkdesign.dk/rebol/cool/cool-widgets.r } Notes: { In a patched CTX-TEXT, NEXT-FIELD and BACK-FIELD can check if any face is ghosted by checking for the GHOSTED face flag. The GHOST and UNGHOST functions (in ghost.r) check the face for the GHOSTABLE flag. All faces which implement their own ghosted state (via the GHOSTED flag), should also set the GHOSTABLE flag so that the GHOST/UNGHOST functions know not to interfere. } Public-Functions: [agg-button-style] ] context [ ; required by include framework agg-button-style: stylize [ agg-button: button 0.0.0.0 font [ size: 12 style: none color: black shadow: none colors: [0.0.0 255.180.75] ] with [ flags: [tabbed no-caret ghostable] ; TABBED: this face participates in tab-cycling ; NO-CARET: don't show caret when focused (see patch/focus-system-patch.r) ; GHOSTABLE: indicates to the old gui/ghost.r functions not to cover the face the old way ; GHOSTED: puts this face in a "ghosted", inactive state. (see patch/ctx-text-next-field-patch.r) ; custom facets corner-radius: 4 inner-gap: 4x4 ; gap between the edge and the key focus rectangle edge: none effect: [ merge draw [ fill-pen linear 0x0 0 30 90 1.0 1.0 240.240.240 200.200.200 200.200.200 1 line-width 1 pen coal ;shape [ ; line 10x0 70x0 arc 79x10 corner-radius corner-radius ; 1-7 ; line 79x20 arc 70x29 corner-radius corner-radius ; 8-13 ; line 10x29 arc 0x20 corner-radius corner-radius ; 14-19 ; line 0x10 arc 10x0 corner-radius corner-radius ; 20-25 ;] box 0x0 99x23 rounded corner-radius ; <- note ROUNDED is patched to ROUND for older View versions ] ] init: [ ; This code is from the original button init font/color: font/colors/1 if image [ if not effect [ effect: copy [fit] if color [append effect reduce ['colorize color depth]] if all [colors greater? length? colors 1 not effects] [ effects: compose/deep [ [fit colorize (first colors) (depth)] [fit colorize (second colors) (depth)] ] ] ] ] if not color [color: svvc/button] ] feel: make feel [ redraw: func [face action position /local state shape corner][ if all [face/texts face/texts/2] [ face/text: either face/state [face/texts/2] [face/texts/1] ] either face/images [ face/image: either face/state [face/images/2] [face/images/1] ] [ state: either not face/state [face/blinker] [true] if face/colors [face/color: pick face/colors not state] if face/effects [face/effect: pick face/effects not state] ] ;corner: min face/corner-radius (0.5 * min face/size/x face/size/y) change at face/effect/draw 9 either face/state [ either face/state = 'working [ ;[250.160.220 245.165.215 245.180.225 250.180.220] ; down, working (pink) [210.210.120 205.205.115 205.205.120 210.210.120] ; down, working (dull yellow) ][ [200.200.200 195.195.195 205.205.205 200.200.200] ; down ] ][ [230.230.230 240.240.240 230.230.230 220.220.220] ; up ] face/effect/draw/5: face/size/y ; gradient height ;shape: face/effect/draw/shape ;shape/2/x: shape/5/y: ;shape/6: shape/7: shape/12: shape/13: ;shape/18: shape/19: shape/24: shape/25: corner ;shape/5/x: shape/9/x: face/size/x - 1 ; initially 79 ;shape/11/y: shape/15/y: face/size/y - 1 ; initially 29 ;shape/3/x: shape/11/x: face/size/x - 1 - corner ; initially 70 ;shape/9/y: shape/17/y: face/size/y - 1 - corner ; initially 20 ;shape/15/x: shape/21/y: shape/23/x: corner change next find/tail face/effect/draw 'box face/size - 1x1 face/effect/draw/rounded: in face 'corner-radius ; <- note ROUNDED is patched to ROUND for older View versions face/effect/draw/line-width: either same? face system/view/focal-face [2.5][1] ; focal highlight ;clear skip find face/effect/draw 'shape 2 clear skip find face/effect/draw 'box 5 if all [ same? face system/view/focal-face ;key-focus? ][ append face/effect/draw compose/deep [ ; key-focused line-width 1 fill-pen none ; <- necessary, otherwise original fill is affected somehow (looks buggy) pen (any [all [in svvc 'focal-highlight svvc/focal-highlight] 0.50.190]) ; fall back to hard-coded colour ;0.50.190.104 ; <- since View 1.3.2, PEN with two colours causes crash (already in RAMBO) line-pattern 2 2 box (in face 'inner-gap) (face/size - 1x1 - face/inner-gap) rounded (in face 'corner-radius) ; <- note ROUNDED is patched to ROUND for older View versions ] ] clear skip find face/effect 'draw 2 if flag-face? face ghosted [ append face/effect [ ;emboss grayscale blur colorize 155.155.155 blur ] ] ] over: none engage: func [face action event][ if flag-face? face ghosted [exit] switch action [ time [if not face/state [face/blinker: not face/blinker]] down [face/state: on focus/no-show face] alt-down [face/state: on focus/no-show face] up [if face/state [do-face face face/text] face/state: off] alt-up [if face/state [do-face-alt face face/text] face/state: off] over [face/state: on] away [face/state: off] key [ switch event/key [ #"^-" [ ; tab focus either event/shift [ctx-text/back-field face][ctx-text/next-field face] ] #" " [ ; space face/state: on show face do-face face face/text face/state: off ; (SHOW FACE done below) ] #"^M" [ ; enter face/state: on show face do-face face face/text face/state: off ; (SHOW FACE done below) ] ] ] ] cue face action if face/show? [show face] ; in case face has hidden itself ] ] ; patch to support older VIEW versions, which use ROUND instead of ROUNDED if system/version < 2.7.4 [ change find effect/draw [rounded] [round] change at first find second get in feel 'redraw [face/effect/draw/rounded:] 4 [round] change find select second find/tail next find second get in feel 'redraw [if all][if all][compose/deep][rounded] [round] ] ;probe effect/draw ;probe get in feel 'redraw ] ] ] ; end of context