Difference between revisions of "Simpledisplay.d"

From D Wiki
Jump to: navigation, search
m (event handlers must all be delegates)
Line 3: Line 3:
 
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.)
 
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:
+
== Feature ==
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/simpledisplay.d
+
* 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
  
depends on:
 
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/color.d
 
  
Features:
+
== Example ==
  * 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:
 
  
 
<syntaxhighlight lang="D">
 
<syntaxhighlight lang="D">
Line 49: Line 43:
  
  
More advanced features:
+
== More advanced features ==
  
 
* clipboard text copy/paste, and PRIMARY selection on X
 
* clipboard text copy/paste, and PRIMARY selection on X
Line 67: Line 61:
 
* decorationless windows
 
* decorationless windows
 
* notification area icons
 
* notification area icons
 +
 +
== References ==
 +
* [https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/simpledisplay.d Code ]
 +
* [https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/color.d Dependencies]
 +
 +
 +
[[Category:GUI Libraries]]

Revision as of 19:43, 1 September 2015

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.)

Feature

  • 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

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
     delegate(KeyEvent ke) {
         // key pressed or released
     },
     delegate(dchar character) {
        // character pressed
     },
     delegate(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

References