Difference between revisions of "Simpledisplay.d"
(initial documentation of my module) |
(→Feature) |
||
(3 intermediate revisions by 2 users not shown) | |||
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.) | ||
− | + | == 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 == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | Example | ||
+ | <syntaxhighlight lang="D"> | ||
import simpledisplay; | import simpledisplay; | ||
void main() { | void main() { | ||
Line 30: | Line 24: | ||
// do an event loop to show it and collect input | // do an event loop to show it and collect input | ||
window.eventLoop(0, // the 0 is a timer if you want approximate frames | window.eventLoop(0, // the 0 is a timer if you want approximate frames | ||
− | (KeyEvent ke) { | + | delegate(KeyEvent ke) { |
// key pressed or released | // key pressed or released | ||
}, | }, | ||
− | (dchar character) { | + | delegate(dchar character) { |
// character pressed | // character pressed | ||
}, | }, | ||
− | (MouseEvent me) { | + | delegate(MouseEvent me) { |
// mouse moved or clicked | // mouse moved or clicked | ||
} | } | ||
); | ); | ||
} | } | ||
− | + | </syntaxhighlight> | |
Drawing functions: see struct ScreenPainter | Drawing functions: see struct ScreenPainter | ||
Line 48: | Line 42: | ||
− | 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 66: | Line 60: | ||
* 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]] |
Latest 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