Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arcs, segments, and sectors #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,42 @@ void Canvas::setLineEnds(LineEnds value)
}


void Canvas::setLinePattern(LinePattern & value)
{
Primitive p;
p.cmd = PrimitiveCmd::SetLinePattern;
p.linePattern = value;
m_displayController->addPrimitive(p);
}


void Canvas::setLinePatternLength(uint8_t value)
{
Primitive p;
p.cmd = PrimitiveCmd::SetLinePatternLength;
p.ivalue = value;
m_displayController->addPrimitive(p);
}


void Canvas::setLinePatternOffset(uint8_t value)
{
Primitive p;
p.cmd = PrimitiveCmd::SetLinePatternOffset;
p.ivalue = value;
m_displayController->addPrimitive(p);
}


void Canvas::setLineOptions(LineOptions options)
{
Primitive p;
p.cmd = PrimitiveCmd::SetLineOptions;
p.lineOptions = options;
m_displayController->addPrimitive(p);
}


void Canvas::setBrushColor(RGB888 const & color)
{
Primitive p;
Expand Down Expand Up @@ -339,6 +375,48 @@ void Canvas::drawEllipse(int X, int Y, int width, int height)
}


void Canvas::drawArc(int X, int Y, int X1, int Y1, int X2, int Y2)
{
moveTo(X, Y);
Primitive p;
p.cmd = PrimitiveCmd::DrawArc;
// Use a Rect as a convenience to pass 2 points
// NB arc is always drawn anti-clockwise, with X1,Y1 as the start point
// and X2,Y2 as the end point, which is used to calculate the angle
// (i.e. the end point does not have to lie on circumference)
p.rect = Rect(X1, Y1, X2, Y2);
m_displayController->addPrimitive(p);
}


void Canvas::fillSegment(int X, int Y, int X1, int Y1, int X2, int Y2)
{
moveTo(X, Y);
Primitive p;
p.cmd = PrimitiveCmd::FillSegment;
// Use a Rect as a convenience to pass 2 points
// NB arc is always drawn anti-clockwise, with X1,Y1 as the start point
// and X2,Y2 as the end point, which is used to calculate the angle
// (i.e. the end point does not have to lie on circumference)
p.rect = Rect(X1, Y1, X2, Y2);
m_displayController->addPrimitive(p);
}


void Canvas::fillSector(int X, int Y, int X1, int Y1, int X2, int Y2)
{
moveTo(X, Y);
Primitive p;
p.cmd = PrimitiveCmd::FillSector;
// Use a Rect as a convenience to pass 2 points
// NB arc is always drawn anti-clockwise, with X1,Y1 as the start point
// and X2,Y2 as the end point, which is used to calculate the angle
// (i.e. the end point does not have to lie on circumference)
p.rect = Rect(X1, Y1, X2, Y2);
m_displayController->addPrimitive(p);
}


void Canvas::drawGlyph(int X, int Y, int width, int height, uint8_t const * data, int index)
{
Primitive p;
Expand Down
84 changes: 84 additions & 0 deletions src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,50 @@ class Canvas {
*/
void setLineEnds(LineEnds value);

/**
* @brief Sets line pattern
*
* @param value Line pattern.
*
* Example:
*
* Canvas.setLinePattern(pattern)
*/
void setLinePattern(LinePattern & value);

/**
* @brief Sets line pattern length
*
* @param value Line pattern length.
*
* Example:
*
* Canvas.setLinePatternLength(length)
*/
void setLinePatternLength(uint8_t value);

/**
* @brief Sets offset position within the line pattern
*
* @param value offset position.
*
* Example:
*
* Canvas.setLinePatternOffset(position)
*/
void setLinePatternOffset(uint8_t value);

/**
* @brief Sets line drawing options
*
* @param value Line drawing options.
*
* Example:
*
* Canvas.setLineOptions(LineOptions().Antialias(true).Smooth(true));
*/
void setLineOptions(LineOptions value);

/**
* @brief Fills a single pixel with the pen color.
*
Expand Down Expand Up @@ -486,6 +530,46 @@ class Canvas {
*/
void drawEllipse(int X, int Y, int width, int height);

/**
* @brief Draws an anticlockwise arc of a circle specifying center, start and endpoints, using current pen color.
*
* @param X Horizontal coordinate of the circle center.
* @param Y Vertical coordinate of the circle center.
* @param X1 Horizontal coordinate of the start point.
* @param Y1 Vertical coordinate of the start point.
* @param X2 Horizontal coordinate of the end point.
* @param Y2 Vertical coordinate of the end point.
*/
void drawArc(int X, int Y, int X1, int Y1, int X2, int Y2);

/**
* @brief Draws a filled segment of a circle specifying center, start and endpoints, using current brush color.
* The circle arc is drawn anticlockwise.
* The endpoint is used to work out the angle to the end point of the arc, rather than being on the arc itself.
*
* @param X Horizontal coordinate of the circle center.
* @param Y Vertical coordinate of the circle center.
* @param X1 Horizontal coordinate of the start point.
* @param Y1 Vertical coordinate of the start point.
* @param X2 Horizontal coordinate of the end point.
* @param Y2 Vertical coordinate of the end point.
*/
void fillSegment(int X, int Y, int X1, int Y1, int X2, int Y2);

/**
* @brief Draws a filled sector of a circle specifying center, start and endpoints, using current brush color.
* The circle arc is drawn anticlockwise.
* The endpoint is used to work out the angle to the end point of the arc, rather than being on the arc itself.
*
* @param X Horizontal coordinate of the circle center.
* @param Y Vertical coordinate of the circle center.
* @param X1 Horizontal coordinate of the start point.
* @param Y1 Vertical coordinate of the start point.
* @param X2 Horizontal coordinate of the end point.
* @param Y2 Vertical coordinate of the end point.
*/
void fillSector(int X, int Y, int X1, int Y1, int X2, int Y2);

/**
* @brief Fills an ellipse specifying center and size, using current brush color.
*
Expand Down
21 changes: 21 additions & 0 deletions src/dispdrivers/vga16controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,27 @@ void VGA16Controller::drawEllipse(Size const & size, Rect & updateRect)
}


void VGA16Controller::drawArc(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericDrawArc(rect, updateRect, getPixelLambda(mode), setPixelLambda(mode));
}


void VGA16Controller::fillSegment(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSegment(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA16Controller::fillSector(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSector(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA16Controller::clear(Rect & updateRect)
{
hideSprites(updateRect);
Expand Down
9 changes: 9 additions & 0 deletions src/dispdrivers/vga16controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ class VGA16Controller : public VGAPalettedController {
// abstract method of BitmappedDisplayController
void drawEllipse(Size const & size, Rect & updateRect);

// abstract method of BitmappedDisplayController
void drawArc(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSegment(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSector(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void clear(Rect & updateRect);

Expand Down
21 changes: 21 additions & 0 deletions src/dispdrivers/vga2controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,27 @@ void VGA2Controller::drawEllipse(Size const & size, Rect & updateRect)
}


void VGA2Controller::drawArc(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericDrawArc(rect, updateRect, getPixelLambda(mode), setPixelLambda(mode));
}


void VGA2Controller::fillSegment(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSegment(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA2Controller::fillSector(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSector(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA2Controller::clear(Rect & updateRect)
{
hideSprites(updateRect);
Expand Down
9 changes: 9 additions & 0 deletions src/dispdrivers/vga2controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ class VGA2Controller : public VGAPalettedController {
// abstract method of BitmappedDisplayController
void drawEllipse(Size const & size, Rect & updateRect);

// abstract method of BitmappedDisplayController
void drawArc(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSegment(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSector(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void clear(Rect & updateRect);

Expand Down
21 changes: 21 additions & 0 deletions src/dispdrivers/vga4controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ void VGA4Controller::drawEllipse(Size const & size, Rect & updateRect)
}


void VGA4Controller::drawArc(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericDrawArc(rect, updateRect, getPixelLambda(mode), setPixelLambda(mode));
}


void VGA4Controller::fillSegment(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSegment(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA4Controller::fillSector(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSector(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA4Controller::clear(Rect & updateRect)
{
hideSprites(updateRect);
Expand Down
9 changes: 9 additions & 0 deletions src/dispdrivers/vga4controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ class VGA4Controller : public VGAPalettedController {
// abstract method of BitmappedDisplayController
void drawEllipse(Size const & size, Rect & updateRect);

// abstract method of BitmappedDisplayController
void drawArc(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSegment(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSector(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void clear(Rect & updateRect);

Expand Down
21 changes: 21 additions & 0 deletions src/dispdrivers/vga8controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,27 @@ void VGA8Controller::drawEllipse(Size const & size, Rect & updateRect)
}


void VGA8Controller::drawArc(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericDrawArc(rect, updateRect, getPixelLambda(mode), setPixelLambda(mode));
}


void VGA8Controller::fillSegment(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSegment(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA8Controller::fillSector(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSector(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void VGA8Controller::clear(Rect & updateRect)
{
hideSprites(updateRect);
Expand Down
9 changes: 9 additions & 0 deletions src/dispdrivers/vga8controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ class VGA8Controller : public VGAPalettedController {
// abstract method of BitmappedDisplayController
void drawEllipse(Size const & size, Rect & updateRect);

// abstract method of BitmappedDisplayController
void drawArc(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSegment(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void fillSector(Rect const & rect, Rect & updateRect);

// abstract method of BitmappedDisplayController
void clear(Rect & updateRect);

Expand Down
21 changes: 21 additions & 0 deletions src/dispdrivers/vgacontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,27 @@ void IRAM_ATTR VGAController::drawEllipse(Size const & size, Rect & updateRect)
}


void IRAM_ATTR VGAController::drawArc(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericDrawArc(rect, updateRect, getPixelLambda(mode), setPixelLambda(mode));
}


void IRAM_ATTR VGAController::fillSegment(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSegment(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void IRAM_ATTR VGAController::fillSector(Rect const & rect, Rect & updateRect)
{
auto mode = paintState().paintOptions.mode;
genericFillSector(rect, updateRect, getPixelLambda(mode), fillRowLambda(mode));
}


void IRAM_ATTR VGAController::clear(Rect & updateRect)
{
hideSprites(updateRect);
Expand Down
Loading