This tutorial explains how to use SVG artwork in a Ruby plasmoid and how to interact with it in the simplest way possible.
Perhaps the simplest SVG animation in Plasma is the visual emulation of a monochrome LCD panel as its elements do not move but are simply turned on and off to compose an understandable visual effect. And the simplest effect is blinking.
As we both do not yet know how to import and use an SVG picture we are going to build a very simple plasmoid and reuse an SVG from a non Ruby plasmoid. Then we'll ask a more experienced Ruby user on irc to fill in the blanks, without forcing them to write a time consuming complete Plasma Ruby SVG tutorial.
To understand the initial set-up you should read an introductory tutorial like Simple Paste Applet.
Notice that we downloaded the zipped svg file and placed it in the contents folder, to make sure we also (double) click the svgz file and see an actual picture, if you see semi random text you mistakenly downloaded a web page of the KDE archive instead of the picture file. The metadata.desktop file looks like this:
Name=Monochrome LCD demo
Comment=This is a very simplified applet written in Ruby
The main.rb initially looks like this:
class Main < PlasmaScripting::Applet def initialize parent super parent end
def init set_minimum_size 150, 150 end end
A working monochrome LCD plasmoid
After a more experienced Ruby programmer has expanded the code to include the SVG and to make the three zero digits blink on for half a second and then off for half a second, like an unset alarm clock, the code looks like this:
The homework assignment for us novice programmers is to compose the digits with different numbers, ok it's more or less a copy and paste job, but try to make your display display some fun stuff. This is all we need to program our own monochrome LCD plasmoids. In a next tutorial I'll explain how to create them with an SVG drawing application, as I've already played with SVG drawing.
Perhaps the experienced programmer has some more time to spare and can show us how our plasmoid can be made to respond to mouse clicks on the SVG elements. Well only if such interactions are even possible in a plain plasmoid. For our second applet we want to know how to interact with SVG so we want the blinker to blink only the most right digit when we click on any element of the last digit. And to blink the right two digits when we click the middle one and again all three digits when we press the left one. The code now looks like this:
SVG rendering is considered slow when compared to rendering PNG's. That is why during initiation or resizing of an SVG application the rendered SVG is sometimes cached as a bitmap or as multiple bitmaps, or sprites, which contains rendered elements as plain pixels which are kept and copied to a canvas which, once composition is complete, is painted over the bitmap being displayed in one go, making for an instant looking update of everything on the screen. Does plasma require some sort of canvas to compose elements on? And if so. Can you show us one or some versions of the blinking applet which uses bitmap caching?
Don't forget that I'm not asking you to write the tutorial, commenting your code should be sufficient for me to write a story about it.