1
0
mirror of https://github.com/lxsang/Diya-API.git synced 2025-04-17 14:06:44 +02:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Dany LE
c249c2e381 Rework on Graphic styling 2022-08-07 20:43:16 +02:00
Dany LE
6d7ab2dcd6 Merge b8257f7011f36db6df2cc82f2bfd7b15f7cc502e 2022-08-07 18:17:07 +02:00
Dany LE
b8257f7011 refactory code 2022-08-07 18:15:57 +02:00
21 changed files with 283 additions and 273 deletions

View File

@ -45,7 +45,7 @@ Diya2DNode >> initialize [
vbuffer := nil. vbuffer := nil.
] ]
{ #category : #'as yet unclassified' } { #category : #accessing }
Diya2DNode >> inner: aPoint [ Diya2DNode >> inner: aPoint [
^ self boundingBox containsPoint: (self local: aPoint) ^ self boundingBox containsPoint: (self local: aPoint)
] ]
@ -57,7 +57,7 @@ Diya2DNode >> local: aPoint [
] ]
{ #category : #'as yet unclassified' } { #category : #accessing }
Diya2DNode >> recFromBuffer [ Diya2DNode >> recFromBuffer [
|maxX maxY minX minY x y| |maxX maxY minX minY x y|
maxX := minX := vbuffer at: 1. maxX := minX := vbuffer at: 1.

View File

@ -9,34 +9,9 @@ Class {
#category : #'Diya-Graphics' #category : #'Diya-Graphics'
} }
{ #category : #accessing }
Diya2DPrimShape >> bgColor [
^style get: #bgcolor
]
{ #category : #accessing }
Diya2DPrimShape >> bgColor: c [
^style set: #bgcolor value: c
]
{ #category : #accessing }
Diya2DPrimShape >> borderColor [
^style get: #borderColor
]
{ #category : #accessing }
Diya2DPrimShape >> borderColor: c [
style set: #borderColor value: c.
]
{ #category : #accessing } { #category : #accessing }
Diya2DPrimShape >> borderWidth [ Diya2DPrimShape >> borderWidth [
^style get: #border ^ self ? #border
]
{ #category : #accessing }
Diya2DPrimShape >> borderWidth: w [
style set: #border value: w.
] ]
{ #category : #accessing } { #category : #accessing }
@ -44,16 +19,6 @@ Diya2DPrimShape >> boundingBox [
^ bbox applyTf: self tf. ^ bbox applyTf: self tf.
] ]
{ #category : #accessing }
Diya2DPrimShape >> color [
^ self style get: #color.
]
{ #category : #accessing }
Diya2DPrimShape >> color: value [
^ self style set: #color value: value
]
{ #category : #initialization } { #category : #initialization }
Diya2DPrimShape >> draw [ Diya2DPrimShape >> draw [
vbuffer ifNil: [ ^self ]. vbuffer ifNil: [ ^self ].
@ -76,7 +41,7 @@ Diya2DPrimShape >> draw [
{ #category : #initialization } { #category : #initialization }
Diya2DPrimShape >> drawBorder [ Diya2DPrimShape >> drawBorder [
"Diya2DShader uniqueInstance use." "Diya2DShader uniqueInstance use."
shader setUniform: #u_color value: self borderColor asGL4FArray; shader setUniform: #u_color value: (self ? #borderColor) asGL4FArray;
setUniform: #u_texture_type value: 1. setUniform: #u_texture_type value: 1.
OpenGL OpenGL
lineWidth: self borderWidth. lineWidth: self borderWidth.
@ -108,7 +73,7 @@ Diya2DPrimShape >> initialize [
bbox := Rectangle origin: 0@0 corner: 0@0. bbox := Rectangle origin: 0@0 corner: 0@0.
] ]
{ #category : #'as yet unclassified' } { #category : #accessing }
Diya2DPrimShape >> inner: aPoint [ Diya2DPrimShape >> inner: aPoint [
bbox ifNil: [ ^false ]. bbox ifNil: [ ^false ].
^ bbox containsPoint: (self local: aPoint) ^ bbox containsPoint: (self local: aPoint)
@ -118,8 +83,8 @@ Diya2DPrimShape >> inner: aPoint [
Diya2DPrimShape >> setUpShader [ Diya2DPrimShape >> setUpShader [
super setUpShader. super setUpShader.
self shader self shader
setUniform: #u_color value: self color asGL4FArray; setUniform: #u_color value: (self ? #color) asGL4FArray;
setUniform: #u_bg_color value: self bgColor asGL4FArray; setUniform: #u_bg_color value: (self ? #bgColor) asGL4FArray;
setUniform: #u_texture_type value: setUniform: #u_texture_type value:
(self texture ifNil: [ 0 ] ifNotNil:[self texture format]). (self texture ifNil: [ 0 ] ifNotNil:[self texture format]).
] ]

View File

@ -19,9 +19,7 @@ DiyaApplicationLauncher >> appNode [
DiyaApplicationLauncher >> bindGlobalEvent [ DiyaApplicationLauncher >> bindGlobalEvent [
|pointer | |pointer |
pointer := root addNode: (DiyaCircle r: 10) at: 200@200. pointer := root addNode: (DiyaCircle r: 10) at: 200@200.
pointer color: Color orange. pointer styleName: #pointer.
pointer borderColor: Color red.
pointer borderWidth: 2.
root on: #keydown do:[:e| Transcript show: 'keydown...';cr. running := false.]. root on: #keydown do:[:e| Transcript show: 'keydown...';cr. running := false.].
root on: #quit do: [:e| running := false]. root on: #quit do: [:e| running := false].
root on: #(fingerdown fingermotion mousemotion) do:[:e| root on: #(fingerdown fingermotion mousemotion) do:[:e|
@ -80,11 +78,21 @@ DiyaApplicationLauncher >> running [
{ #category : #initialization } { #category : #initialization }
DiyaApplicationLauncher >> setup [ DiyaApplicationLauncher >> setup [
event := SDL_Event new. event := SDL_Event new.
DiyaUIThemesManager uniqueInstance currentTheme
define: #fps_text styles: {
#color -> Color red.
#fontSize -> 18.
#bgColor -> Color transparent.
};
define: #pointer styles: {
#borderColor -> Color red.
#bgColor -> Color orange.
#border -> 3
}.
root addNode: (Diya2DNode new) at: 0@0. root addNode: (Diya2DNode new) at: 0@0.
txtFPS := root addNode:(DiyaText data: '') at: ( self context resolution x - 80)@(self context resolution y - 40). txtFPS := root addNode:(DiyaText data: '') at: ( self context resolution x - 80)@(self context resolution y - 40).
txtFPS extent: 80@40. txtFPS extent: 80@40.
txtFPS fontSize: 18. txtFPS styleName: #fps_text.
txtFPS color: Color red.
self bindGlobalEvent. self bindGlobalEvent.
running := true. running := true.
self launch: self defaultApplication. self launch: self defaultApplication.

View File

@ -14,9 +14,9 @@ DiyaButton class >> text: string [
] ]
{ #category : #accessing } { #category : #accessing }
DiyaButton >> icon: id [ DiyaButton >> icon: ico [
label icon: id. label icon: ico.
label updateLayout. label setDirty.
] ]
{ #category : #accessing } { #category : #accessing }
@ -27,10 +27,6 @@ DiyaButton >> iconSize: size [
{ #category : #initialization } { #category : #initialization }
DiyaButton >> initialize [ DiyaButton >> initialize [
super initialize. super initialize.
style
set:#textAlign value: #center;
set:#textVAlign value: #middle;
set:#border value: 1.
rec := self addNode: (DiyaRectangle new). rec := self addNode: (DiyaRectangle new).
label := self addNode: (DiyaLabel new). label := self addNode: (DiyaLabel new).
label txt label txt
@ -48,8 +44,9 @@ DiyaButton >> text: string [
] ]
{ #category : #accessing } { #category : #accessing }
DiyaButton >> updateLayout [ DiyaButton >> update [
rec extent: self extent. rec extent: self extent.
label position: 0@0. label position: 0@0.
label extent: self extent. label extent: self extent.
^true
] ]

View File

@ -1,20 +0,0 @@
Class {
#name : #DiyaDefaultStyle,
#superclass : #DiyaNodeStyle,
#category : #'Diya-Graphics'
}
{ #category : #initialization }
DiyaDefaultStyle >> initialize [
super initialize.
self set: #bgcolor value:(Color r: 0.2118 g: 0.2118 b: 0.2118).
self set: #color value: Color white.
self set: #border value: 0.
self set: #fontSize value: 18.
self set: #fontFamily value: DiyaFontManager uniqueInstance defaultFamily.
self set: #fontStyle value: DiyaFontManager uniqueInstance defaultStyle.
self set: #borderColor value: (Color r: 0.051 g: 0.051 b: 0.051).
self set: #bgcolor2 value: (Color r: 0.1529 g: 0.1529 b: 0.1529).
self set: #textAlign value: #left.
self set: #textVAlign value: #top
]

View File

@ -67,7 +67,7 @@ DiyaEllipse >> rx [
{ #category : #accessing } { #category : #accessing }
DiyaEllipse >> rx: anObject [ DiyaEllipse >> rx: anObject [
rx := anObject. rx := anObject.
dirty := true. self setDirty
] ]
{ #category : #accessing } { #category : #accessing }
@ -78,15 +78,15 @@ DiyaEllipse >> ry [
{ #category : #accessing } { #category : #accessing }
DiyaEllipse >> ry: anObject [ DiyaEllipse >> ry: anObject [
ry := anObject. ry := anObject.
dirty := true self setDirty
] ]
{ #category : #initialization } { #category : #initialization }
DiyaEllipse >> setUpShader [ DiyaEllipse >> setUpShader [
super setUpShader. super setUpShader.
self shader self shader
setUniform: #u_border value: (style get: #border); setUniform: #u_border value: (self ? #border);
setUniform: #u_border_color value: (style get:#borderColor) asGL4FArray; setUniform: #u_border_color value: ( self ? #borderColor) asGL4FArray;
setUniform: #u_rx value: rx; setUniform: #u_rx value: rx;
setUniform: #u_ry value: ry. setUniform: #u_ry value: ry.
] ]

View File

@ -9,6 +9,51 @@ DiyaExampleApp >> cleanup [
] ]
{ #category : #accessing }
DiyaExampleApp >> defineStyleSheet [
DiyaUIThemesManager uniqueInstance currentTheme
define: #text_icon_1 styles: {
#color -> Color orange.
#fontSize -> 24.
#bgColor -> Color transparent.
};
define: #image_view styles: {
#color -> (Color r: 1.0 g:1.0 b:1.0 alpha:1.0 ).
#border -> 3.
#bgColor -> Color cyan.
#borderColor -> Color red
};
define: #text_view styles: {
#color -> Color green.
#fontSize -> 16.
#bgColor -> Color transparent.
#xAlign -> #center
};
define: #line_view styles: {
#color -> Color red.
#border -> 4
};
define: #ell_view styles: {
#borderColor -> Color red.
#color -> Color white.
#bgColor -> Color cyan.
#border -> 3.
};
define: #poly_view styles: {
#borderColor -> Color red.
#color -> Color green.
#border -> 3.
};
define: #button_view styles: {
#borderColor -> Color red.
#color -> Color white.
#bgColor -> Color magenta.
#border -> 1.
#yAlign -> #middle.
#xAlign -> #center
}
]
{ #category : #accessing } { #category : #accessing }
DiyaExampleApp >> main [ DiyaExampleApp >> main [
@ -17,10 +62,10 @@ DiyaExampleApp >> main [
{ #category : #accessing } { #category : #accessing }
DiyaExampleApp >> setup [ DiyaExampleApp >> setup [
|node node1 ell label icon button| |node node1 ell label icon button|
self defineStyleSheet.
label := root addNode: (DiyaLabel new) at: 10@40. label := root addNode: (DiyaLabel new) at: 10@40.
label extent: 250@24. label extent: 250@24.
label color: Color orange. label styleName:#text_icon_1.
label iconSize: 24.
label icon: 16rF254. label icon: 16rF254.
@ -31,53 +76,39 @@ DiyaExampleApp >> setup [
label txt: 'Mouse ', (node1 local: e mapped worldPosition) asIntegerPoint asString]. label txt: 'Mouse ', (node1 local: e mapped worldPosition) asIntegerPoint asString].
node := root addNode: (DiyaImageView from:'mrsang.png') at: 10 @ 400. node := root addNode: (DiyaImageView from:'mrsang.png') at: 10 @ 400.
node color: (Color r: 1.0 g:1.0 b:1.0 alpha:1.0 ). node styleName: #image_view.
node borderWidth:1.
node bgColor: Color cyan.
node borderColor: Color red.
node borderWidth: 3.0.
node extent:200@200. node extent:200@200.
node := root addNode: (DiyaRectangle new) at: 10@80. node := root addNode: (DiyaRectangle new) at: 10@80.
node borderWidth: 1. node styleName: #image_view.
node extent: 240@320. node extent: 240@320.
node := root addNode: (DiyaText data: String loremIpsum) at: 10@80. node := root addNode: (DiyaText data: String loremIpsum) at: 10@80.
node extent: 240@320. node extent: 240@320.
node wordWrap: true. node wordWrap: true.
node fontSize: 16. node styleName: #text_view.
node bgColor: Color transparent.
node align: #center.
node := root addNode: (DiyaLine from: 10@10 to: 200@200). node := root addNode: (DiyaLine from: 10@10 to: 200@200).
node color: (Color red). node styleName: #line_view.
node borderWidth: 2.0.
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 100@300. ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 100@300.
ell borderColor: Color red.
ell color: Color white.
ell bgColor: Color cyan.
ell rotation: Float pi / 6.0. ell rotation: Float pi / 6.0.
ell borderWidth: 3.0. ell styleName: #ell_view.
"node rotation: Float pi / 2.0." "node rotation: Float pi / 2.0."
ell textureNamed:'mrsang.png'. ell textureNamed:'mrsang.png'.
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].
node := root addNode: (DiyaConvexPolygon points:{250@100. 400@250. 450@80. 350@60}). node := root addNode: (DiyaConvexPolygon points:{250@100. 400@250. 450@80. 350@60}).
node color: Color green.
node borderColor: Color red.
node textureNamed: 'mrsang.png'. node textureNamed: 'mrsang.png'.
node borderWidth: 3.0. node styleName: #poly_view.
icon := root addNode: (DiyaFontIcon data: #(16rF101 16rF155 16rF185 16rF21B 16rF298 16rF254)) at: 240@500. icon := root addNode: (DiyaFontIcon data: #(16rF101 16rF155 16rF185 16rF21B 16rF298 16rF254)) at: 240@500.
icon fontSize: 24. icon styleName: #text_icon_1 .
icon bgColor: Color transparent.
icon color: (Color r: 209/255 g: 66/255 b:245/255 ).
button := root addNode: (DiyaButton text: 'Click me !') at: 240@460. button := root addNode: (DiyaButton text: 'Click me !') at: 240@460.
button extent: 200@40. button extent: 200@40.
button icon:16rF185"'mrsang.png'". button icon:"16rF185"'mrsang.png'.
button iconSize: 24. button styleName: #button_view.
^ root ^ root
] ]

View File

@ -10,7 +10,6 @@ Class {
{ #category : #initialization } { #category : #initialization }
DiyaFontIcon >> data: code [ DiyaFontIcon >> data: code [
super data:(code isArray ifTrue: [ code ] ifFalse:[{code}]). super data:(code isArray ifTrue: [ code ] ifFalse:[{code}]).
bbox := Rectangle origin: 0@0 corner: ((data size) * (self fontSize) ) @ self fontSize.
] ]
{ #category : #initialization } { #category : #initialization }
@ -31,11 +30,9 @@ DiyaFontIcon >> drawText [
] ]
{ #category : #initialization } { #category : #accessing }
DiyaFontIcon >> fontName: name style: face size: size [ DiyaFontIcon >> fontName [
super fontName: name style:face size: size. ^ self ? #textIconFamily
data ifNil: [ ^ self ].
bbox := Rectangle origin: 0@0 corner: ((data size) * size ) @ size.
] ]
{ #category : #initialization } { #category : #initialization }
@ -48,17 +45,10 @@ DiyaFontIcon >> iconSize [
^ self fontSize ^ self fontSize
] ]
{ #category : #accessing }
DiyaFontIcon >> iconSize: v [
"self extent: "
^ self fontSize: v
]
{ #category : #initialization } { #category : #initialization }
DiyaFontIcon >> initialize [ DiyaFontIcon >> initialize [
super initialize. super initialize.
data := { }. data := { }.
self fontName: 'bootstrap-icons' style: 'Regular' size: 16.
vbuffer := FFIExternalArray externalNewType: GLfloat size:24. vbuffer := FFIExternalArray externalNewType: GLfloat size:24.
vbuffer autoRelease. vbuffer autoRelease.
] ]
@ -67,3 +57,10 @@ DiyaFontIcon >> initialize [
DiyaFontIcon >> lastSeparatorFrom: i [ DiyaFontIcon >> lastSeparatorFrom: i [
self shouldNotBeCalled self shouldNotBeCalled
] ]
{ #category : #initialization }
DiyaFontIcon >> update [
data ifNil: [ ^self ].
bbox := Rectangle origin: 0@0 corner: ((data size) * (self fontSize) ) @ self fontSize.
^ super update.
]

View File

@ -5,17 +5,24 @@ Class {
} }
{ #category : #accessing } { #category : #accessing }
DiyaImageIcon >> iconSize [ DiyaImageIcon >> borderWidth [
^ self extent x ^0
] ]
{ #category : #accessing } { #category : #accessing }
DiyaImageIcon >> iconSize:v [ DiyaImageIcon >> iconSize [
^ self extent: v@v ^ self ? #iconSize
] ]
{ #category : #accessing } { #category : #accessing }
DiyaImageIcon >> initialize [ DiyaImageIcon >> initialize [
super initialize. super initialize.
style set: #border value: 0 ]
{ #category : #accessing }
DiyaImageIcon >> update [
|v|
v := self iconSize.
self extent: (v@v).
^super update
] ]

View File

@ -14,14 +14,6 @@ DiyaLabel >> fontSize [
] ]
{ #category : #accessing }
DiyaLabel >> fontSize: value [
txt fontSize: value.
"icon ifNotNil: [ icon fontSize: value ]."
"dirty := true."
]
{ #category : #accessing } { #category : #accessing }
DiyaLabel >> getHAlign: offset [ DiyaLabel >> getHAlign: offset [
^ 0 max: (txt alignLine: ( txt maxLineWidth)). ^ 0 max: (txt alignLine: ( txt maxLineWidth)).
@ -36,13 +28,12 @@ DiyaLabel >> icon [
DiyaLabel >> icon: anObject [ DiyaLabel >> icon: anObject [
icon := nil. icon := nil.
anObject isNumber ifTrue: [ anObject isNumber ifTrue: [
icon := self addNode: (DiyaFontIcon data: anObject). icon := self addNode: (DiyaFontIcon data: anObject).].
icon align: #left].
anObject isString ifTrue: [ anObject isString ifTrue: [
icon := self addNode: (DiyaImageIcon from: anObject). icon := self addNode: (DiyaImageIcon from: anObject).
]. ].
icon ifNil: [ ^ DiyaCoreAPIError signal: 'Invalid icon identification']. icon ifNil: [ ^ DiyaCoreAPIError signal: 'Invalid icon identification'].
dirty := true. self setDirty
] ]
{ #category : #accessing } { #category : #accessing }
@ -52,13 +43,6 @@ DiyaLabel >> iconSize [
] ]
{ #category : #accessing }
DiyaLabel >> iconSize: v [
icon ifNil: [ ^self ].
icon iconSize: v
]
{ #category : #initialization } { #category : #initialization }
DiyaLabel >> initialize [ DiyaLabel >> initialize [
super initialize. super initialize.
@ -75,11 +59,11 @@ DiyaLabel >> txt [
{ #category : #accessing } { #category : #accessing }
DiyaLabel >> txt: anObject [ DiyaLabel >> txt: anObject [
txt data: anObject. txt data: anObject.
dirty := true self setDirty
] ]
{ #category : #accessing } { #category : #accessing }
DiyaLabel >> updateLayout [ DiyaLabel >> update [
|offset isize align| |offset isize align|
offset := 0. offset := 0.
icon ifNotNil: [ icon ifNotNil: [
@ -96,5 +80,6 @@ DiyaLabel >> updateLayout [
icon ifNil: [ ^self ]. icon ifNil: [ ^self ].
"{ offset. txt extent. txt maxLineWidth. align } inspect." "{ offset. txt extent. txt maxLineWidth. align } inspect."
icon position: (align @( (self extent y - self iconSize ) >> 1)). icon position: (align @( (self extent y - self iconSize ) >> 1)).
^ true
] ]

View File

@ -62,7 +62,7 @@ DiyaLine >> from [
{ #category : #accessing } { #category : #accessing }
DiyaLine >> from: anObject [ DiyaLine >> from: anObject [
from := anObject. from := anObject.
dirty := true. self setDirty
] ]
{ #category : #initialization } { #category : #initialization }
@ -74,10 +74,9 @@ DiyaLine >> initialize [
vbuffer := FFIExternalArray externalNewType: GLfloat size:8. vbuffer := FFIExternalArray externalNewType: GLfloat size:8.
vbuffer autoRelease. vbuffer autoRelease.
type := GL_LINES. type := GL_LINES.
style set: #border value: 0
] ]
{ #category : #'as yet unclassified' } { #category : #accessing }
DiyaLine >> inner: aPoint [ DiyaLine >> inner: aPoint [
^false ^false
] ]
@ -90,7 +89,7 @@ DiyaLine >> to [
{ #category : #accessing } { #category : #accessing }
DiyaLine >> to: anObject [ DiyaLine >> to: anObject [
to := anObject. to := anObject.
dirty := true. self setDirty
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -13,7 +13,7 @@ Class {
'dirty', 'dirty',
'ehandlers', 'ehandlers',
'root', 'root',
'style', 'styleName',
'id' 'id'
], ],
#pools : [ #pools : [
@ -29,6 +29,20 @@ DiyaNode class >> with: shader [
^self new shader: shader; yourself ^self new shader: shader; yourself
] ]
{ #category : #accessing }
DiyaNode >> ? style [
| styles value|
styleName ifNotNil: [
styles := DiyaUIThemesManager uniqueInstance currentTheme ? (self styleName).
value := styles at: style ifAbsent:[nil].
value ifNotNil: [ ^value ].
].
"try to look at parent"
parent ifNil:[self styleNotFound: style].
"parent styleName = self styleName ifTrue: [self styleNotFound: style]."
^ parent ? style
]
{ #category : #accessing } { #category : #accessing }
DiyaNode >> addNode: node [ DiyaNode >> addNode: node [
^self addNode: node at: 0@0 ^self addNode: node at: 0@0
@ -41,7 +55,6 @@ DiyaNode >> addNode: node at: pos [
node position: pos. node position: pos.
children add: node. children add: node.
node root: self root. node root: self root.
node style parent: style.
^ node ^ node
] ]
@ -84,16 +97,21 @@ DiyaNode >> initialize [
children := OrderedCollection new. children := OrderedCollection new.
dirty := false. dirty := false.
ehandlers := Dictionary new. ehandlers := Dictionary new.
style := DiyaNodeStyle new. styleName := nil.
root := nil. root := nil.
id := Random new nextInt: 1e6 id := Random new nextInt: 1e6
] ]
{ #category : #'as yet unclassified' } { #category : #accessing }
DiyaNode >> inner: aPoint [ DiyaNode >> inner: aPoint [
^ self subclassResponsibility ^ self subclassResponsibility
] ]
{ #category : #testing }
DiyaNode >> isDirty [
^ dirty
]
{ #category : #testing } { #category : #testing }
DiyaNode >> isRoot [ DiyaNode >> isRoot [
^ false ^ false
@ -140,7 +158,7 @@ DiyaNode >> register: aBlock to: eventName [
DiyaNode >> render [ DiyaNode >> render [
dirty ifTrue:[ dirty ifTrue:[
dirty := self update not]. dirty := self update not].
shader ifNotNil: [ self setUpShader ]. shader ifNotNil: [self setUpShader].
self draw. self draw.
children ifNil: [ ^self ]. children ifNil: [ ^self ].
children do: [:c | c render ]. children do: [:c | c render ].
@ -178,6 +196,16 @@ DiyaNode >> scale: anObject [
self updateTF. self updateTF.
] ]
{ #category : #initialization }
DiyaNode >> setClean [
dirty := false
]
{ #category : #initialization }
DiyaNode >> setDirty [
dirty := true
]
{ #category : #accessing } { #category : #accessing }
DiyaNode >> setUpShader [ DiyaNode >> setUpShader [
|mem| |mem|
@ -211,15 +239,23 @@ DiyaNode >> shader: anObject [
] ]
{ #category : #accessing } { #category : #accessing }
DiyaNode >> style [ DiyaNode >> styleName [
^style ^ styleName
] ]
{ #category : #accessing } { #category : #accessing }
DiyaNode >> style: aStyle [ DiyaNode >> styleName: anObject [
style := aStyle. styleName := anObject.
dirty := true. self setDirty
parent ifNotNil: [ style parent: parent style ] ]
{ #category : #'event handling' }
DiyaNode >> styleNotFound: style [
"looking for default theme in global"
^(DiyaUIThemesManager uniqueInstance defaultTheme ? (self styleName))
at: style ifAbsent:[
DiyaCoreAPIError signal: 'Query undefined style ', style, ' in', styleName.
]
] ]
{ #category : #accessing } { #category : #accessing }
@ -227,7 +263,7 @@ DiyaNode >> tf [
^ tf ^ tf
] ]
{ #category : #'as yet unclassified' } { #category : #'event handling' }
DiyaNode >> trigger: evt [ DiyaNode >> trigger: evt [
evt enable ifFalse:[^self]. evt enable ifFalse:[^self].
ehandlers at: evt mapped type ifPresent:[:handler| handler value: evt]. ehandlers at: evt mapped type ifPresent:[:handler| handler value: evt].

View File

@ -1,45 +0,0 @@
Class {
#name : #DiyaNodeStyle,
#superclass : #DiyaBaseObject,
#instVars : [
'styles',
'parent'
],
#category : #'Diya-Graphics'
}
{ #category : #'as yet unclassified' }
DiyaNodeStyle class >> inherit: parent [
^self new parent: parent; yourself
]
{ #category : #initialization }
DiyaNodeStyle >> get: styleName [
^ styles at: styleName ifAbsent: [ parent ifNotNil: [ parent get: styleName ] ifNil: nil]
]
{ #category : #initialization }
DiyaNodeStyle >> initialize [
super initialize.
styles := Dictionary new.
parent := nil.
"self set: #bgcolor value: Color transparent.
self set: #color value:Color white.
self set: #border value: 0.
self set: #borderColor value: Color transparent."
]
{ #category : #accessing }
DiyaNodeStyle >> parent [
^ parent
]
{ #category : #accessing }
DiyaNodeStyle >> parent: anObject [
parent := anObject
]
{ #category : #initialization }
DiyaNodeStyle >> set: styleName value: value [
styles at: styleName put: value
]

View File

@ -37,7 +37,7 @@ DiyaPolygon >> points [
{ #category : #accessing } { #category : #accessing }
DiyaPolygon >> points: anObject [ DiyaPolygon >> points: anObject [
points := anObject. points := anObject.
dirty := true self setDirty
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -23,7 +23,7 @@ DiyaRectangle >> drawLines [
{ #category : #accessing } { #category : #accessing }
DiyaRectangle >> extent: v [ DiyaRectangle >> extent: v [
bbox := Rectangle origin:0@0 corner: v. bbox := Rectangle origin:0@0 corner: v.
dirty := true self setDirty
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -12,7 +12,7 @@ DiyaRootNode >> boundingBox [
{ #category : #accessing } { #category : #accessing }
DiyaRootNode >> draw [ DiyaRootNode >> draw [
|c| |c|
c := style get: #bgcolor. c := self ? #bgColor.
OpenGL clearColorR: c red G: c green B: c blue A: c alpha. OpenGL clearColorR: c red G: c green B: c blue A: c alpha.
OpenGL clear: GL_COLOR_BUFFER_BIT. OpenGL clear: GL_COLOR_BUFFER_BIT.
context vbo bind: GL_ARRAY_BUFFER. context vbo bind: GL_ARRAY_BUFFER.
@ -29,7 +29,7 @@ DiyaRootNode >> initialize [
parent := self. parent := self.
shader := nil. shader := nil.
root := self. root := self.
style := DiyaDefaultStyle new styleName := #global
] ]
{ #category : #'as yet unclassified' } { #category : #'as yet unclassified' }

View File

@ -0,0 +1,33 @@
Class {
#name : #DiyaStyleSheet,
#superclass : #DiyaBaseObject,
#instVars : [
'stylesheet'
],
#category : #'Diya-Graphics'
}
{ #category : #convenience }
DiyaStyleSheet >> ? sheet [
^stylesheet at: sheet ifAbsent:[
DiyaCoreAPIError signal: 'Unable to query stylesheet ', sheet
].
]
{ #category : #initialization }
DiyaStyleSheet >> define: name styles: styles [
stylesheet at: name put: styles asDictionary.
^self
]
{ #category : #initialization }
DiyaStyleSheet >> initialize [
super initialize.
stylesheet := Dictionary new.
]
{ #category : #accessing }
DiyaStyleSheet >> stylesheet [
^ stylesheet
]

View File

@ -1,5 +1,5 @@
Class { Class {
#name : #DiyaTableLayout, #name : #DiyaTableLayout,
#superclass : #DiyaWidget, #superclass : #DiyaLayout,
#category : #'Diya-Widgets' #category : #'Diya-Widgets'
} }

View File

@ -27,13 +27,7 @@ DiyaText class >> data: string shader: s [
{ #category : #'menu messages' } { #category : #'menu messages' }
DiyaText >> align [ DiyaText >> align [
^ self style get: #textAlign ^ self ? #xAlign
]
{ #category : #'menu messages' }
DiyaText >> align: v [
self style set: #textAlign value: v.
self formatText
] ]
{ #category : #accessing } { #category : #accessing }
@ -54,6 +48,11 @@ DiyaText >> allocMemory [
vbuffer autoRelease. vbuffer autoRelease.
] ]
{ #category : #accessing }
DiyaText >> borderWidth [
^0
]
{ #category : #accessing } { #category : #accessing }
DiyaText >> data [ DiyaText >> data [
^ data ^ data
@ -62,7 +61,7 @@ DiyaText >> data [
{ #category : #accessing } { #category : #accessing }
DiyaText >> data: anObject [ DiyaText >> data: anObject [
data := anObject. data := anObject.
dirty := true self setDirty
] ]
{ #category : #initialization } { #category : #initialization }
@ -84,36 +83,22 @@ DiyaText >> drawText [
{ #category : #accessing } { #category : #accessing }
DiyaText >> extent: v [ DiyaText >> extent: v [
bbox := Rectangle origin: 0@0 corner: (v x) @ (v y negated ). bbox := Rectangle origin: 0@0 corner: (v x) @ (v y negated ).
dirty := true self setDirty
] ]
{ #category : #accessing } { #category : #accessing }
DiyaText >> fontName [ DiyaText >> fontName [
^ self style get: #fontFamily ^ self ? #fontFamily
]
{ #category : #initialization }
DiyaText >> fontName: name style: face size: size [
name ifNotNil: [style set:#fontFamily value: name].
face ifNotNil: [style set: #fontStyle value:face].
style set: #fontSize value: size.
dirty := true.
self initTexture
] ]
{ #category : #accessing } { #category : #accessing }
DiyaText >> fontSize [ DiyaText >> fontSize [
^ self style get:#fontSize ^ self ? #fontSize
]
{ #category : #initialization }
DiyaText >> fontSize: size [
self fontName: nil style:nil size: size
] ]
{ #category : #accessing } { #category : #accessing }
DiyaText >> fontStyle [ DiyaText >> fontStyle [
^ self style get: #fontStyle ^ self ? #fontStyle
] ]
{ #category : #accessing } { #category : #accessing }
@ -187,8 +172,6 @@ DiyaText >> initialize [
data := nil. data := nil.
wrap := false. wrap := false.
texheight := 0. texheight := 0.
style set: #border value: 0.
"style set: #bgcolor value: Color red."
type := GL_QUADS. type := GL_QUADS.
maxLineWidth := 0. maxLineWidth := 0.
] ]
@ -237,7 +220,7 @@ DiyaText >> texture [
texheight = texture height ifFalse: [ texheight = texture height ifFalse: [
texheight := texture height. texheight := texture height.
self update. self update.
dirty := false. self setClean.
]. ].
^texture ^texture
] ]
@ -251,19 +234,12 @@ DiyaText >> update [
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16. vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
vbuffer autoRelease. vbuffer autoRelease.
self drawText. self drawText.
dirty := false.
^true ^true
] ]
{ #category : #'menu messages' } { #category : #'menu messages' }
DiyaText >> valign [ DiyaText >> valign [
^ self style get: #textVAlign ^ self ? #yAlign
]
{ #category : #'menu messages' }
DiyaText >> valign: v [
self style set: #textVAlign value: v.
self formatText.
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -0,0 +1,68 @@
Class {
#name : #DiyaUIThemesManager,
#superclass : #DiyaSingleton,
#instVars : [
'themes',
'currentThemeName'
],
#category : #'Diya-Graphics'
}
{ #category : #adding }
DiyaUIThemesManager >> addTheme:name stylesheet:sheet [
themes at:name put: sheet
]
{ #category : #accessing }
DiyaUIThemesManager >> currentTheme [
^ themes at: self currentThemeName ifAbsent: [
DiyaCoreAPIError signal: 'Undefined theme named', self currentThemeName
]
]
{ #category : #accessing }
DiyaUIThemesManager >> currentThemeName [
^ currentThemeName
]
{ #category : #accessing }
DiyaUIThemesManager >> currentThemeName: anObject [
currentThemeName := anObject
]
{ #category : #initialization }
DiyaUIThemesManager >> defaultTheme [
^ themes at: #default
]
{ #category : #initialization }
DiyaUIThemesManager >> defineDefaultTheme [
self addTheme: #default stylesheet: (DiyaStyleSheet 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.
}
)
]
{ #category : #initialization }
DiyaUIThemesManager >> initialize [
super initialize.
themes := Dictionary new.
self defineDefaultTheme.
self currentThemeName: #default.
]
{ #category : #accessing }
DiyaUIThemesManager >> themes [
^ themes
]

View File

@ -12,22 +12,6 @@ DiyaWidget class >> fromStyle: aStyle [
^self new style: aStyle; yourself ^self new style: aStyle; yourself
] ]
{ #category : #accessing }
DiyaWidget >> bgColor:v [
^style set: #bgcolor value: v
]
{ #category : #accessing }
DiyaWidget >> color [
^style get: #color
]
{ #category : #accessing }
DiyaWidget >> color: value [
style set: #color value: value
]
{ #category : #geometry } { #category : #geometry }
DiyaWidget >> extent [ DiyaWidget >> extent [
^extent ^extent
@ -36,21 +20,10 @@ DiyaWidget >> extent [
{ #category : #geometry } { #category : #geometry }
DiyaWidget >> extent: size [ DiyaWidget >> extent: size [
extent := size. extent := size.
dirty := true. self setDirty.
] ]
{ #category : #initialization } { #category : #initialization }
DiyaWidget >> initialize [ DiyaWidget >> initialize [
super initialize. super initialize.
] ]
{ #category : #accessing }
DiyaWidget >> update [
self updateLayout.
^ true
]
{ #category : #accessing }
DiyaWidget >> updateLayout [
self subclassResponsibility
]