User Tools

Site Tools


drawing_with_script

====== Purpose ====== Scripts are able to manipulate icons and backgrounds in Lightning Launcher. It means that it is possible to generate some arbitrary content and display it as a shortcut icon, as an item background or as a folder window background. ====== How ====== The [[http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/Image.html|Image]] class is the entry point. Such an Image can be retrieved through [[http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/Shortcut.html#getImage%28%29|Shortcut.getImage]] or [[http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/Item.html#getBoxBackground%28java.lang.String%29|Item.getBoxBackground]], or [[http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/Folder.html#getWindowBackground%28%29|Folder.getWindowBackground]] for instance. Call the draw method on Image to obtain a Canvas object. The canvas is an android object (http://developer.android.com/reference/android/graphics/Paint.html) used to issue drawing operations on the Image. The canvas object offers a number of methods to draw lines, curves, path, bitmaps, gradients and text. This drawing tool is used system wide to draw the UI. Use the [[http://developer.android.com/reference/android/graphics/Path.html|Path]] object to draw complex shapes. Use [[http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/Image.html#getBitmap%28%29|Image.getBitmap]] to access the Android object in [[http://developer.android.com/reference/android/graphics/Canvas.html#drawBitmap%28android.graphics.Bitmap,%20float,%20float,%20android.graphics.Paint%29|Canvas.drawBitmap]]. Once drawing is done, call Image.update() to refresh the screen, or save() to persist the image to file (when appropriate). ====== Samples ====== ===== Copy an icon from an item to another item ===== <sxh javascript;> var i = LL.getCurrentDesktop().getItemByLabel("some item").getDefaultIcon(); LL.getEvent().getItem().setDefaultIcon(i); </sxh> ===== Paint a diagonal line over a coloured background ===== <sxh javascript;> // retrieve the image for the clicked item var i = LL.getEvent().getItem().getImage(); // create a paint object var p = new Paint(); p.setAntiAlias(true); p.setStrokeWidth(10); // retrieve the canvas var c = i.draw(); // fill with red c.drawARGB(255,255,0,0); // draw a line (10px thick, with antialiasing on) c.drawLine(0,0, i.getWidth(), i.getHeight(), p); // update so that changes are flipped to the screen i.update(); </sxh> ===== Draw the folder window background with a gradient ===== <sxh javascript;> var WIDTH = 512; var HEIGHT = 512; var i = LL.createImage(WIDTH,HEIGHT); LL.getOpenFolders().getAt(0).setBackground(i); var c = i.draw(); var g = new LinearGradient(0,0,WIDTH,HEIGHT,[0xff000000,0,0xffffffff],[0,0.5,1],Shader.TileMode.REPEAT); var p = new Paint(); p.setStyle(Paint.Style.FILL); p.setShader(g); c.drawRect(0,0,WIDTH,HEIGHT,p); i.update(); </sxh>

drawing_with_script.txt · Last modified: 2014/07/21 07:21 by pierrox