Skip to content

Commit

Permalink
Sim: Update hack-canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
Octal450 committed Oct 28, 2024
1 parent f44d34d commit e3acd9d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions DC-10-main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@
</pts>
<libraries>
<file>Aircraft/DC-10/Nasal/libraries.nas</file>
<file>Aircraft/DC-10/Nasal/hack-canvas.nas</file>
<file>Aircraft/DC-10/Nasal/thunder-effects.nas</file>
<file>Aircraft/DC-10/Nasal/view-controller.nas</file>
</libraries>
Expand Down
77 changes: 77 additions & 0 deletions Nasal/hack-canvas.nas
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Hack Canvas
# Authors: Nikolai V. Chr., Josh Davidson (Octal450)
# Inspired from what Thorsten did with setTextUpdate()
# All these methods return me so they can be chained
# This file should be loaded before any canvas use

# Element
canvas.Element._lastVisible = nil;
canvas.Element.show = func() {
if (1 == me._lastVisible) {
return me;
}
me._lastVisible = 1;
me.setBool("visible", 1);
};
canvas.Element.hide = func() {
if (0 == me._lastVisible) {
return me;
}
me._lastVisible = 0;
me.setBool("visible", 0);
};
canvas.Element.setVisible = func(vis) {
if (vis == me._lastVisible) {
return me;
}
me._lastVisible = vis;
me.setBool("visible", vis);
};

# Path
canvas.Path._lastColor = nil;
canvas.Path.setColor = func() {
me._newColor = canvas._getColor(arg);
if (me._newColor == me._lastColor) {
return me;
}
me._lastColor = me._newColor;
me.setStroke(me._newColor);
};
canvas.Path._lastColorFill = nil;
canvas.Path.setColorFill = func() {
me._newColorFill = canvas._getColor(arg);
if (me._newColorFill == me._lastColorFill) {
return me;
}
me._lastColorFill = me._newColorFill;
me.setFill(me._newColorFill);
};

# Text
canvas.Text._lastColor = nil;
canvas.Text.setColor = func() {
me._newColor = canvas._getColor(arg);
if (me._newColor == me._lastColor) {
return me;
}
me._lastColor = me._newColor;
me.set("fill", me._newColor);
};
canvas.Text._lastColorFill = nil;
canvas.Text.setColorFill = func() {
me._newColorFill = canvas._getColor(arg);
if (me._newColorFill == me._lastColorFill) {
return me;
}
me._lastColorFill = me._newColorFill;
me.set("background", me._newColorFill);
};
canvas.Text._lastText = canvas.Text["_lastText"];
canvas.Text.setText = func(text) {
if (text == me._lastText and text != nil and size(text) == size(me._lastText)) {
return me;
}
me._lastText = text;
me.set("text", typeof(text) == "scalar" ? text : "");
};

0 comments on commit e3acd9d

Please sign in to comment.