-
-
Notifications
You must be signed in to change notification settings - Fork 65
Complete ICairoShim refactoring for drawUserFunction and SVG-based classes #612
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
Open
Copilot
wants to merge
22
commits into
master
Choose a base branch
from
copilot/refactor-item-draw-method
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,438
−116
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
95ebc67
Initial plan
Copilot 0eaa1ef
Add ICairoShim interface and CairoShimCairo implementation with Item …
Copilot 74e75b5
Add ICairoShim overloads to Lock and DataOp
Copilot a16b88e
Add ICairoShim overload declarations to all Item subclasses and Wire
Copilot 54bd730
Add ICairoShim overloads for draw() methods in operation, intOp, and …
Copilot a6dd439
Add ICairoShim draw implementations to remaining model files
Copilot 47e747f
Complete ICairoShim refactoring - all tasks done
Copilot 10c746a
Make ICairoShim methods const, add Pango support, remove cairoContext
Copilot 407b85c
Fix all draw implementations to use _internalGetCairoContext temporarily
Copilot fb3b692
Add drawTriangle ICairoShim overload and implement SwitchIcon properly
Copilot 15aa917
Implement drawUserFunction and Ravel::draw with ICairoShim (partial)
Copilot 8a4fee1
Fix compilation errors
highperformancecoder 80a78b4
Merge branch 'master' into copilot/refactor-item-draw-method
highperformancecoder 1d965a1
Merge branch 'copilot/refactor-item-draw-method' of github.com:highpe…
highperformancecoder a00591e
Merge branch 'master' into copilot/refactor-item-draw-method
highperformancecoder e68a7af
Merge branch 'master' into copilot/refactor-item-draw-method
highperformancecoder d90e792
Merge branch 'copilot/refactor-item-draw-method' of github.com:highpe…
highperformancecoder ea302b7
Update RavelCAPI ref
highperformancecoder 822b28c
Update RavelCAPI ref
highperformancecoder 2db4ba5
Merge branch 'copilot/refactor-item-draw-method' of github.com:highpe…
highperformancecoder 6dfcd1b
Add DrawBinOpShim for ICairoShim support and update drawUserFunction
Copilot 84344b2
Implement GodleyIcon and Group draw methods with ICairoShim
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,91 +1,140 @@ | ||
| #include "cairoShim.h" | ||
| #include "cairoShimCairo.h" | ||
| #include "minsky_epilogue.h" | ||
| #define CAIRO_WIN32_STATIC_BUILD | ||
| #include <cairo.h> | ||
| #undef CAIRO_WIN32_STATIC_BUILD | ||
| #include <pango.h> | ||
|
|
||
| using namespace std; | ||
|
|
||
| namespace ravel | ||
| namespace minsky | ||
| { | ||
| void CairoShimCairo::moveTo(double x, double y) | ||
| CairoShimCairo::CairoShimCairo(cairo_t* c) : cairo(c) {} | ||
|
|
||
| CairoShimCairo::~CairoShimCairo() = default; | ||
|
|
||
| // Drawing operations | ||
| void CairoShimCairo::moveTo(double x, double y) const | ||
| {cairo_move_to(cairo,x,y);} | ||
|
|
||
| void CairoShimCairo::lineTo(double x, double y) | ||
| void CairoShimCairo::lineTo(double x, double y) const | ||
| {cairo_line_to(cairo,x,y);} | ||
|
|
||
| void CairoShimCairo::relMoveTo(double x, double y) | ||
| void CairoShimCairo::relMoveTo(double x, double y) const | ||
| {cairo_rel_move_to(cairo,x,y);} | ||
|
|
||
| void CairoShimCairo::relLineTo(double x, double y) | ||
| void CairoShimCairo::relLineTo(double x, double y) const | ||
| {cairo_rel_line_to(cairo,x,y);} | ||
|
|
||
| void CairoShimCairo::arc | ||
| (double x, double y, double radius, double start, double end) | ||
| void CairoShimCairo::arc(double x, double y, double radius, double start, double end) const | ||
| {cairo_arc(cairo,x,y,radius,start,end);} | ||
|
|
||
| // paths | ||
| void CairoShimCairo::newPath() | ||
| void CairoShimCairo::curveTo(double x1, double y1, double x2, double y2, double x3, double y3) const | ||
| {cairo_curve_to(cairo,x1,y1,x2,y2,x3,y3);} | ||
|
|
||
| void CairoShimCairo::rectangle(double x, double y, double width, double height) const | ||
| {cairo_rectangle(cairo,x,y,width,height);} | ||
|
|
||
| // Path operations | ||
| void CairoShimCairo::newPath() const | ||
| {cairo_new_path(cairo);} | ||
|
|
||
| void CairoShimCairo::closePath() | ||
| void CairoShimCairo::newSubPath() const | ||
| {cairo_new_sub_path(cairo);} | ||
|
|
||
| void CairoShimCairo::closePath() const | ||
| {cairo_close_path(cairo);} | ||
|
|
||
| void CairoShimCairo::fill() | ||
| void CairoShimCairo::getCurrentPoint(double& x, double& y) const | ||
| {cairo_get_current_point(cairo, &x, &y);} | ||
|
|
||
| // Fill and stroke operations | ||
| void CairoShimCairo::fill() const | ||
| {cairo_fill(cairo);} | ||
|
|
||
| void CairoShimCairo::fillPreserve() const | ||
| {cairo_fill_preserve(cairo);} | ||
|
|
||
| void CairoShimCairo::clip() | ||
| void CairoShimCairo::clip() const | ||
| {cairo_clip(cairo);} | ||
|
|
||
| void CairoShimCairo::stroke() | ||
| void CairoShimCairo::resetClip() const | ||
| {cairo_reset_clip(cairo);} | ||
|
|
||
| void CairoShimCairo::stroke() const | ||
| {cairo_stroke(cairo);} | ||
|
|
||
| void CairoShimCairo::strokePreserve() | ||
| void CairoShimCairo::strokePreserve() const | ||
| {cairo_stroke_preserve(cairo);} | ||
|
|
||
| void CairoShimCairo::setLineWidth(double w) | ||
| void CairoShimCairo::paint() const | ||
| {cairo_paint(cairo);} | ||
|
|
||
| // Line properties | ||
| void CairoShimCairo::setLineWidth(double w) const | ||
| {cairo_set_line_width(cairo, w);} | ||
|
|
||
| // sources | ||
| void CairoShimCairo::setSourceRGB | ||
| (double r, double g, double b) | ||
| double CairoShimCairo::getLineWidth() const | ||
| {return cairo_get_line_width(cairo);} | ||
|
|
||
| void CairoShimCairo::setDash(const double* dashes, int num_dashes, double offset) const | ||
| {cairo_set_dash(cairo, dashes, num_dashes, offset);} | ||
|
|
||
| void CairoShimCairo::setFillRule(cairo_fill_rule_t fill_rule) const | ||
| {cairo_set_fill_rule(cairo, fill_rule);} | ||
|
|
||
| // Color operations | ||
| void CairoShimCairo::setSourceRGB(double r, double g, double b) const | ||
| {cairo_set_source_rgb(cairo,r,g,b);} | ||
|
|
||
| void CairoShimCairo::setSourceRGBA | ||
| (double r, double g, double b, double a) | ||
| void CairoShimCairo::setSourceRGBA(double r, double g, double b, double a) const | ||
| {cairo_set_source_rgba(cairo,r,g,b,a);} | ||
|
|
||
| // text. Argument is in UTF8 encoding | ||
| void CairoShimCairo::showText(const std::string& text) | ||
| // Text operations | ||
| void CairoShimCairo::showText(const std::string& text) const | ||
| {cairo_show_text(cairo,text.c_str());} | ||
|
|
||
| void CairoShimCairo::setTextExtents(const std::string& text) | ||
| {cairo_text_extents(cairo,text.c_str(),&extents);} | ||
| void CairoShimCairo::setFontSize(double size) const | ||
| {cairo_set_font_size(cairo, size);} | ||
|
|
||
| double CairoShimCairo::textWidth() const | ||
| {return extents.width;} | ||
| void CairoShimCairo::selectFontFace(const std::string& family, cairo_font_slant_t slant, cairo_font_weight_t weight) const | ||
| {cairo_select_font_face(cairo, family.c_str(), slant, weight);} | ||
|
|
||
| double CairoShimCairo::textHeight() const | ||
| {return extents.height;} | ||
| void CairoShimCairo::textExtents(const std::string& text, cairo_text_extents_t& extents) const | ||
| {cairo_text_extents(cairo,text.c_str(),&extents);} | ||
|
|
||
| // matrix transformation | ||
| void CairoShimCairo::identityMatrix() | ||
| // Transformation operations | ||
| void CairoShimCairo::identityMatrix() const | ||
| {cairo_identity_matrix(cairo);} | ||
|
|
||
| void CairoShimCairo::translate(double x, double y) | ||
| void CairoShimCairo::translate(double x, double y) const | ||
| {cairo_translate(cairo,x,y);} | ||
|
|
||
| void CairoShimCairo::scale(double sx, double sy) | ||
| void CairoShimCairo::scale(double sx, double sy) const | ||
| {cairo_scale(cairo,sx,sy);} | ||
|
|
||
| void CairoShimCairo::rotate(double angle) | ||
| void CairoShimCairo::rotate(double angle) const | ||
| {cairo_rotate(cairo,angle);} | ||
|
|
||
| // context manipulation | ||
| void CairoShimCairo::save() | ||
| void CairoShimCairo::userToDevice(double& x, double& y) const | ||
| {cairo_user_to_device(cairo, &x, &y);} | ||
|
|
||
| // Context state operations | ||
| void CairoShimCairo::save() const | ||
| {cairo_save(cairo);} | ||
|
|
||
| void CairoShimCairo::restore() | ||
| void CairoShimCairo::restore() const | ||
| {cairo_restore(cairo);} | ||
|
|
||
|
|
||
| // Tolerance | ||
| void CairoShimCairo::setTolerance(double tolerance) const | ||
| {cairo_set_tolerance(cairo, tolerance);} | ||
|
|
||
| // Pango support | ||
| ecolab::Pango& CairoShimCairo::pango() const | ||
| { | ||
| if (!m_pango) | ||
| m_pango.reset(new ecolab::Pango(cairo)); | ||
| return *m_pango; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,87 @@ | ||
| #ifndef CAIROSHIMCAIRO_H | ||
| #define CAIROSHIMCAIRO_H | ||
| #include "cairoShim.h" | ||
| #include "ICairoShim.h" | ||
| #include <cairo.h> | ||
| #include <pango.h> | ||
| #include <memory> | ||
|
|
||
| namespace ecolab { class Pango; } | ||
|
|
||
| namespace minsky | ||
| { | ||
| /// Concrete implementation of ICairoShim using actual Cairo library | ||
| class CairoShimCairo: public ICairoShim | ||
| { | ||
| cairo_t* cairo; | ||
| cairo_t* cairo; | ||
| mutable std::unique_ptr<ecolab::Pango> m_pango; | ||
| CairoShimCairo(const CairoShimCairo&)=delete; | ||
| void operator=(const CairoShimCairo&)=delete; | ||
| public: | ||
| // template parameter G = cairo_t* or HDC | ||
| CairoShim(cairo_t*); | ||
| ~CairoShim(); | ||
|
|
||
| void moveTo(double x, double y); | ||
| void lineTo(double x, double y); | ||
| void relMoveTo(double x, double y); | ||
| void relLineTo(double x, double y); | ||
| void arc(double x, double y, double radius, double start, double end); | ||
|
|
||
| void setLineWidth(double); | ||
|
|
||
| // paths | ||
| void newPath(); | ||
| void closePath(); | ||
| void fill(); | ||
| void clip(); | ||
| void stroke(); | ||
| void strokePreserve(); | ||
|
|
||
| // sources | ||
| void setSourceRGB(double r, double g, double b); | ||
| void setSourceRGBA(double r, double g, double b, double a); | ||
|
|
||
| // text. Argument is in UTF8 encoding | ||
| void showText(const std::string&); | ||
| void setTextExtents(const std::string&); | ||
| double textWidth() const; | ||
| double textHeight() const; | ||
|
|
||
| // matrix transformation | ||
| void identityMatrix(); | ||
| void translate(double x, double y); | ||
| void scale(double sx, double sy); | ||
| void rotate(double angle); ///< angle in radians | ||
|
|
||
| // context manipulation | ||
| void save(); | ||
| void restore(); | ||
| CairoShimCairo(cairo_t* c); | ||
| ~CairoShimCairo() override; | ||
|
|
||
| // Drawing operations | ||
| void moveTo(double x, double y) const override; | ||
| void lineTo(double x, double y) const override; | ||
| void relMoveTo(double x, double y) const override; | ||
| void relLineTo(double x, double y) const override; | ||
| void arc(double x, double y, double radius, double start, double end) const override; | ||
| void curveTo(double x1, double y1, double x2, double y2, double x3, double y3) const override; | ||
| void rectangle(double x, double y, double width, double height) const override; | ||
|
|
||
| // Path operations | ||
| void newPath() const override; | ||
| void newSubPath() const override; | ||
| void closePath() const override; | ||
| void getCurrentPoint(double& x, double& y) const override; | ||
|
|
||
| // Fill and stroke operations | ||
| void fill() const override; | ||
| void fillPreserve() const override; | ||
| void stroke() const override; | ||
| void strokePreserve() const override; | ||
| void clip() const override; | ||
| void resetClip() const override; | ||
| void paint() const override; | ||
|
|
||
| // Line properties | ||
| void setLineWidth(double width) const override; | ||
| double getLineWidth() const override; | ||
| void setDash(const double* dashes, int num_dashes, double offset) const override; | ||
| void setFillRule(cairo_fill_rule_t fill_rule) const override; | ||
|
|
||
| // Color operations | ||
| void setSourceRGB(double r, double g, double b) const override; | ||
| void setSourceRGBA(double r, double g, double b, double a) const override; | ||
|
|
||
| // Text operations | ||
| void showText(const std::string& text) const override; | ||
| void setFontSize(double size) const override; | ||
| void selectFontFace(const std::string& family, cairo_font_slant_t slant, cairo_font_weight_t weight) const override; | ||
| void textExtents(const std::string& text, cairo_text_extents_t& extents) const override; | ||
|
|
||
| // Transformation operations | ||
| void identityMatrix() const override; | ||
| void translate(double x, double y) const override; | ||
| void scale(double sx, double sy) const override; | ||
| void rotate(double angle) const override; | ||
| void userToDevice(double& x, double& y) const override; | ||
|
|
||
| // Context state operations | ||
| void save() const override; | ||
| void restore() const override; | ||
|
|
||
| // Tolerance | ||
| void setTolerance(double tolerance) const override; | ||
|
|
||
| // Pango support | ||
| ecolab::Pango& pango() const override; | ||
|
|
||
| // TEMPORARY: Internal accessor for migration - to be removed once all implementations are updated | ||
| cairo_t* _internalGetCairoContext() const { return cairo; } | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #include "cairoShimCairo.xcd" | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Where is selectFontFace used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used in Group::draw(ICairoShim&) at line 1133 of model/group.cc for rendering the group title text with sans-serif italic font.