Browse Source

Clean up getColor function

master
Wesley Kerfoot 6 years ago
parent
commit
ca9db1a599
  1. 42
      blit.c

42
blit.c

@ -20,19 +20,25 @@ getDisplay() {
return display; return display;
} }
XColor XColor*
getColor(unsigned short red, getColor(Display *display,
int screen,
unsigned short red,
unsigned short green, unsigned short green,
unsigned short blue) { unsigned short blue) {
/* Return a new XColor structure */ /* Return a new XColor structure */
/* Initialize it with RGB */ /* Initialize it with RGB */
XColor xcolor;
xcolor.red = red; XColor *xcolor = malloc(sizeof (XColor));
xcolor.green = green;
xcolor.blue = blue;
xcolor.flags = DoRed | DoGreen | DoBlue; xcolor->red = red;
xcolor->green = green;
xcolor->blue = blue;
xcolor->flags = DoRed | DoGreen | DoBlue;
XAllocColor(display,
XDefaultColormap(display, screen),
xcolor);
return xcolor; return xcolor;
} }
@ -42,19 +48,11 @@ main(void) {
Window window; Window window;
XEvent event; XEvent event;
const char *msg = "Hello, world!\n";
XColor xcolor = getColor(0xffff, 0xffff, 0xffff);
Display *display = getDisplay(); Display *display = getDisplay();
int screen = DefaultScreen(display); int screen = DefaultScreen(display);
GC gc = XDefaultGC(display, screen); GC gc = XDefaultGC(display, screen);
XAllocColor(display, XColor *xcolor = getColor(display, screen, 0xffff, 0xffff, 0xffff);
XDefaultColormap(display, screen),
&xcolor);
window = XCreateSimpleWindow(display, window = XCreateSimpleWindow(display,
RootWindow(display, screen), RootWindow(display, screen),
@ -64,9 +62,7 @@ main(void) {
100, 100,
1, 1,
WhitePixel(display, screen), WhitePixel(display, screen),
xcolor.pixel); xcolor->pixel);
printf("%p\n", window);
XSelectInput(display, XSelectInput(display,
window, window,
@ -98,13 +94,9 @@ main(void) {
XNextEvent(display, &event); XNextEvent(display, &event);
if (event.type == Expose) { if (event.type == Expose) {
XColor boxcolor = getColor(32000, 0, 32000); XColor *boxcolor = getColor(display, screen, 32000, 0, 32000);
XAllocColor(display,
XDefaultColormap(display, screen),
&boxcolor);
XSetForeground(display, gc, boxcolor.pixel); XSetForeground(display, gc, boxcolor->pixel);
} }

Loading…
Cancel
Save