summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Marchesin <stephane.marchesin@gmail.com>2010-05-06 20:18:46 -0700
committerStephane Marchesin <stephane.marchesin@gmail.com>2010-05-06 20:18:46 -0700
commite206b83d96d7c247c19df36e1083b69588f7473a (patch)
tree5a682b71764cffeb9cb02f118295e83701ef251e
parentb296bdd13c2e326096d5ef777cb933ed91f20556 (diff)
Start implementing XParseColor
-rw-r--r--damage.c2
-rw-r--r--draw.h1
-rw-r--r--tests/rect.c2
-rw-r--r--xenon.h3
-rw-r--r--xlib_api.c41
5 files changed, 41 insertions, 8 deletions
diff --git a/damage.c b/damage.c
index 6702c33..5ad38ed 100644
--- a/damage.c
+++ b/damage.c
@@ -1,5 +1,5 @@
#include "draw.h"
-#include "xenon.h"
+#include "util.h"
static xenon_rect current_rect;
diff --git a/draw.h b/draw.h
index 399a76a..c7445d4 100644
--- a/draw.h
+++ b/draw.h
@@ -21,6 +21,7 @@ extern xenon_rect screen_rect;
extern void draw_point(GC gc, int x, int y);
extern void draw_rectangle(GC gc, xenon_rect* r);
+extern void draw_image(GC gc, XImage* image, xenon_rect area, int x, int y);
#endif
diff --git a/tests/rect.c b/tests/rect.c
index 86dfac2..db66834 100644
--- a/tests/rect.c
+++ b/tests/rect.c
@@ -31,12 +31,10 @@ int main() {
XAllocColor(dis, colormap, &green_col);
XSetForeground(dis, green_gc, green_col.pixel);
- printf("select input\n");
XSelectInput(dis, win, ExposureMask | KeyPressMask | ButtonPressMask);
XDrawRectangle(dis, win, green_gc, 1, 1, 247, 247);
XDrawRectangle(dis, win, green_gc, 50, 50, 148, 148);
- printf("flush\n");
XFlush(dis);
sleep(5);
diff --git a/xenon.h b/xenon.h
index 0b2141f..2af7ffb 100644
--- a/xenon.h
+++ b/xenon.h
@@ -7,7 +7,4 @@
#include <stdlib.h>
#include <stdio.h>
-#define min(a,b) ((a)<(b)?(a):(b))
-#define max(a,b) ((a)>(b)?(a):(b))
-
#endif
diff --git a/xlib_api.c b/xlib_api.c
index 351d058..67f13c5 100644
--- a/xlib_api.c
+++ b/xlib_api.c
@@ -3,7 +3,9 @@
#include "window.h"
#include "display.h"
#include "damage.h"
+#include "render.h"
#include "draw.h"
+#include "util.h"
Status XAllocColor(
Display* display,
@@ -190,7 +192,42 @@ Status XParseColor(
XColor* exact_def_return
)
{
- printf("parse color ok\n");
+ unsigned short r,g,b;
+ if (!spec)
+ return BadValue;
+ if (spec[0] == '#')
+ {
+ switch(strlen(spec))
+ {
+ case 4:
+ r = hexval(spec[1]) << 12;
+ g = hexval(spec[2]) << 12;
+ b = hexval(spec[3]) << 12;
+ break;
+ case 7:
+ r = ( hexval(spec[1]) << 12 ) + ( hexval(spec[2]) << 8 );
+ g = ( hexval(spec[3]) << 12 ) + ( hexval(spec[4]) << 8 );
+ b = ( hexval(spec[5]) << 12 ) + ( hexval(spec[6]) << 8 );
+ break;
+ case 10:
+ r = ( hexval(spec[1]) << 12 ) + ( hexval(spec[2]) << 8 ) + ( hexval(spec[3]) << 4 );
+ g = ( hexval(spec[4]) << 12 ) + ( hexval(spec[5]) << 8 ) + ( hexval(spec[6]) << 4 );
+ b = ( hexval(spec[7]) << 12 ) + ( hexval(spec[8]) << 8 ) + ( hexval(spec[9]) << 4 );
+ break;
+ case 13:
+ r = ( hexval(spec[1]) << 12 ) + ( hexval(spec[2]) << 8 ) + ( hexval(spec[3]) << 4 ) + hexval(spec[4]);
+ g = ( hexval(spec[5]) << 12 ) + ( hexval(spec[6]) << 8 ) + ( hexval(spec[7]) << 4 ) + hexval(spec[8]);
+ b = ( hexval(spec[9]) << 12 ) + ( hexval(spec[10]) << 8 ) + ( hexval(spec[11]) << 4 ) + hexval(spec[12]);
+ break;
+ default:
+ return BadValue;
+ }
+ printf("parse color ok %x-%x-%x\n",r>>8,g>>8,b>>8);
+ }
+ else
+ {
+ return BadValue;
+ }
}
int XPutImage(
@@ -216,7 +253,7 @@ int XPutImage(
handle = dlopen("/usr/lib/libX11.so.6", RTLD_LAZY);
if (!handle)
printf("can't open libX11\n");
- typedef GC (* XPutImagefunc) (Display*, Drawable, GC, XImage*, int, int, int, int, unsigned, unsigned);
+ typedef int (* XPutImagefunc) (Display*, Drawable, GC, XImage*, int, int, int, int, unsigned, unsigned);
XPutImagefunc XPutImagereal = dlsym(handle, "XPutImage");
return XPutImagereal(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height);
}