2022-03-01 22:58:58 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaText,
|
2022-03-19 02:18:29 +01:00
|
|
|
#superclass : #Diya2DPrimShape,
|
2022-03-01 22:58:58 +01:00
|
|
|
#instVars : [
|
2022-03-04 20:28:38 +01:00
|
|
|
'data',
|
2022-03-19 02:18:29 +01:00
|
|
|
'wrap',
|
2022-03-23 00:52:15 +01:00
|
|
|
'texheight',
|
2022-03-24 22:48:41 +01:00
|
|
|
'font',
|
2022-08-06 03:11:36 +02:00
|
|
|
'lines',
|
|
|
|
'maxLineWidth'
|
2022-03-01 22:58:58 +01:00
|
|
|
],
|
2022-03-03 19:19:40 +01:00
|
|
|
#pools : [
|
|
|
|
'FT2Types'
|
|
|
|
],
|
2022-03-01 22:58:58 +01:00
|
|
|
#category : #'Diya-Graphics'
|
|
|
|
}
|
|
|
|
|
2022-03-03 19:19:40 +01:00
|
|
|
{ #category : #'as yet unclassified' }
|
|
|
|
DiyaText class >> data: string [
|
|
|
|
^ (self new) data: string; yourself
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'as yet unclassified' }
|
|
|
|
DiyaText class >> data: string shader: s [
|
|
|
|
^ (self with:s) data: string; yourself
|
|
|
|
]
|
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #'menu messages' }
|
|
|
|
DiyaText >> align [
|
2022-08-07 20:43:16 +02:00
|
|
|
^ self ? #xAlign
|
2022-03-24 22:48:41 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> alignLine:w [
|
|
|
|
self align = #center ifTrue:[^ 0 max:((self extent x - w) / 2.0 ) asFloat].
|
|
|
|
self align = #right ifTrue:[^ 0 max: self extent x - w].
|
|
|
|
^0
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> allocMemory [
|
|
|
|
vbuffer ifNotNil: [
|
|
|
|
vbuffer size >= data size
|
|
|
|
ifTrue: [^self]
|
|
|
|
ifFalse:[vbuffer free]
|
|
|
|
].
|
|
|
|
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
|
|
|
|
vbuffer autoRelease.
|
|
|
|
]
|
|
|
|
|
2022-08-07 20:43:16 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> borderWidth [
|
|
|
|
^0
|
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> data [
|
|
|
|
^ data
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> data: anObject [
|
2022-03-06 19:50:19 +01:00
|
|
|
data := anObject.
|
2022-08-07 20:43:16 +02:00
|
|
|
self setDirty
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
2022-03-19 02:18:29 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> drawBorder [
|
2022-03-21 01:45:21 +01:00
|
|
|
self shouldNotBeCalled
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> drawLines [
|
|
|
|
^ self shouldNotBeCalled
|
2022-03-03 19:19:40 +01:00
|
|
|
]
|
|
|
|
|
2022-03-06 12:07:20 +01:00
|
|
|
{ #category : #accessing }
|
2022-03-06 19:50:19 +01:00
|
|
|
DiyaText >> drawText [
|
2022-03-24 22:48:41 +01:00
|
|
|
self splitLines.
|
|
|
|
self formatText .
|
2022-03-03 19:19:40 +01:00
|
|
|
]
|
|
|
|
|
2022-03-16 01:32:01 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> extent: v [
|
2022-03-16 21:33:35 +01:00
|
|
|
bbox := Rectangle origin: 0@0 corner: (v x) @ (v y negated ).
|
2022-08-07 20:43:16 +02:00
|
|
|
self setDirty
|
2022-03-16 01:32:01 +01:00
|
|
|
]
|
|
|
|
|
2022-03-03 19:19:40 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> fontName [
|
2022-08-07 20:43:16 +02:00
|
|
|
^ self ? #fontFamily
|
2022-03-03 19:19:40 +01:00
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> fontSize [
|
2022-08-07 20:43:16 +02:00
|
|
|
^ self ? #fontSize
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> fontStyle [
|
2022-08-07 20:43:16 +02:00
|
|
|
^ self ? #fontStyle
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
|
|
|
|
2022-08-12 16:37:53 +02:00
|
|
|
{ #category : #'text-processing' }
|
2022-03-24 22:48:41 +01:00
|
|
|
DiyaText >> formatText [
|
|
|
|
|offset index line|
|
|
|
|
lines ifNil: [^self].
|
|
|
|
offset := 0@(self valignText: (texture linespace) * (lines size)).
|
|
|
|
index := 1.
|
|
|
|
lines do:[:assoc|
|
|
|
|
line := assoc value.
|
|
|
|
offset setX: (self alignLine: assoc key) setY: offset y.
|
|
|
|
line do:[:g|
|
|
|
|
(self getCharsVerticesFrom: g offset: offset cellh: texture cellh) do:[:v|
|
|
|
|
vbuffer at: index put:v.
|
|
|
|
index := index + 1.
|
|
|
|
]
|
|
|
|
].
|
2022-08-06 03:11:36 +02:00
|
|
|
offset setX: 0.0 setY: (offset y ) + (texture linespace)
|
2022-03-06 19:50:19 +01:00
|
|
|
].
|
2022-03-24 22:48:41 +01:00
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> getCharsVerticesFrom:glyph offset: offset cellh: cellh [
|
|
|
|
|x y w h gsize texcoord|
|
|
|
|
gsize := glyph extent.
|
2022-03-06 18:33:10 +01:00
|
|
|
x := offset x + (glyph bearing x).
|
2022-08-06 03:11:36 +02:00
|
|
|
y := offset y "- cellh".
|
2022-03-06 18:33:10 +01:00
|
|
|
w := (gsize x).
|
|
|
|
h := (gsize y).
|
2022-03-17 00:32:19 +01:00
|
|
|
texcoord := glyph texcoord.
|
2022-03-06 18:33:10 +01:00
|
|
|
offset setX: (offset x + (glyph advance x)) setY: offset y.
|
2022-08-06 03:11:36 +02:00
|
|
|
^{x. y. texcoord origin x. texcoord origin y.
|
|
|
|
x. y + h. texcoord origin x. texcoord corner y.
|
|
|
|
x + w. y + h. texcoord corner x. texcoord corner y.
|
2022-03-24 22:48:41 +01:00
|
|
|
"x. y + h. texcoord origin x. texcoord origin y.
|
|
|
|
x + w. y. texcoord corner x. texcoord corner y."
|
2022-08-06 03:11:36 +02:00
|
|
|
x + w. y. texcoord corner x. texcoord origin y. }.
|
2022-03-06 12:07:20 +01:00
|
|
|
]
|
|
|
|
|
2022-03-21 01:45:21 +01:00
|
|
|
{ #category : #accessing }
|
2022-03-24 22:48:41 +01:00
|
|
|
DiyaText >> getLineAt: index to: line with: tex2D [
|
|
|
|
| glyph ret w |
|
|
|
|
w := 0.
|
|
|
|
index to: data size do:[ :i|
|
|
|
|
glyph := tex2D getGlyph: (data at:i) asInteger.
|
|
|
|
(w + (glyph advance x)) >= (self extent x) ifTrue:[
|
|
|
|
wrap ifFalse: [ ^ i @ w].
|
|
|
|
ret := self lastSeparatorFrom: i.
|
|
|
|
ret to: i - 1 do:[:j|
|
|
|
|
w := w - (line removeLast advance x)].
|
|
|
|
^ (ret+1)@w
|
|
|
|
] ifFalse:[
|
|
|
|
w := w + (glyph advance x).
|
|
|
|
line add: glyph.
|
|
|
|
].
|
|
|
|
].
|
2022-08-06 03:11:36 +02:00
|
|
|
maxLineWidth := maxLineWidth max: w.
|
2022-03-24 22:48:41 +01:00
|
|
|
^ (data size + 1) @ w
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> initTexture [
|
|
|
|
font:= DiyaFontManager uniqueInstance style: self fontStyle from: self fontName.
|
|
|
|
texture := font textureOf: self fontSize.
|
2022-03-21 01:45:21 +01:00
|
|
|
]
|
|
|
|
|
2022-03-01 22:58:58 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> initialize [
|
|
|
|
super initialize.
|
|
|
|
data := nil.
|
2022-03-06 19:50:19 +01:00
|
|
|
wrap := false.
|
2022-03-19 02:18:29 +01:00
|
|
|
texheight := 0.
|
2022-03-24 22:48:41 +01:00
|
|
|
type := GL_QUADS.
|
2022-08-06 03:11:36 +02:00
|
|
|
maxLineWidth := 0.
|
2022-03-16 01:32:01 +01:00
|
|
|
]
|
|
|
|
|
2022-08-12 16:37:53 +02:00
|
|
|
{ #category : #'text-processing' }
|
2022-03-21 01:45:21 +01:00
|
|
|
DiyaText >> lastSeparatorFrom: index [
|
|
|
|
index to: 1 by: -1 do: [:i|
|
|
|
|
(data at: i) isSeparator ifTrue:[^i].
|
2022-03-16 01:32:01 +01:00
|
|
|
].
|
|
|
|
^ 0
|
2022-03-01 22:58:58 +01:00
|
|
|
]
|
2022-03-06 12:07:20 +01:00
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> lines [
|
|
|
|
^ lines
|
|
|
|
]
|
|
|
|
|
2022-08-06 03:11:36 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> maxLineHeight [
|
|
|
|
texture ifNil: [ ^0].
|
|
|
|
^ texture linespace
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> maxLineWidth [
|
|
|
|
^ maxLineWidth
|
|
|
|
]
|
|
|
|
|
2022-08-10 19:55:49 +02:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> process [
|
|
|
|
bbox ifNil: [ ^true ].
|
|
|
|
data ifNil:[^true].
|
|
|
|
data ifEmpty:[^true].
|
2022-08-12 16:37:53 +02:00
|
|
|
texture ifNil: [ self initTexture ].
|
2022-08-10 19:55:49 +02:00
|
|
|
vbuffer ifNotNil: [vbuffer free].
|
|
|
|
vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16.
|
|
|
|
vbuffer autoRelease.
|
|
|
|
self drawText.
|
|
|
|
^true
|
|
|
|
]
|
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> splitLines [
|
|
|
|
|line ret tex2D|
|
|
|
|
ret := 1@0.
|
|
|
|
tex2D := self texture.
|
|
|
|
lines := OrderedCollection new.
|
|
|
|
[
|
|
|
|
line := OrderedCollection new.
|
|
|
|
ret := self getLineAt: ret x to: line with: tex2D.
|
|
|
|
lines add: ((ret y) -> line).
|
|
|
|
(ret x < data size) and: wrap
|
|
|
|
] whileTrue.
|
|
|
|
]
|
|
|
|
|
2022-08-15 12:28:09 +02:00
|
|
|
{ #category : #stepping }
|
|
|
|
DiyaText >> step [
|
|
|
|
texture ifNil: [ ^self ].
|
|
|
|
texheight = texture height ifTrue: [ ^self].
|
|
|
|
texheight := texture height.
|
|
|
|
self setDirty
|
|
|
|
]
|
|
|
|
|
2022-08-12 16:37:53 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> styleName: aName [
|
|
|
|
super styleName: aName.
|
|
|
|
texture := nil.
|
|
|
|
]
|
|
|
|
|
2022-03-06 12:07:20 +01:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> texture [
|
2022-03-24 22:48:41 +01:00
|
|
|
^texture
|
2022-03-06 12:07:20 +01:00
|
|
|
]
|
2022-03-06 19:50:19 +01:00
|
|
|
|
2022-03-24 22:48:41 +01:00
|
|
|
{ #category : #'menu messages' }
|
|
|
|
DiyaText >> valign [
|
2022-08-07 20:43:16 +02:00
|
|
|
^ self ? #yAlign
|
2022-03-24 22:48:41 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaText >> valignText:h [
|
2022-08-06 03:11:36 +02:00
|
|
|
self valign = #middle ifTrue:[^ (0 max:((self extent y - h) / 2 ) asFloat)].
|
|
|
|
self valign = #bottom ifTrue:[^ (0 max:(self extent y - h ))].
|
2022-03-24 22:48:41 +01:00
|
|
|
^0
|
|
|
|
]
|
|
|
|
|
2022-03-06 19:50:19 +01:00
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaText >> wordWrap: aBool [
|
|
|
|
wrap := aBool.
|
2022-08-12 16:37:53 +02:00
|
|
|
self setDirty
|
2022-03-06 19:50:19 +01:00
|
|
|
]
|