initiate plugins branch
[wmaker-crm.git] / plugins / libwmfun / generic.c
blobac838f60039bdf6a95e7ec52e67c06f1df98b951
1 /*
2 * libwmfun - WindowMaker texture function library
3 * Copyright (C) 1999 Tobias Gloth
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
22 * $Id$
24 * $Log$
25 * Revision 1.1 2000/12/03 18:58:41 id
26 * initiate plugins branch
28 * Revision 1.1.1.1 1999/02/21 17:16:47 gloth
29 * initial revision
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
37 #include "generic.h"
39 static Display *dpy = 0;
40 static Colormap cmap;
42 void initWindowMaker (Display *d, Colormap c) {
43 if (!d) {
44 return;
46 dpy = d;
47 cmap = c;
50 void error (const char *format, ...) {
51 va_list args;
52 va_start (args, format);
53 vfprintf (stderr, format, args);
54 va_end (args);
57 int parse_color (const char *string, int *result) {
58 XColor color;
60 if (!XParseColor (dpy, cmap, string, &color)) {
61 return 0;
63 result[0] = color.red >> 8;
64 result[1] = color.green >> 8;
65 result[2] = color.blue >> 8;
67 return 1;
70 int parse_xcolor (const char *string, XColor *xcolor) {
71 if (!XParseColor (dpy, cmap, string, xcolor)) {
72 return 0;
74 if (!XAllocColor (dpy, cmap, xcolor)) {
75 return 0;
78 return 1;
81 void interpolate_color (int *t, const int *s0, const int *s1, int mix) {
82 t[0] = (mix * s0[0] + (255 - mix) * s1[0]) >> 8;
83 t[1] = (mix * s0[1] + (255 - mix) * s1[1]) >> 8;
84 t[2] = (mix * s0[2] + (255 - mix) * s1[2]) >> 8;
87 int random_int (int range) {
88 return rand() / (RAND_MAX / range + 1);
91 double random_double (double range) {
92 return ((double)rand()) / (((double)RAND_MAX) / range);
95 int start_image (const char *name,
96 int argc, int argc_min, int argc_max,
97 int width, int height, RImage **image) {
99 if (!dpy) {
100 error ("%s: library not initialized\n", name);
101 return 0;
104 if ((argc < argc_min) || (argc >= argc_max)) {
105 error ("%s: invalid number of parameters: \n", name, argc);
106 return 0;
109 *image = RCreateImage (width, height, 0);
110 if (!*image) {
111 error ("%s: can't create image\n", name);
112 return 0;
114 return 1;