Skip to content

Commit

Permalink
Add hooks to canvas to hide/show stuff on draw start/end
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 29, 2024
1 parent b975b13 commit e8df3f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
49 changes: 38 additions & 11 deletions applications/test/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,77 @@ OxideWindow{
color: "white"
anchors.fill: parent
}
component MyButton: Button{
id: control
contentItem: Text {
text: control.text
font: control.font
color: control.enabled ? "black" : "white"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle{
color: control.enabled ? "white" : "black"
border.color: "black"
border.width: 1
radius: 2
}
}
RowLayout{
id: buttons
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
Button{

MyButton{
text: "Black Pen"
enabled: canvas.brush !== Oxide.brushFromColor("black")
onClicked: canvas.brush = Oxide.brushFromColor("black")
}
Button{
MyButton{
text: "White Pen"
enabled: canvas.brush !== Oxide.brushFromColor("white")
onClicked: canvas.brush = Oxide.brushFromColor("white")
}
Item{
Layout.fillWidth: true
}
Button{
MyButton{
text: "3px"
enabled: canvas.penWidth !== 3
onClicked: canvas.penWidth = 3
}
Button{
MyButton{
text: "6px"
enabled: canvas.penWidth !== 6
onClicked: canvas.penWidth = 6
}
Button{
MyButton{
text: "12px"
enabled: canvas.penWidth !== 12
onClicked: canvas.penWidth = 12
}
Button{
MyButton{
text: "24px"
enabled: canvas.penWidth !== 24
onClicked: canvas.penWidth = 24
}
}
Label{
id: message
text: "Ctrl-Q, Ctrl-W, Backspace, or Escape to quit"
color: "black"
anchors.centerIn: parent
}
Canvas{
id: canvas
anchors.left: parent.left
anchors.right: parent.right
anchors.top: buttons.bottom
anchors.bottom: parent.bottom
}
Label{
text: "Ctrl-Q, Ctrl-W, Backspace, or Escape to quit"
color: "black"
anchors.centerIn: parent
onDrawStart: message.visible = false
onDrawDone: message.visible = true
}
}
}
28 changes: 14 additions & 14 deletions shared/liboxide/oxideqml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace Oxide {
return;
}
m_lastPoint = event->localPos();
emit drawStart();
}

void Canvas::mouseMoveEvent(QMouseEvent* event){
Expand Down Expand Up @@ -134,25 +135,24 @@ namespace Oxide {
#ifdef EPAPER
auto color = m_brush.color();
if(
m_brush.isOpaque()
!m_brush.isOpaque()
&& (
color == Qt::black || color == Qt::white
color != Qt::black || color != Qt::white
)
){
return;
auto buf = getSurfaceForWindow(window());
auto rect = mapRectToScene(boundingRect());
Blight::connection()->repaint(
buf,
rect.x(),
rect.y(),
rect.width(),
rect.height(),
Blight::WaveformMode::Grayscale
);
}
auto buf = getSurfaceForWindow(window());
QImage image(buf->data, buf->width, buf->height, buf->stride, (QImage::Format)buf->format);
auto rect = mapRectToScene(boundingRect());
Blight::connection()->repaint(
buf,
rect.x(),
rect.y(),
rect.width(),
rect.height(),
Blight::WaveformMode::Grayscale
);
#endif
emit drawDone();
}

#ifdef EPAPER
Expand Down
2 changes: 2 additions & 0 deletions shared/liboxide/oxideqml.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace Oxide {
QImage* image();

signals:
void drawStart();
void drawDone();
void brushChanged(const QBrush& brush);
void penWidthChanged(qreal pendWidth);

Expand Down

0 comments on commit e8df3f0

Please sign in to comment.