Skip to content

Commit

Permalink
Properly show/hide canvas bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsikes committed Nov 29, 2022
1 parent 3f8ceaa commit 981aa1d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
6 changes: 6 additions & 0 deletions canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ class Canvas : public QOpenGLWidget, protected QOpenGLFunctions {
/// Set the maximum X and Y bounds
void setBounds(double x, double y);

/// Set whether the view should use the whole widget or a box within
void setIsBounded(bool aIsBounded) { canvasIsBounded = aIsBounded; update(); }

/// Returns true if the bounds are drawn
bool isBounded() { return canvasIsBounded; }

/// Return a screenshot of the canvas
QImage getImage();

Expand Down
1 change: 1 addition & 0 deletions constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum messageCategory : message_t {
C_CANVAS_CLEAR_SCREEN, // Clear the graphics screen
C_CANVAS_SET_BACKGROUND_COLOR, // Set the canvas background color
C_CANVAS_SETBOUNDS, // Set the X and Y bounds of the drawing surface area
C_CANVAS_SET_IS_BOUNDED, // Determine whether canvas draws in a box or whole widget
C_CANVAS_SET_PENSIZE, // Set the drawing pen size
C_CANVAS_SET_FONT_NAME, // Set the label font name
C_CANVAS_SET_FONT_SIZE, // Set the label font size
Expand Down
12 changes: 10 additions & 2 deletions kernel_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ DatumP Kernel::excWrap(DatumP node) {
TurtleModeEnum newMode = turtleWrap;
if (mainTurtle()->getMode() != newMode) {
mainTurtle()->setMode(newMode);
mainController()->setIsCanvasBounded(true);
if (mainController()->isCanvasBounded() == false) {
mainController()->setIsCanvasBounded(true);
mainTurtle()->home(false);
mainController()->clearScreen();
}
}
return h.ret();
}
Expand All @@ -331,7 +335,11 @@ DatumP Kernel::excFence(DatumP node) {
TurtleModeEnum newMode = turtleFence;
if (mainTurtle()->getMode() != newMode) {
mainTurtle()->setMode(newMode);
mainController()->setIsCanvasBounded(true);
if (mainController()->isCanvasBounded() == false) {
mainController()->setIsCanvasBounded(true);
mainTurtle()->home(false);
mainController()->clearScreen();
}
}
return h.ret();
}
Expand Down
3 changes: 2 additions & 1 deletion logocontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class LogoController : public QObject {

virtual void setPensize(double) { Error::noGraphics(); }
virtual bool isPenSizeValid(double) { Error::noGraphics(); return false; }
void setIsCanvasBounded(bool) { Error::noGraphics(); }
virtual void setIsCanvasBounded(bool) { Error::noGraphics(); }
virtual bool isCanvasBounded() { Error::noGraphics(); return false; }
void setSplitterSizeRatios(float, float) { Error::noGraphics(); }

Kernel *kernel;
Expand Down
7 changes: 7 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ void MainWindow::readStandardOutput()
ui->mainCanvas->setBounds(x, y);
break;
}
case C_CANVAS_SET_IS_BOUNDED:
{
bool isBounded;
*dataStream >> isBounded;
ui->mainCanvas->setIsBounded(isBounded);
break;
}
case C_CANVAS_SET_FONT_NAME:
{
QString name;
Expand Down
15 changes: 15 additions & 0 deletions qlogocontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ ScreenModeEnum QLogoController::getScreenMode()
return screenMode;
}

void QLogoController::setIsCanvasBounded(bool aIsBounded)
{
if (canvasIsBounded == aIsBounded)
return;
canvasIsBounded = aIsBounded;
sendMessage([&](QDataStream *out) {
*out << (message_t)C_CANVAS_SET_IS_BOUNDED << aIsBounded;
});
}

bool QLogoController::isCanvasBounded()
{
return canvasIsBounded;
}

void QLogoController::setTurtleIsVisible(bool isVisible)
{
sendMessage([&](QDataStream *out) {
Expand Down
3 changes: 3 additions & 0 deletions qlogocontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class QLogoController : public LogoController

double xbound;
double ybound;
bool canvasIsBounded = true;

QColor currentBackgroundColor;
QImage canvasImage;
Expand Down Expand Up @@ -83,6 +84,8 @@ class QLogoController : public LogoController
double boundX() { return xbound; }
double boundY() { return ybound; }
QColor getCanvasBackgroundColor(void);
void setIsCanvasBounded(bool aIsBounded);
bool isCanvasBounded();

bool isPenSizeValid(double candidate) { return ((candidate >= minPensize) && (candidate <= maxPensize)); }
QImage getCanvasImage();
Expand Down

0 comments on commit 981aa1d

Please sign in to comment.