From 84956f9086a9285e2347f13516eabb9ed5f35f27 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Tue, 11 Jun 2013 13:05:44 -0400 Subject: [PATCH] catch up --- README | 44 ++++++++++++++++++++++++++++++-------------- color.d | 10 +++++----- image.d | 2 +- simpledisplay.d | 42 ++++++++++++++++++++++++++---------------- 4 files changed, 62 insertions(+), 36 deletions(-) diff --git a/README b/README index 1d683f5..404c8db 100644 --- a/README +++ b/README @@ -8,19 +8,17 @@ Read more about the modules at these links (docs are still works in process): cgi.d info: http://arsdnet.net/web.d/cgi.d.html web.d info: http://arsdnet.net/web.d/web.d.html - -Recent bigger changes: - web.d can now accept file uploads via hackish thing - make a param with type "Cgi.UploadedFile" - Currently included are: Web related ================ -cgi.d - base module for making webapps in D +cgi.d - base module for making webapps in D. Supports cgi, fastcgi, scgi, and embedded_httpd via -version=xxxx dom.d - an xml/html DOM based on what Javascript provides in browsers web.d - a fancier way to write web apps. Uses reflection to make functions accessible via url with minimal boilerplate in your code +email.d - gives read and write support for emails, sending via SMTP and + reading mbox files web.d.php - a PHP library meant to ease integration of php components with web.d apps. Gives (read) access to the session, and full @@ -29,20 +27,27 @@ web.d.php - a PHP library meant to ease integration of php components html.d - functions to manipulate HTML documents, and now css and javascript with DOM functions, nested css statements, and macros for css and js. +oauth.d - Oauth 1.0 implementation with some helper functions for facebook, twitter, etc. +htmltotext.d - converts html into plain text + +rtud.d - a real time update helper for HTML5 EventSource. Kinda buggy. + Database related ================ database.d - main interface to databases. Includes DataObject -mysql.d - a mysql engine for database.d (most mature of the three) +mysql.d - a mysql engine for database.d (most mature of the three). also includes some basic ORM postgres.d - a postgres engne for database.d sqlite.d - a sqlite engine for database.d mssql.d - a (super crappy) mssql engine for database.d (uses ODBC) +querygenerator.d - a user submission for generating sql queries Desktop app stuff ================ simpledisplay.d - gives quick and easy access to a window for drawing -simpleaudio.d - gives minimal audio output +htmlwidget.d - a very small html widget, built on simpledisplay.d +terminal.d - quick and easy access to a text mode console/terminal Game stuff ================= @@ -58,27 +63,38 @@ engine.d, screen.d, audio.d - a quick wrapper to SDL and OpenGL I used Other ================ +eventloop.d - first draft of a generic event loop that can be reused by several libraries + try it with terminal.d or simpledisplay.d with -version=with_eventloop. Only + works on Linux right now. sha.d - implementations of the SHA1 and SHA256 algorithms +image.d - generic image class that can be drawn upon (coming soon) or loaded/written by png.d png.d - provides some png read/write support +jpg.d - just reading jpg header right now curl.d - a small wrapper around the curl library csv.d - gives read support to csv files http.d - a lighterweight alternative to curl.d - color.d - a basic color struct and some HSL functions +characterencodings.d - conversion to UTF8 of various encodings +Obsolete +================ +lazypng.d - now merged into png.d +httpd.d - old http server, use cgi.d with -version=embedded_httpd instead +netman.d - old network helper code, you should try vibe.d or maybe + cgi.d's threaded thing instead since this one is now unmaintained and poor in + quality compared to vibe anyway. +domconvenience.d - now merged into dom.d -Things I might add once I clean up the files (this can be expedited upon -request, to an extent): -htmlwidget.d - a very small html widget +Things I'll add when I get the time: + browser.d - a tiny browser based on htmlwidget.d -netman.d - old code handles net connections (required by httpd.d) -imagedraft.d - (temporary name) has algorithms for images bmp.d - gives .bmp read/write -dws.d - a draft of my D windowing system (also includes some Qt code) wav.d - reading and writing WAV files midi.d - reading and writing MIDI files +simpleaudio.d - gives minimal audio output +minimal.zip - a set of minimal D functions, works on bare metal. see: http://arsdnet.net/dcode/minimal.zip Authors: diff --git a/color.d b/color.d index d9d4e0b..0427a47 100644 --- a/color.d +++ b/color.d @@ -1,8 +1,8 @@ module arsd.color; -import std.math; -import std.conv; -import std.algorithm; +import std.math : abs; +import std.conv : to; +import std.algorithm : startsWith, min, max; import std.string : strip, split; struct Color { @@ -35,7 +35,7 @@ struct Color { */ string toCssString() { - import std.string; + import std.string : format; if(a == 255) return format("#%02x%02x%02x", r, g, b); else @@ -43,7 +43,7 @@ struct Color { } string toString() { - import std.string; + import std.string : format; if(a == 255) return format("%02x%02x%02x", r, g, b); else diff --git a/image.d b/image.d index 0fb1ae5..13a7662 100644 --- a/image.d +++ b/image.d @@ -19,7 +19,7 @@ module arsd.image; */ -import arsd.color; +public import arsd.color; interface Image { //IndexedImage convertToIndexedImage() const; diff --git a/simpledisplay.d b/simpledisplay.d index 8506a0a..8f550a9 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -2,6 +2,8 @@ module simpledisplay; /* Stuff to add: + take a screenshot function! + Pens and brushes? Maybe a global event loop? @@ -23,12 +25,6 @@ version(html5) {} else { version = X11; } -import std.exception; -import core.thread; -import std.string; // FIXME: move to drawText X11 on next dmd - -import std.stdio; - public import arsd.color; // no longer stand alone... :-( but i need a common type for this to work with images easily. struct Point { @@ -363,13 +359,16 @@ class Sprite { ubyte* rawData; // FIXME: this should prolly be a device dependent bitmap... - handle = enforce(CreateDIBSection( + handle = CreateDIBSection( null, &infoheader, DIB_RGB_COLORS, cast(void**) &rawData, null, - 0)); + 0); + + if(handle is null) + throw new Exception("couldn't create pixmap"); auto itemsPerLine = ((cast(int) width * 3 + 3) / 4) * 4; auto arrLength = itemsPerLine * height; @@ -554,9 +553,6 @@ class SimpleWindow { /* Additional utilities */ -import std.conv; -import std.math; - Color fromHsl(real h, real s, real l) { return arsd.color.fromHsl([h,s,l]); } @@ -565,7 +561,6 @@ Color fromHsl(real h, real s, real l) { /* ********** What follows is the system-specific implementations *********/ version(Windows) { - import std.string; SimpleWindow[HWND] windowObjects; @@ -782,6 +777,7 @@ version(Windows) { if(!RegisterClass(&wc)) throw new Exception("RegisterClass"); + import std.string : toStringz; hwnd = CreateWindow(cn, toStringz(title), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, null, null, hInstance, null); @@ -896,6 +892,8 @@ version(Windows) { MSG message; int ret; + import core.thread; + if(pulseTimeout) { bool done = false; while(!done) { @@ -993,13 +991,15 @@ version(Windows) { infoheader.bmiHeader.biBitCount = 24; infoheader.bmiHeader.biCompression = BI_RGB; - handle = enforce(CreateDIBSection( + handle = CreateDIBSection( null, &infoheader, DIB_RGB_COLORS, cast(void**) &rawData, null, - 0)); + 0); + if(handle is null) + throw new Exception("create image failed"); } @@ -1016,7 +1016,6 @@ version(X11) { alias Window NativeWindowHandle; enum KEY_ESCAPE = 9; - import core.stdc.stdlib; mixin template NativeScreenPainterImplementation() { Display* display; @@ -1105,6 +1104,7 @@ version(X11) { } void drawText(int x, int y, int x2, int y2, string text) { + import std.string : split; foreach(line; text.split("\n")) { XDrawString(display, d, gc, x, y + 12, line.ptr, cast(int) line.length); y += 16; @@ -1178,7 +1178,9 @@ version(X11) { if(window !is null) this.window = window; if(display is null) { - display = enforce(XOpenDisplay(null)); + display = XOpenDisplay(null); + if(display is null) + throw new Exception("Unable to open X display"); version(with_eventloop) { import arsd.eventloop; addFileEventListeners(display.fd, &eventListener, null, null); @@ -1199,6 +1201,9 @@ version(X11) { } static void close() { + if(display is null) + return; + version(with_eventloop) { import arsd.eventloop; removeFileEventListeners(display.fd); @@ -1218,6 +1223,7 @@ version(X11) { auto screen = DefaultScreen(display); // This actually needs to be malloc to avoid a double free error when XDestroyImage is called + import core.stdc.stdlib : malloc; rawData = cast(ubyte*) malloc(width * height * 4); handle = XCreateImage( @@ -1232,6 +1238,8 @@ version(X11) { } void dispose() { + // note: this calls free(rawData) for us + if(handle) XDestroyImage(handle); } @@ -1348,6 +1356,7 @@ version(X11) { int eventLoop(long pulseTimeout) { bool done = false; + import core.thread; while (!done) { while(!done && @@ -3252,6 +3261,7 @@ version(html5) { int eventLoop(long pulseTimeout) { bool done = false; + import core.thread; while (!done) { while(!done &&