aboutsummaryrefslogtreecommitdiffstats
path: root/src/xlib.c
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-24 23:54:54 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-24 23:54:54 -0700
commitae22db5d707dd2728bbdf4d2f70d7d9285017024 (patch)
tree56f5fa0aec8e3a5d10ad582bc080658115f23a66 /src/xlib.c
parent29510850182646a62d7969641edd8265a8cfc7ac (diff)
downloadmirror-meh-ae22db5d707dd2728bbdf4d2f70d7d9285017024.tar.gz
mirror-meh-ae22db5d707dd2728bbdf4d2f70d7d9285017024.tar.bz2
mirror-meh-ae22db5d707dd2728bbdf4d2f70d7d9285017024.zip
cleanup
Diffstat (limited to 'src/xlib.c')
-rw-r--r--src/xlib.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/src/xlib.c b/src/xlib.c
index 57a7581..5023cbd 100644
--- a/src/xlib.c
+++ b/src/xlib.c
@@ -86,53 +86,43 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height) {
}
-void drawimage(struct image *img, unsigned int width, unsigned int height){
- static struct image *lastimg = NULL;
- static int lastwidth = 0, lastheight = 0;
- static XImage *ximg = NULL;
- if(0 && img == lastimg && width == lastwidth && height == lastheight){
+XImage *getimage(struct image *img, int width, int height){
+ if(width * img->height > height * img->width){
+ return ximage(img, img->width * height / img->height, height);
}else{
- if(ximg)
- XDestroyImage(ximg);
- lastwidth = width;
- lastheight = height;
- lastimg = img;
- if(width * img->height > height * img->width){
- ximg = ximage(img, img->width * height / img->height, height);
- }else{
- ximg = ximage(img, width, img->height * width / img->width);
- }
+ return ximage(img, width, img->height * width / img->width);
}
- assert(ximg);
- {
- XRectangle rects[2];
- int yoffset, xoffset;
- xoffset = (width - ximg->width) / 2;
- yoffset = (height - ximg->height) / 2;
- if(xoffset || yoffset){
- rects[0].x = rects[0].y = 0;
- if(xoffset){
- rects[0].width = rects[1].width = xoffset;
- rects[0].height = rects[1].height = height;
- rects[1].x = width-xoffset;
- rects[1].y = 0;
- }else if(yoffset){
- rects[0].width = rects[1].width = width;
- rects[0].height = rects[1].height = yoffset;
- rects[1].x = 0;
- rects[1].y = height - yoffset;
- }
- XFillRectangles(display, window, gc, rects, 2);
+}
+
+void drawimage(XImage *ximg, unsigned int width, unsigned int height){
+ XRectangle rects[2];
+ int yoffset, xoffset;
+ xoffset = (width - ximg->width) / 2;
+ yoffset = (height - ximg->height) / 2;
+ if(xoffset || yoffset){
+ rects[0].x = rects[0].y = 0;
+ if(xoffset){
+ rects[0].width = rects[1].width = xoffset;
+ rects[0].height = rects[1].height = height;
+ rects[1].x = width-xoffset;
+ rects[1].y = 0;
+ }else if(yoffset){
+ rects[0].width = rects[1].width = width;
+ rects[0].height = rects[1].height = yoffset;
+ rects[1].x = 0;
+ rects[1].y = height - yoffset;
}
- XPutImage(display, window, gc, ximg, 0, 0, xoffset, yoffset, ximg->width, ximg->height);
- XFlush(display);
+ XFillRectangles(display, window, gc, rects, 2);
}
+ XPutImage(display, window, gc, ximg, 0, 0, xoffset, yoffset, ximg->width, ximg->height);
+ XFlush(display);
}
void setaspect(unsigned int w, unsigned int h){
XSizeHints *hints = XAllocSizeHints();
- hints->flags = PAspect;
+ //hints->flags = PAspect;
+ hints->flags = 0;
hints->min_aspect.x = hints->max_aspect.x = w;
hints->min_aspect.y = hints->max_aspect.y = h;
XSetWMNormalHints(display, window, hints);