dymokomi/luced-2d
Source of release 0.5.1
0.5.1 / src / sample_tools.luc
## The Eyedropper, and any tool while the color picker samples: held down,
## its ring shows the color under it over the foreground as it was, which it
## keeps sampling as it moves.
from luce_ui.ui import Event
from luce_gpu.gpu import Color
from tool_handler import ToolHandler, ToolContext
pub class EyedropperTool: ToolHandler:
pub var ringing: bool = false
## The foreground when the press began, the ring's lower half.
pub var before: Color = Color(0.0, 0.0, 0.0)
pub func active(self) -> bool:
return self.ringing
pub func press(self, context: ToolContext, event: Event, x: float, y: float) -> unit!:
if context.dialog_sample(x, y):
return
let colors = context.workspace.colors
self.ringing = true
self.before = Color(colors.red, colors.green, colors.blue)
context.workspace.eyedroppers.pick(x, y)
pub func drag(self, context: ToolContext, event: Event, x: float, y: float) -> unit!:
context.workspace.eyedroppers.pick(x, y)
pub func release(self, context: ToolContext, event: Event, x: float, y: float) -> unit!:
self.ringing = false
context.changed()