104 lines
No EOL
2.4 KiB
Text
104 lines
No EOL
2.4 KiB
Text
import "luxe: world" for Entity, Text, Transform
|
|
import "luxe: assets" for Assets
|
|
import "luxe: asset" for Asset
|
|
import "luxe: render" for Material
|
|
import "luxe: math" for Math
|
|
|
|
import "globals" for Globals
|
|
import "math/vector" for Vector
|
|
|
|
class Tooltip{
|
|
depth{127}
|
|
color{[1, 1, 1, 1]}
|
|
background{[0, 0, 0, 1]}
|
|
|
|
shadowOffsets{[[1, 0],[0, 1],[-1, 0],[0, -1],[1, 1],[1, -1],[-1, -1],[-1, 1]]}
|
|
|
|
construct new(app){
|
|
_text = Entity.create(app.ui)
|
|
var mat = Material.create("luxe: material_basis/ui_font")
|
|
Text.create(_text, mat, 8, Asset.font("assets/fonts/BabyBlocks"), color)
|
|
|
|
//Text.create(b, Assets.material("luxe: material/font"), 25, "luxe : fonts/lato", [1, 1, 1, 1])
|
|
//Text.set_text(b, "Play")
|
|
|
|
Transform.create(_text)
|
|
Transform.set_snap(_text, 1, 1, 0)
|
|
|
|
var offsets = shadowOffsets
|
|
_shadows = []
|
|
for(i in offsets){
|
|
var shadow = Entity.create(app.ui)
|
|
var mat = Material.create("luxe: material_basis/ui_font")
|
|
Text.create(shadow, mat, 8, Asset.font("assets/fonts/BabyBlocks"), background)
|
|
Transform.create(shadow)
|
|
Transform.set_snap(shadow, 1, 1, 0)
|
|
_shadows.add(shadow)
|
|
}
|
|
_width = 0
|
|
_height = 0
|
|
|
|
Globals["Tooltip"] = this
|
|
}
|
|
|
|
tick(){
|
|
var pos = Vector.new(Globals["UiMouse"])
|
|
if(pos){
|
|
pos.x = Math.clamp(pos.x, 1, Globals["Renderer"].width - _width - 1)
|
|
pos.y = Math.clamp(pos.y, 1, Globals["Renderer"].height - _height - 1)
|
|
if(_x){
|
|
pos.x = _x
|
|
}
|
|
if(_y){
|
|
pos.y = _y
|
|
}
|
|
Transform.set_pos(_text, pos.x, pos.y, depth)
|
|
|
|
var offsets = shadowOffsets
|
|
for(i in 0...offsets.count){
|
|
Transform.set_pos(_shadows[i], pos.x+offsets[i].x, pos.y+offsets[i].y, depth-1)
|
|
}
|
|
}
|
|
}
|
|
|
|
set(text) {
|
|
set(text, null)
|
|
}
|
|
|
|
fix_y(value){
|
|
_y = value
|
|
tick()
|
|
}
|
|
|
|
fix_x(value){
|
|
_x = value
|
|
tick()
|
|
}
|
|
|
|
set(text, source){
|
|
for(shadow in _shadows){
|
|
Text.set_text_buffer(shadow, text)
|
|
Text.commit(shadow)
|
|
}
|
|
Text.set_text_buffer(_text, text)
|
|
Text.commit(_text)
|
|
_active = true
|
|
_source = source
|
|
_x = null
|
|
_y = null
|
|
|
|
var extents = Text.get_extents(_text)
|
|
_width = extents.x
|
|
_height = extents.y
|
|
}
|
|
|
|
clear(){
|
|
clear(_source)
|
|
}
|
|
|
|
clear(source){
|
|
if(_source != source) return
|
|
set("")
|
|
_active = false
|
|
}
|
|
} |