Simpledisplay.d

From D Wiki
Revision as of 23:19, 7 October 2013 by Adr (talk | contribs) (initial documentation of my module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

About my simpledisplay.d

It is a little library that gives access to simple windows on MS Windows and on X11 with minimal dependencies. (There's some Mac OS Cocoa code in there, but it is unmaintained because I don't have a Mac.)

code: https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/simpledisplay.d

depends on: https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/color.d

Features:

  * you can create images by writing pixels in a regular format (MemoryImage) or using some operating system APIs (class Image and class Sprite)
  * easily create a window and draw on them or get events from them
  * build more on top of the window


Example program:

import simpledisplay; void main() {

  // create a window easily
  auto window = new SimpleWindow(500 /* width */, 500 /* height */);
  {
      // draw on the window. it double buffers automatically, so you want it to go out of scope to show changes
      auto painter = window.draw();
      painter.outlineColor = Color.green;
      painter.drawLine(Point(0, 0), Point(500, 500));
  }
  // do an event loop to show it and collect input
  window.eventLoop(0, // the 0 is a timer if you want approximate frames
    (KeyEvent ke) {
        // key pressed or released
    },
    (dchar character) {
       // character pressed
    },
    (MouseEvent me) {
       // mouse moved or clicked
    }
  );

}


Drawing functions: see struct ScreenPainter

MemoryImages are in color.d and my other modules like png.d and bmp.d can load files into them.


More advanced features:

  • clipboard text copy/paste, and PRIMARY selection on X
  • window resize handling: pass Resizability.allowResizing to the constructor, set a handler on window.windowResized
  • some OpenGL: pass OpenGlOptions.yes to the constructor. Compile with version=with_opengl on windows and have glu32.lib ready.
  • hook native events: set delegate to window.handleNativeEvent
  • open multiple windows at once
  • window.title = "something"; to rename window
  • window.icon = some_memory_image; to change window icon
  • integration with generic arsd.eventloop on Linux
  • a bunch of Windows and Xlib functions are prototyped as well
  • the event loop on Windows also calls SleepEx to clear pending async I/O for you
  • class Sprite is a pixmap for more efficient usage on X

Might (might!) be coming:

  • joystick input
  • decorationless windows
  • notification area icons