" Views.st -- the basic View hierarchy Copyright (c) 2007 Ian Piumarta All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. Last edited: 2007-09-18 20:12:44 by piumarta on emilia " { import: Object } { import: Colour } { import: Shape } "----------------------------------------------------------------" " A CompositeView is a logical grouping of an arbitray number of sibling views. The group as a whole can provide content for an arbitrary number of parent containers. " CompositeView : LinkedList ( properties "IdentityDictionary of properties" ) CompositeView printContentsOn: aStream [] _object asOop { _return((oop)((long)self << 1 | 1)); } CompositeView printOn: aStream [ super printOn: aStream. aStream nextPut: $-; print: self asOop ] "----------------------------------------------------------------" " A ComposableView can be combined with other views in a hierarchical fashion. (The structure is actually be a bipartite graph, somewhat more general than a simple tree-like hierarchy.) " ComposableView : Link ( contents "CompositeView of other views that provide my content" properties "IdentityDictionary of properties" surface "Platform dependent surface object (Window)" ) ComposableView withContents: contentsCollection [ self := super new. contents := contentsCollection ] ComposableView new [ ^self withContents: CompositeView new. ] ComposableView contents [ ^contents ] ComposableView surface [ ^surface ] ComposableView surface: aWindow [ surface := aWindow. contents do: [:each | each surface: aWindow] ] ComposableView add: aView [ self attach: aView. ^contents addLast: aView ] ComposableView addFirst: aView [ self attach: aView. ^contents addFirst: aView ] ComposableView addLast: aView [ self attach: aView. ^contents addLast: aView ] ComposableView add: aView before: bView [ self attach: aView. ^contents add: aView before: bView ] ComposableView add: aView after: bView [ self attach: aView. ^contents add: aView after: bView ] ComposableView removeFirst [ self detach: self first. ^contents removeFirst ] ComposableView removeLast [ self detach: self last. ^contents removeLast ] ComposableView remove: aView [ self detach: aView. ^contents remove: aView ] ComposableView attach: aView [ aView when: #onDamaged do: self >>> #damaged:. aView when: #onLayoutChanged do: self >>> #layoutChanged:. aView surface: surface. ] ComposableView detach: aView [ aView removeSignals: #onDamaged receiver: self. aView removeSignals: #onLayoutChanged receiver: self. ] ComposableView removeFrom: firstView to: lastView [ | next | [next := firstView nextLink. self remove: firstView. firstView ~~ lastView and: [firstView := next]] whileTrue ] ComposableView isEmpty [ ^contents isEmpty ] ComposableView notEmpty [ ^contents notEmpty ] ComposableView first [ ^contents first ] ComposableView last [ ^contents last ] ComposableView printOn: aStream [ super printOn: aStream. aStream nextPut: $-; print: self asOop ] "----------------------------------------------------------------" { import: Transform } " A TransformView modifies the coordinate system of its contents. " TransformView : ComposableView ( transform "Transform2D -- transforms my coordinate system into that of my inferior views" inverse "Transform2D -- the inverse of my transform (cached for speed)" ) TransformView withContents: aCompositeView [ self := super withContents: aCompositeView. inverse := transform := Transform2D withIdentity. ] TransformView isTransformView [ ^self ] Object isTransformView [ ^nil ] TransformView translation: aPair [ inverse := (transform := Transform2D withTranslation: aPair) inverted ] TransformView rotation: aNumber [ inverse := (transform := Transform2D withRotation: aNumber) inverted ] TransformView scaling: aPair [ inverse := (transform := Transform2D withScaling: aPair) inverted ] TransformView translateBy: aPair [ inverse := (transform translateBy: aPair) inverted ] TransformView rotateBy: aNumber [ inverse := (transform rotateBy: aNumber) inverted ] TransformView scaleBy: aPair [ inverse := (transform scaleBy: aPair) inverted ] ComposableView transformView [ ^TransformView new add: self; yourself ] CompositeView transformView [ ^TransformView withContents: self ] ComposableView translateBy: aPair [ ^self transformView translateBy: aPair ] ComposableView rotateBy: aPair [ ^self transformView rotateBy: aPair ] ComposableView scaleBy: aPair [ ^self transformView scaleBy: aPair ] CompositeView translateBy: aPair [ ^self transformView translateBy: aPair ] CompositeView rotateBy: aPair [ ^self transformView rotateBy: aPair ] CompositeView scaleBy: aPair [ ^self transformView scaleBy: aPair ] TransformView transform [ ^transform ] ComposableView transform [ ^Transform2D withIdentity ] "----------------------------------------------------------------" " A View is an abstract ComposableView having a shape that can be displayed and/or interacted with. Concrete Subtypes must implement #pathOn: and #bounds. " View : ComposableView ( fillColour "Colour that will fill my associated shape" strokeColour "Colour that will outline my associated shape" strokeWidth "Number measuring the width of my stroked outline" ) View fillColour: aColour [ fillColour := aColour ] View fillColour [ ^fillColour ] View strokeColour: aColour [ strokeColour := aColour ] View strokeColour [ ^strokeColour ] View strokeWidth: aNumber [ strokeWidth := aNumber ] View strokeWidth [ ^strokeWidth ] "----------------------------------------------------------------" " A ShapedView provides its displayable path via a Shape. " ShapedView : View ( shape "Shape of my displayable path" ) ShapedView isShapedView [ ^self ] Object isShapedView [ ^nil ] ShapedView withShape: aShape [ self := self new. shape := aShape. ] ShapedView shape [ ^shape ] ShapedView shape: aShape [ shape := aShape ] Shape shapedView [ ^ShapedView withShape: self ] ShapedView printOn: aStream [ super printOn: aStream. aStream nextPut: $(; print: shape; nextPut: $) ]