.. meta:: :description: Unicon Graphics :keywords: unicon, icon, graphics ======== Graphics ======== .. Modified: 2019-10-20/19:44-0400 btiffin .. Copyright 2016 Brian Tiffin .. This file is part of the Unicon Programming document .. GPL 3.0+ :ref:`license` .. image:: images/unicon.png :align: center .. only:: html :ref:`genindex` :floatright:`Unicon` .. index:: graphics, gui .. _graphics: Unicon graphics --------------- Unicon has graphics built in, *well optionally built in, if the operating system supports X11, Win32 and/or OpenGL*. In the case of Unicon, graphics doesn't just mean colours drawn on a canvas. Unicon includes an entire Graphical User Interface engine as well. Graphics come in 2D and 3D forms. That means you can draw, and you can work with widgets and event driven programming without changing language or tool. Much of the callback management normally associated with event driven programming is handled by Unicon for many of the graphic operations. The design of the graphics features of Unicon allow for both procedural and event programming in a seamless way. Using graphics does not dictate an event driven only style of programming in Unicon. -------- .. index:: colors, colours .. _colours: Colours ------- Unicon uses a pretty nifty colour naming system, as English phrases. There are base colour names, with attributes for lightness, saturation and transparency levels. :: colour := "medium strong bluish green" Is parsed down to an RGBA (Red Green Blue Alpha) colour value. If the phrase is not understood, Unicon passes the name down to the operating system for another round of lookup. For X11 that means all the Xorg colour names are also valid. :ref:`Jafar` was nice enough to extract the pertinent bits from ``unicon/src/rwindow.r`` .. sourcecode:: c static colrname colortable[] = { /* known colors */ /* color ish-form hue lgt sat */ { "black", "blackish", 0, 0, 0 }, { "blue", "bluish", 240, 50, 100 }, { "brown", "brownish", 30, 25, 100 }, { "cyan", "cyanish", 180, 50, 100 }, { "gray", "grayish", 0, 50, 0 }, { "green", "greenish", 120, 50, 100 }, { "grey", "greyish", 0, 50, 0 }, { "magenta", "magentaish", 300, 50, 100 }, { "orange", "orangish", 15, 50, 100 }, { "pink", "pinkish", 345, 75, 100 }, { "purple", "purplish", 270, 50, 100 }, { "red", "reddish", 0, 50, 100 }, { "violet", "violetish", 270, 75, 100 }, { "white", "whitish", 0, 100, 0 }, { "yellow", "yellowish", 60, 50, 100 }, }; static colrmod lighttable[] = { /* lightness modifiers */ { "dark", 0 }, { "deep", 0 }, /* = very dark (see code) */ { "light", 100 }, { "medium", 50 }, { "pale", 100 }, /* = very light (see code) */ }; static colrmod sattable[] = { /* saturation levels */ { "moderate", 50 }, { "strong", 75 }, { "vivid", 100 }, { "weak", 25 }, }; static colrmod transptable[] = { /* transparency levels */ { "dull", 75 }, /* alias for subtranslucent */ { "opaque", 100 }, { "subtranslucent", 75 }, { "subtransparent", 25 }, { "translucent", 50 }, { "transparent", 5 }, }; Along with all those combinations, there are the system names, for things like Teal, and Cornflower, and Dark Khaki, when using X11. https://en.wikipedia.org/wiki/X11_color_names With a full list (many hundreds of named colours) in the source code at https://cgit.freedesktop.org/xorg/xserver/tree/os/oscolor.c *If you look closely, there are more than double the 50 Shades of Grey*. Other specific graphic subsystems will have their own list of available names. Unicon colour scheme .................... I've asked about an official Unicon project colour scheme, and I'm not sure if there has been an actual choice made. *I've even asked to put* ``unicon`` *in the list of known colours, for potential branding purposes (and cool code samples). That may never happen though, but it's worth asking.* From the project home page, *from September 2016*, the current guess is a form of orange (although the logo on that page uses a professionally laid out gradient, by Serendel Macphereson). Best (bad)\ [#designer]_ guess (vivid orange) shown below. .. literalinclude:: examples/colour-sample.icn :language: unicon :start-after: ##+ .. only:: html .. rst-class:: rightalign :download:`examples/colour-sample.icn` .. image:: images/colour-sample.png .. only:: html .. rst-class:: leftalign :download:`images/colour-sample.png` .. command-output:: unicon -s colour-sample.icn -x :cwd: examples .. [#designer] Do not mistake this author for a graphic designer. There are few design skills in these fingers and little artistic flair hiding behind the eyes. -------- .. index:: drawing Drawing ------- Points, lines, rectangles, circles, spheres, torus and more, are all part and parcel of Unicon graphics. As is text. The :ref:`write` statement can write to a graphical window as readily as it can write to standard output and to files. -------- Events ------ Event driven programming was never easier or more adaptable than with Unicon. -------- Attributes ---------- Unicon windows use a set of attributes to control look, feel and certain features of graphic handling. These attributes can be set during :ref:`open` and with the function :ref:`WAttrib`. The ``src/runtime/rwindow.r`` source file lists the following supported attributes. .. sourcecode:: c stringint attribs[] = { { 0, NUMATTRIBS}, {"ascent", A_ASCENT}, {"bg", A_BG}, {"buffer", A_BUFFERMODE}, {"canvas", A_CANVAS}, {"ceol", A_CEOL}, {"cliph", A_CLIPH}, {"clipw", A_CLIPW}, {"clipx", A_CLIPX}, {"clipy", A_CLIPY}, {"col", A_COL}, {"columns", A_COLUMNS}, {"cursor", A_CURSOR}, {"depth", A_DEPTH}, {"descent", A_DESCENT}, {"dim", A_DIM}, {"display", A_DISPLAY}, {"displayheight", A_DISPLAYHEIGHT}, {"displaywidth", A_DISPLAYWIDTH}, {"drawop", A_DRAWOP}, {"dx", A_DX}, {"dy", A_DY}, {"echo", A_ECHO}, {"eye", A_EYE}, {"eyedir", A_EYEDIR}, {"eyepos", A_EYEPOS}, {"eyeup", A_EYEUP}, {"fg", A_FG}, {"fheight", A_FHEIGHT}, {"fillstyle", A_FILLSTYLE}, {"font", A_FONT}, {"fovangle", A_FOV}, {"fwidth", A_FWIDTH}, {"gamma", A_GAMMA}, {"geometry", A_GEOMETRY}, {"glrenderer", A_GLRENDERER}, {"glvendor", A_GLVENDOR}, {"glversion", A_GLVERSION}, {"height", A_HEIGHT}, {"iconic", A_ICONIC}, {"iconimage", A_ICONIMAGE}, {"iconlabel", A_ICONLABEL}, {"iconpos", A_ICONPOS}, {"image", A_IMAGE}, {"inputmask", A_INPUTMASK}, {"label", A_LABEL}, {"leading", A_LEADING}, {"light", A_LIGHT}, {"light0", A_LIGHT0}, {"light1", A_LIGHT1}, {"light2", A_LIGHT2}, {"light3", A_LIGHT3}, {"light4", A_LIGHT4}, {"light5", A_LIGHT5}, {"light6", A_LIGHT6}, {"light7", A_LIGHT7}, {"lines", A_LINES}, {"linestyle", A_LINESTYLE}, {"linewidth", A_LINEWIDTH}, {"meshmode", A_MESHMODE}, {"normode", A_NORMODE}, {"pattern", A_PATTERN}, {"pick", A_PICK}, {"pointer", A_POINTER}, {"pointercol", A_POINTERCOL}, {"pointerrow", A_POINTERROW}, {"pointerx", A_POINTERX}, {"pointery", A_POINTERY}, {"pos", A_POS}, {"posx", A_POSX}, {"posy", A_POSY}, {"resize", A_RESIZE}, {"reverse", A_REVERSE}, {"rgbmode", A_RGBMODE}, {"rings", A_RINGS}, {"row", A_ROW}, {"rows", A_ROWS}, {"selection", A_SELECTION}, {"size", A_SIZE}, {"slices", A_SLICES}, {"texcoord", A_TEXCOORD}, {"texmode", A_TEXMODE}, {"texture", A_TEXTURE}, {"titlebar", A_TITLEBAR}, {"visual", A_VISUAL}, {"width", A_WIDTH}, {"windowlabel", A_WINDOWLABEL}, {"x", A_X}, {"y", A_Y}, }; -------- .. index:: vidgets Vidgets ------- For lack of a better term for Graphical User Interface (:ref:`GUI `) elements, Unicon includes a rich set of ready to go widgets. Some few built in, many as part of the :ref:`IPL ` as ``vidgets`` and with the Unicon gui classes. .. literalinclude:: examples/vidget-button.icn :language: unicon :start-after: ##+ .. only:: html .. rst-class:: rightalign :download:`examples/vidget-button.icn` .. image:: images/vidget-button.png .. only:: html .. rst-class:: leftalign :download:`images/vidget-button.png` The sample simulates a mouse click, invoking the ``hello`` procedure. .. command-output:: unicon -s vidget-button.icn -x :cwd: examples .. index:: vidget, widget On names ........ Icon was developed long before modern graphical desktops were mainstream. There is still no ubiquitous term for graphic elements, but ``widget`` seems to be well understood. When Clint Jeffery was working with Ralph Griswold on the early graphics features of Icon, even the term widget was not in common use. The Icon (now Unicon) team went with a portmanteau of Visual Gadget, ``vidget``. Things change, but history stays the same. Unicon classes allow for a modernized approach to :ref:`GUI ` development. -------- .. index:: gui .. _gui: Unicon GUI ---------- .. todo:: samples of Robert Parlett's GUI classes -------- Plot coordinate pairs --------------------- A nice example of Unicon graphics can be found at :ref:`Rosetta Code ` under the ``Plot coordinate pairs`` task. Duplicated here from a copy taken in August of 2016 *with some slight modifications to captured image name, and not waiting for a mouse click to end the run*. .. literalinclude:: examples/plotpairs.icn :language: unicon :start-after: ##+ .. only:: html .. rst-class:: rightalign :download:`examples/plotpairs.icn` A nice feature of Unicon is the :ref:`WriteImage` graphics function. It saves a canvas image in GIF, JPG, BMP or PNG format (depending on given filename extension, including system specific types like XBM, XPM). That handy function is used to generate ``PlotPairs.png`` (and most of the other images) during builds of this documentation. .. command-output:: unicon -s plotpairs.icn -x :cwd: examples .. image:: images/PlotPairs.png .. only:: html .. rst-class:: leftalign :download:`images/PlotPairs.png` .. only:: html .. -------- :ref:`genindex` | Previous: :doc:`objects` | Next: :doc:`database` |