123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- Object subclass: #CanvasRenderingContext
- instanceVariableNames: ''
- category: 'Canvas'!
- !CanvasRenderingContext methodsFor: 'drawing arcs'!
- arcTo: aPoint radius: aNumber startAngle: aNumber2 endAngle: aNumber3 anticlockwise: aBoolean
- <self.arc(aPoint._x(), aPoint._y(), aNumber, aNumber2, aNumber3, aBoolean)>
- !
- arcTo: aPoint radius: aNumber
- self arcTo: aPoint radius: aNumber startAngle: 0 endAngle: Number pi * 2 anticlockwise: false
- ! !
- !CanvasRenderingContext methodsFor: 'drawing paths'!
- fillStyle: aString
- <self.fillStyle = String(aString)>
- !
- beginPath
- <self.beginPath()>
- !
- closePath
- <self.closePath()>
- !
- fill
- <self.fill()>
- !
- stroke
- <self.stroke()>
- !
- moveTo: aPoint
- <self.moveTo(aPoint._x(), aPoint._y())>
- !
- lineTo: aPoint
- <self.lineTo(aPoint._x(), aPoint._y())>
- !
- strokeStyle: aString
- <self.strokeStyle = String(aString)>
- !
- lineWidth: aNumber
- <self.lineWidth = aNumber>
- ! !
- !CanvasRenderingContext methodsFor: 'drawing rectangles'!
- fillRectFrom: aPoint to: anotherPoint
- <self.fillRect(aPoint._x(), aPoint._y(), anotherPoint._x(), anotherPoint._y())>
- !
- strokeRectFrom: aPoint to: anotherPoint
- <self.strokeRect(aPoint._x(), aPoint._y(), anotherPoint._x(), anotherPoint._y())>
- !
- clearRectFrom: aPoint to: anotherPoint
- <self.fillRect(aPoint._x(), aPoint._y(), anotherPoint._x(), anotherPoint._y())>
- ! !
- !CanvasRenderingContext class methodsFor: 'instance creation'!
- tagBrush: aTagBrush
- <return aTagBrush._element().getContext('2d')>
- ! !
- Object subclass: #HTMLCanvas
- instanceVariableNames: 'root'
- category: 'Canvas'!
- !HTMLCanvas methodsFor: 'accessing'!
- root: aTagBrush
- root := aTagBrush
- !
- root
- ^root
- ! !
- !HTMLCanvas methodsFor: 'adding'!
- with: anObject
- ^self root with: anObject
- ! !
- !HTMLCanvas methodsFor: 'initialization'!
- initialize
- super initialize.
- root ifNil: [root := TagBrush fromString: 'div' canvas: self]
- !
- initializeFromJQuery: aJQuery
- root := TagBrush fromJQuery: aJQuery canvas: self
- ! !
- !HTMLCanvas methodsFor: 'tags'!
- newTag: aString
- ^TagBrush fromString: aString canvas: self
- !
- tag: aString
- ^root addBrush: (self newTag: aString)
- !
- h1
- ^self tag: 'h1'
- !
- h2
- ^self tag: 'h2'
- !
- h3
- ^self tag: 'h3'
- !
- h4
- ^self tag: 'h4'
- !
- h5
- ^self tag: 'h5'
- !
- h6
- ^self tag: 'h6'
- !
- p
- ^self tag: 'p'
- !
- div
- ^self tag: 'div'
- !
- span
- ^self tag: 'span'
- !
- img
- ^self tag: 'img'
- !
- ul
- ^self tag: 'ul'
- !
- ol
- ^self tag: 'ol'
- !
- li
- ^self tag: 'li'
- !
- table
- ^self tag: 'table'
- !
- tr
- ^self tag: 'tr'
- !
- td
- ^self tag: 'td'
- !
- th
- ^self tag: 'th'
- !
- form
- ^self tag: 'form'
- !
- input
- ^self tag: 'input'
- !
- button
- ^self tag: 'button'
- !
- select
- ^self tag: 'select'
- !
- option
- ^self tag: 'option'
- !
- textarea
- ^self tag: 'textarea'
- !
- a
- ^self tag: 'a'
- !
- canvas
- ^self tag: 'canvas'
- !
- pre
- ^self tag: 'pre'
- !
- code
- ^self tag: 'code'
- !
- br
- ^self tag: 'br'
- !
- script
- ^self tag: 'script'
- !
- link
- ^self tag: 'link'
- ! !
- !HTMLCanvas class methodsFor: 'instance creation'!
- onJQuery: aJQuery
- ^self basicNew
- initializeFromJQuery: aJQuery;
- initialize;
- yourself
- ! !
- Object subclass: #TagBrush
- instanceVariableNames: 'canvas element'
- category: 'Canvas'!
- !TagBrush methodsFor: 'accessing'!
- element
- ^element
- ! !
- !TagBrush methodsFor: 'adding'!
- contents: anObject
- self asJQuery empty.
- self append: anObject
- !
- addBrush: aTagBrush
- self appendChild: aTagBrush element.
- ^aTagBrush
- !
- with: anObject
- self append: anObject
- !
- append: anObject
- anObject appendToBrush: self
- !
- appendToBrush: aTagBrush
- aTagBrush addBrush: self
- !
- appendBlock: aBlock
- | root |
- root := canvas root.
- canvas root: self.
- aBlock value: canvas.
- canvas root: root
- !
- appendChild: anElement
- <self['@element'].appendChild(anElement)>
- !
- appendString: aString
- self appendChild: (self createTextNodeFor: aString)
- ! !
- !TagBrush methodsFor: 'attributes'!
- at: aString put: aValue
- <self['@element'].setAttribute(aString, aValue)>
- !
- removeAt: aString
- <self['@element'].removeAttribute(aString)>
- !
- class: aString
- self at: 'class' put: aString
- !
- id: aString
- self at: 'id' put: aString
- !
- src: aString
- self at: 'src' put: aString
- !
- href: aString
- self at: 'href' put: aString
- !
- title: aString
- self at: 'title' put: aString
- !
- style: aString
- self at: 'style' put: aString
- !
- type: aString
- self at: 'type' put: aString
- !
- media: aString
- self at: 'media' put: aString
- !
- rel: aString
- self at: 'rel' put: aString
- ! !
- !TagBrush methodsFor: 'converting'!
- asJQuery
- <return smalltalk.JQuery._from_(jQuery(self['@element']))>
- !
- asJQueryDo: aBlock
- aBlock value: self asJQuery
- ! !
- !TagBrush methodsFor: 'events'!
- onKeyDown: aBlock
- self asJQuery on: 'keydown' do: aBlock
- !
- onKeyPress: aBlock
- self asJQuery on: 'keypress' do: aBlock
- !
- onKeyUp: aBlock
- self asJQuery on: 'keyup' do: aBlock
- !
- onFocus: aBlock
- self asJQuery on: 'focus' do: aBlock
- !
- onBlur: aBlock
- self asJQuery on: 'blur' do: aBlock
- !
- onChange: aBlock
- self asJQuery on: 'change' do: aBlock
- !
- onClick: aBlock
- self asJQuery on: 'click' do: aBlock
- ! !
- !TagBrush methodsFor: 'initialization'!
- initializeFromString: aString canvas: aCanvas
- element := self createElementFor: aString.
- canvas := aCanvas
- !
- initializeFromJQuery: aJQuery canvas: aCanvas
- element := aJQuery jquery get: 0.
- canvas := aCanvas
- ! !
- !TagBrush methodsFor: 'private'!
- createElementFor: aString
- <return document.createElement(String(aString))>
- !
- createTextNodeFor: aString
- <return document.createTextNode(String(aString))>
- ! !
- !TagBrush class methodsFor: 'instance creation'!
- fromString: aString canvas: aCanvas
- ^self new
- initializeFromString: aString canvas: aCanvas;
- yourself
- !
- fromJQuery: aJQuery canvas: aCanvas
- ^self new
- initializeFromJQuery: aJQuery canvas: aCanvas;
- yourself
- ! !
- Object subclass: #Widget
- instanceVariableNames: ''
- category: 'Canvas'!
- !Widget methodsFor: 'actions'!
- alert: aString
- <alert(aString)>
- !
- confirm: aString
- <return window.confirm(aString)>
- !
- prompt: aString
- ^self prompt: aString default: ''
- !
- prompt: aString default: anotherString
- <return window.prompt(aString, anotherString)>
- ! !
- !Widget methodsFor: 'adding'!
- appendToBrush: aTagBrush
- self appendToJQuery: aTagBrush asJQuery
- !
- appendToJQuery: aJQuery
- self renderOn: (HTMLCanvas onJQuery: aJQuery)
- ! !
- !Widget methodsFor: 'rendering'!
- renderOn: html
- self
- ! !
- TagBrush subclass: #CanvasBrush
- instanceVariableNames: ''
- category: 'Canvas'!
- !CanvasBrush methodsFor: 'initialization'!
- initializeWithCanvas: aCanvas
- canvas := aCanvas
- ! !
- !CanvasBrush methodsFor: 'private'!
- createElement
- <return document.createElement('canvas')>
- ! !
- !CanvasBrush class methodsFor: 'instance creation'!
- canvas: aCanvas
- ^self new
- initializeWithCanvas: aCanvas;
- yourself
- ! !
- !Object methodsFor: '*Canvas'!
- appendToBrush: aTagBrush
- aTagBrush append: self asString
- ! !
- !BlockClosure methodsFor: '*Canvas'!
- appendToBrush: aTagBrush
- aTagBrush appendBlock: self
- ! !
- !String methodsFor: '*Canvas'!
- appendToBrush: aTagBrush
- aTagBrush appendString: self
- ! !
|