mirror of
https://github.com/lxsang/Diya-API.git
synced 2025-03-12 18:42:48 +01:00
fix: tf global to local problem on 2D node, add LoadingBar widget, and refactor code
This commit is contained in:
parent
2e4c73f8cf
commit
f3ef0c1aa0
@ -52,8 +52,7 @@ Diya2DNode >> inner: aPoint [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Diya2DNode >> local: aPoint [
|
Diya2DNode >> local: aPoint [
|
||||||
^((aPoint - (0@0 applyTf: self tf) )/ scale)
|
^ self tf globalPointToLocal: aPoint
|
||||||
rotateBy: rotation about: 0@0.
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ Diya2DPrimShape >> borderWidth [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Diya2DPrimShape >> boundingBox [
|
Diya2DPrimShape >> boundingBox [
|
||||||
^ bbox applyTf: self tf.
|
^ self tf localBoundsToGlobal: bbox.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
|
43
Diya/DiyaDefaultTheme.class.st
Normal file
43
Diya/DiyaDefaultTheme.class.st
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
Class {
|
||||||
|
#name : #DiyaDefaultTheme,
|
||||||
|
#superclass : #DiyaStyleSheet,
|
||||||
|
#category : #'Diya-UIThemes'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : #define }
|
||||||
|
DiyaDefaultTheme >> defineGlobal [
|
||||||
|
self define: #global styles: {
|
||||||
|
#bgColor -> (Color r: 0.2118 g: 0.2118 b: 0.2118).
|
||||||
|
#color -> Color white.
|
||||||
|
#border -> 0.
|
||||||
|
#fontSize -> 18.
|
||||||
|
#fontFamily -> DiyaFontManager uniqueInstance defaultFamily.
|
||||||
|
#textIconFamily -> 'bootstrap-icons'.
|
||||||
|
#fontStyle -> DiyaFontManager uniqueInstance defaultStyle.
|
||||||
|
#borderColor -> Color transparent.
|
||||||
|
#xAlign -> #left.
|
||||||
|
#yAlign -> #middle.
|
||||||
|
#iconSize -> 24.
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #define }
|
||||||
|
DiyaDefaultTheme >> defineLoadingBar [
|
||||||
|
self define: #loadingBar styles: {
|
||||||
|
#bgColor -> Color red.
|
||||||
|
#border -> 1.
|
||||||
|
#borderColor -> Color white.
|
||||||
|
};
|
||||||
|
define: #loadingProgress styles: {
|
||||||
|
#bgColor -> Color white.
|
||||||
|
#border -> 0.
|
||||||
|
#fontSize -> 18.
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #initialization }
|
||||||
|
DiyaDefaultTheme >> initialize [
|
||||||
|
super initialize.
|
||||||
|
self defineGlobal.
|
||||||
|
self defineLoadingBar.
|
||||||
|
]
|
@ -74,7 +74,7 @@ DiyaExampleApp >> main [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaExampleApp >> setup [
|
DiyaExampleApp >> setup [
|
||||||
|node node1 img ell label icon button texture|
|
|node node1 img ell label icon button texture loading|
|
||||||
texture := DiyaImageTex new.
|
texture := DiyaImageTex new.
|
||||||
"DiyaRendererContext uniqueInstance assets
|
"DiyaRendererContext uniqueInstance assets
|
||||||
addAsset:
|
addAsset:
|
||||||
@ -120,10 +120,11 @@ DiyaExampleApp >> setup [
|
|||||||
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 120@300.
|
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 120@300.
|
||||||
ell scale: 1.2 @ 1.2.
|
ell scale: 1.2 @ 1.2.
|
||||||
ell styleName: #ell_view.
|
ell styleName: #ell_view.
|
||||||
|
ell rotation: 30.
|
||||||
ell textureNamed:'mrsang.png'.
|
ell textureNamed:'mrsang.png'.
|
||||||
ell addNode: (DiyaTimerNode timeout: 1000 / 6 do:[:n |
|
"ell addNode: (DiyaTimerNode timeout: 1000 / 6 do:[:n |
|
||||||
n parent rotation: n parent rotation + 10.
|
n parent rotation: n parent rotation + 10.
|
||||||
] ).
|
] )".
|
||||||
ell on: #(mousebuttondown fingerdown) do:[:e|
|
ell on: #(mousebuttondown fingerdown) do:[:e|
|
||||||
label txt: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString].
|
label txt: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString].
|
||||||
|
|
||||||
@ -144,6 +145,17 @@ DiyaExampleApp >> setup [
|
|||||||
button icon: icon "'mrsang.png'".
|
button icon: icon "'mrsang.png'".
|
||||||
"button rotation: Float pi / 2.0."
|
"button rotation: Float pi / 2.0."
|
||||||
button styleName: #button_view.
|
button styleName: #button_view.
|
||||||
|
|
||||||
|
loading := root addNode: (DiyaLoadingBar new) at: 240@550.
|
||||||
|
loading extent: 200 @ 20.
|
||||||
|
|
||||||
|
loading addNode: (DiyaTimerNode timeout: 2000 do:[:n |
|
||||||
|
|p|
|
||||||
|
p := (n parent percent + 10).
|
||||||
|
p > 100 ifTrue:[ p := 0].
|
||||||
|
n parent percent: p.
|
||||||
|
] ).
|
||||||
|
|
||||||
Transcript show: 'Application setup';cr.
|
Transcript show: 'Application setup';cr.
|
||||||
^ root
|
^ root
|
||||||
]
|
]
|
||||||
|
59
Diya/DiyaLoadingBar.class.st
Normal file
59
Diya/DiyaLoadingBar.class.st
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
Class {
|
||||||
|
#name : #DiyaLoadingBar,
|
||||||
|
#superclass : #DiyaWidget,
|
||||||
|
#instVars : [
|
||||||
|
'label',
|
||||||
|
'bar',
|
||||||
|
'progress',
|
||||||
|
'percent'
|
||||||
|
],
|
||||||
|
#category : #'Diya-Widgets'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaLoadingBar >> bar [
|
||||||
|
^ bar
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #initialization }
|
||||||
|
DiyaLoadingBar >> initialize [
|
||||||
|
super initialize.
|
||||||
|
bar := self addNode: (DiyaRectangle new).
|
||||||
|
progress := self addNode: (DiyaRectangle new).
|
||||||
|
bar styleName: #loadingBar.
|
||||||
|
progress styleName: #loadingProgress.
|
||||||
|
"label := self addNode: (DiyaLabel new).
|
||||||
|
label wordWrap: false."
|
||||||
|
percent := 0.
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaLoadingBar >> label [
|
||||||
|
^ label
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaLoadingBar >> percent [
|
||||||
|
^ percent
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaLoadingBar >> percent: anObject [
|
||||||
|
percent := anObject.
|
||||||
|
self setDirty.
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #processing }
|
||||||
|
DiyaLoadingBar >> process [
|
||||||
|
|border|
|
||||||
|
border := bar ? #border.
|
||||||
|
bar extent: self extent.
|
||||||
|
progress position: border@border.
|
||||||
|
progress extent: ((self percent) * (self extent x) / 100 -( border << 1)) @ (self extent y - (border << 1)).
|
||||||
|
"label extent: self extent."
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
DiyaLoadingBar >> progress [
|
||||||
|
^ progress
|
||||||
|
]
|
@ -11,7 +11,7 @@ DiyaMetaNode >> addNode: node at: pos [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaMetaNode >> boundingBox [
|
DiyaMetaNode >> boundingBox [
|
||||||
^ 0@0
|
^ Rectangle origin: 0@0 extent: 0@0
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #rendering }
|
{ #category : #rendering }
|
||||||
|
@ -42,23 +42,7 @@ DiyaPolygon >> points: anObject [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaPolygon >> process [
|
DiyaPolygon >> process [
|
||||||
bbox := self recFromPoints.
|
bbox := Rectangle encompassing: points.
|
||||||
self calculateVertices.
|
self calculateVertices.
|
||||||
^true
|
^true
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
|
||||||
DiyaPolygon >> recFromPoints [
|
|
||||||
|maxX maxY minX minY x y|
|
|
||||||
maxX := minX := (points at: 1) x.
|
|
||||||
maxY := minY := (points at: 1) y.
|
|
||||||
points do: [ :p|
|
|
||||||
x := p x.
|
|
||||||
y := p y.
|
|
||||||
maxX := maxX max: x.
|
|
||||||
maxY := maxY max: y.
|
|
||||||
minX := minX min: x.
|
|
||||||
minY := minY min: y.
|
|
||||||
].
|
|
||||||
^ Rectangle origin: minX@minY corner: maxX @ maxY
|
|
||||||
]
|
|
||||||
|
@ -5,7 +5,7 @@ Class {
|
|||||||
'parent',
|
'parent',
|
||||||
'style'
|
'style'
|
||||||
],
|
],
|
||||||
#category : #'Diya-Graphics'
|
#category : #'Diya-UIThemes'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -4,7 +4,7 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'stylesheet'
|
'stylesheet'
|
||||||
],
|
],
|
||||||
#category : #'Diya-Graphics'
|
#category : #'Diya-UIThemes'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #convenience }
|
{ #category : #convenience }
|
||||||
|
@ -5,7 +5,7 @@ Class {
|
|||||||
'themes',
|
'themes',
|
||||||
'currentThemeName'
|
'currentThemeName'
|
||||||
],
|
],
|
||||||
#category : #'Diya-Graphics'
|
#category : #'Diya-UIThemes'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #adding }
|
{ #category : #adding }
|
||||||
@ -37,21 +37,7 @@ DiyaUIThemesManager >> defaultTheme [
|
|||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
DiyaUIThemesManager >> defineDefaultTheme [
|
DiyaUIThemesManager >> defineDefaultTheme [
|
||||||
self addTheme: #default stylesheet: (DiyaStyleSheet new
|
self addTheme: #default stylesheet: DiyaDefaultTheme new.
|
||||||
define: #global styles: {
|
|
||||||
#bgColor -> (Color r: 0.2118 g: 0.2118 b: 0.2118).
|
|
||||||
#color -> Color white.
|
|
||||||
#border -> 0.
|
|
||||||
#fontSize -> 18.
|
|
||||||
#fontFamily -> DiyaFontManager uniqueInstance defaultFamily.
|
|
||||||
#textIconFamily -> 'bootstrap-icons'.
|
|
||||||
#fontStyle -> DiyaFontManager uniqueInstance defaultStyle.
|
|
||||||
#borderColor -> Color transparent.
|
|
||||||
#xAlign -> #left.
|
|
||||||
#yAlign -> #middle.
|
|
||||||
#iconSize -> 24.
|
|
||||||
}; yourself
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #initialization }
|
{ #category : #initialization }
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
Extension { #name : #Point }
|
Extension { #name : #Point }
|
||||||
|
|
||||||
{ #category : #'*Diya' }
|
|
||||||
Point >> applyTf: tf [
|
|
||||||
^ tf localPointToGlobal: self
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #'*Diya' }
|
{ #category : #'*Diya' }
|
||||||
Point >> asArray3F [
|
Point >> asArray3F [
|
||||||
^ self asArray3F: 1.0
|
^ self asArray3F: 1.0
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
Extension { #name : #Rectangle }
|
|
||||||
|
|
||||||
{ #category : #'*Diya' }
|
|
||||||
Rectangle >> applyTf: tf [
|
|
||||||
^ tf localBoundsToGlobal: self
|
|
||||||
]
|
|
Loading…
x
Reference in New Issue
Block a user