Change drawing commands in customwidget example
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
parent
85b669385f
commit
2ea0ad23e9
2
knob.py
2
knob.py
|
@ -3,7 +3,7 @@
|
||||||
import math
|
import math
|
||||||
|
|
||||||
from nanogui import Color, Cursor, FloatBox, Vector2f, Vector2i, Widget, glfw
|
from nanogui import Color, Cursor, FloatBox, Vector2f, Vector2i, Widget, glfw
|
||||||
from nanogui.nanovg import BUTT, RGB, RGBA, RGBAf, LerpRGBA, NVGwinding, RGBAf
|
from nanogui.nanovg import BUTT, LerpRGBA, NVGwinding, RGB, RGBA, RGBAf
|
||||||
|
|
||||||
|
|
||||||
class Knob(Widget):
|
class Knob(Widget):
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
import nanogui
|
import nanogui
|
||||||
from nanogui import glfw
|
from nanogui import glfw
|
||||||
from nanogui import BoxLayout, Color, Label, Orientation, Screen, Widget, Window, Vector2i
|
from nanogui import BoxLayout, Color, Label, Orientation, Screen, Widget, Window, Vector2i
|
||||||
from nanogui.nanovg import RGBAf, RGB
|
from nanogui.nanovg import LerpRGBA, RGBAf, RGB
|
||||||
|
|
||||||
|
|
||||||
class CustomWidget(Widget):
|
class CustomWidget(Widget):
|
||||||
def __init__(self, parent, size=(100, 100), color=Color(192, 0, 0, 255)):
|
def __init__(self, parent, size=(100, 100), color=Color(192, 0, 0, 255)):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._size = size
|
self._size = size
|
||||||
self._color = RGBAf(color.r, color.g, color.b, color.w)
|
self.color = RGBAf(color.r, color.g, color.b, color.w)
|
||||||
|
|
||||||
def preferred_size(self, ctx):
|
def preferred_size(self, ctx):
|
||||||
return Vector2i(self._size)
|
return Vector2i(self._size)
|
||||||
|
@ -21,13 +21,18 @@ class CustomWidget(Widget):
|
||||||
|
|
||||||
ctx.BeginPath()
|
ctx.BeginPath()
|
||||||
ctx.Rect(pos[0], pos[1], size[0], size[1])
|
ctx.Rect(pos[0], pos[1], size[0], size[1])
|
||||||
ctx.FillColor(RGB(128, 128, 0))
|
bg = LerpRGBA(RGB(64, 64, 64), self.color, 0.3)
|
||||||
|
ctx.FillColor(bg)
|
||||||
ctx.Fill()
|
ctx.Fill()
|
||||||
ctx.BeginPath()
|
ctx.BeginPath()
|
||||||
ctx.StrokeWidth(5.0)
|
ctx.StrokeWidth(5.0)
|
||||||
ctx.StrokeColor(self._color)
|
ctx.StrokeColor(self.color)
|
||||||
ctx.MoveTo(pos[0], pos[1])
|
ctx.Rect(
|
||||||
ctx.LineTo(pos[0] + size[0], pos[1] + size[1] / 3.0)
|
pos[0] + size[0] / 4.0,
|
||||||
|
pos[1] + size[1] / 4.0,
|
||||||
|
size[0] / 2.0,
|
||||||
|
size[1] / 2.0,
|
||||||
|
)
|
||||||
ctx.Stroke()
|
ctx.Stroke()
|
||||||
ctx.ClosePath()
|
ctx.ClosePath()
|
||||||
|
|
||||||
|
@ -42,7 +47,7 @@ class CustomWidgetApp(Screen):
|
||||||
|
|
||||||
Label(self.win, "NanoGUI CustomWidget Demo", "sans-bold")
|
Label(self.win, "NanoGUI CustomWidget Demo", "sans-bold")
|
||||||
|
|
||||||
cw = CustomWidget(self.win, (200, 100))
|
_ = CustomWidget(self.win, (200, 100))
|
||||||
|
|
||||||
self.draw_all()
|
self.draw_all()
|
||||||
self.set_visible(True)
|
self.set_visible(True)
|
||||||
|
|
Loading…
Reference in New Issue