changeset: 4:c10b3ecd18e9
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Tue Jul 27 13:40:31 2010 +0100
files: Makefile draw.h drawbox.c drawtext.c drawtextn.c
description:
separated drawbox and drawtext, added drawtextn
diff -r b3aa07ccca94 -r c10b3ecd18e9 Makefile
--- a/Makefile Fri Jul 02 05:50:18 2010 +0100
+++ b/Makefile Tue Jul 27 13:40:31 2010 +0100
@@ -3,8 +3,9 @@
include config.mk
-SRC = cleanupdraw.c commitdraw.c drawcursor.c drawsquare.c drawtext.c eprint.c \
- getcolor.c initfont.c setupdraw.c textnw.c textw.c
+SRC = cleanupdraw.c commitdraw.c drawbox.c drawcursor.c drawsquare.c \
+ drawtext.c drawtextn.c eprint.c getcolor.c initfont.c setupdraw.c \
+ textnw.c textw.c
OBJ = ${SRC:.c=.o}
all: options libdraw.a
diff -r b3aa07ccca94 -r c10b3ecd18e9 draw.h
--- a/draw.h Fri Jul 02 05:50:18 2010 +0100
+++ b/draw.h Tue Jul 27 13:40:31 2010 +0100
@@ -29,9 +29,11 @@
/* forward declarations */
void cleanupdraw(DC *dc);
void commitdraw(DC *dc, Window w);
+void drawbox(DC *dc, unsigned long col[ColLast]);
void drawcursor(DC *dc, const char *text, size_t pos, unsigned long col[ColLast]);
void drawsquare(DC *dc, Bool filled, unsigned long col[ColLast]);
void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
+void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
void eprint(const char *fmt, ...);
unsigned long getcolor(DC *dc, const char *colstr);
void initfont(DC *dc, const char *fontstr);
diff -r b3aa07ccca94 -r c10b3ecd18e9 drawbox.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/drawbox.c Tue Jul 27 13:40:31 2010 +0100
@@ -0,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+#include <X11/Xlib.h>
+#include <draw.h>
+
+void
+drawbox(DC *dc, unsigned long col[ColLast]) {
+ XRectangle r = { dc->x, dc->y, dc->w, dc->h };
+
+ XSetForeground(dc->dpy, dc->gc, BG(dc, col));
+ XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
+}
diff -r b3aa07ccca94 -r c10b3ecd18e9 drawtext.c
--- a/drawtext.c Fri Jul 02 05:50:18 2010 +0100
+++ b/drawtext.c Tue Jul 27 13:40:31 2010 +0100
@@ -1,36 +1,8 @@
/* See LICENSE file for copyright and license details. */
#include <string.h>
-#include <X11/Xlib.h>
#include <draw.h>
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
void
drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
- char buf[256];
- int i, x, y, h, len, olen;
- XRectangle r = { dc->x, dc->y, dc->w, dc->h };
-
- XSetForeground(dc->dpy, dc->gc, BG(dc, col));
- XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
- if(!text || !*text)
- return;
- olen = strlen(text);
- h = dc->font.height;
- y = dc->y + ((h+2) / 2) - (h / 2) + dc->font.ascent;
- x = dc->x + (h / 2);
- /* shorten text if necessary */
- for(len = MIN(olen, sizeof buf); len && textnw(dc, text, len) > dc->w - h; len--);
- if(!len)
- return;
- memcpy(buf, text, len);
- if(len < olen)
- for(i = len; i && i > len - 3; buf[--i] = '.');
- XSetForeground(dc->dpy, dc->gc, FG(dc, col));
- if(dc->font.set)
- XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len);
- else {
- XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
- XDrawString(dc->dpy, dc->drawable, dc->gc, x, y, buf, len);
- }
+ drawtextn(dc, text, text ? strlen(text) : 0, col);
}
diff -r b3aa07ccca94 -r c10b3ecd18e9 drawtextn.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/drawtextn.c Tue Jul 27 13:40:31 2010 +0100
@@ -0,0 +1,31 @@
+/* See LICENSE file for copyright and license details. */
+#include <string.h>
+#include <X11/Xlib.h>
+#include <draw.h>
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
+void
+drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) {
+ char buf[256];
+ int i, x, y, h;
+ size_t mn;
+
+ h = dc->font.height;
+ y = dc->y + ((h+2) / 2) - (h / 2) + dc->font.ascent;
+ x = dc->x + (h / 2);
+ /* shorten text if necessary */
+ for(mn = MIN(n, sizeof buf); mn && textnw(dc, text, mn) > dc->w - h; mn--);
+ if(!mn)
+ return;
+ memcpy(buf, text, mn);
+ if(mn < n)
+ for(i = mn; i && i > mn - 3; buf[--i] = '.');
+ XSetForeground(dc->dpy, dc->gc, FG(dc, col));
+ if(dc->font.set)
+ XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, mn);
+ else {
+ XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
+ XDrawString(dc->dpy, dc->drawable, dc->gc, x, y, buf, mn);
+ }
+}
Received on Tue Jul 27 2010 - 14:40:38 CEST
This archive was generated by hypermail 2.2.0 : Tue Jul 27 2010 - 14:48:04 CEST