Ejemplo n.º 1
0
int render_clock()
{
	static char buflasttime[128];
	char buftime[128];
	time_t current_time;
	current_time = time(0);
	strftime(buftime, sizeof(buftime), theme->clock.format, localtime(&current_time));
	if (!strcmp(buflasttime, buftime))
		return 0;
	strcpy(buflasttime, buftime);
	
	tile_image(theme->tile_img, clock_pos, clock_width);
	int ox = clock_pos;
	draw_clock_background(ox, clock_width);
	int gap = theme->clock.space_gap;
	int lgap = get_image_width(theme->clock.left_img);
	int rgap = get_image_width(theme->clock.right_img);
	int x = ox + gap + lgap;
	int w = clock_width - ((gap * 2) + lgap + rgap);

	imlib_context_set_cliprect(x, 0, w, bbheight);
	draw_text(theme->clock.font, theme->clock.text_align, x, w,
			theme->clock.text_offset_x, theme->clock.text_offset_y,
			buftime, &theme->clock.text_color);
	imlib_context_set_cliprect(0, 0, bbwidth, bbheight);
	return 1;
}
Ejemplo n.º 2
0
void render_taskbar(struct task *tasks, struct desktop *desktops)
{
	tile_image(theme->tile_img, taskbar_pos, taskbar_width);
	int activedesktop = 0;
	struct desktop *iter = desktops;
	while (iter) {
		if (iter->focused)
			break;
		activedesktop++;
		iter = iter->next;
	}
	
	struct task *t = tasks;
	uint state;
	int gap = theme->taskbar.space_gap;

	while (t) {
		if (t->desktop == activedesktop || t->desktop == -1) {
			state = t->focused ? BSTATE_PRESSED : BSTATE_IDLE;
			/* draw bg */
			draw_taskbar_button(state, t->posx, t->width);
			int lgap = get_image_width(theme->taskbar.left_img[state]);
			int rgap = get_image_width(theme->taskbar.right_img[state]);
			int x = t->posx + gap + lgap;
			int w = t->width - ((gap * 2) + lgap + rgap);

			/* draw icon */
			if (theme->taskbar.icon_h && theme->taskbar.icon_w) {
				int srcw, srch;
				int y = (theme->height - theme->taskbar.icon_h) / 2;
				imlib_context_set_image(t->icon);
				srcw = imlib_image_get_width();
				srch = imlib_image_get_height();
				y += theme->taskbar.icon_offset_y;
				x += theme->taskbar.icon_offset_x;
				w -= theme->taskbar.icon_offset_x;
				imlib_context_set_image(bb);
				imlib_context_set_blend(1);
				imlib_blend_image_onto_image(t->icon, 1, 0, 0, srcw, srch,
						x, y, theme->taskbar.icon_w, theme->taskbar.icon_h);
				imlib_context_set_blend(0);
				x += theme->taskbar.icon_w;
				w -= theme->taskbar.icon_w;
			}

			/* draw text */
			imlib_context_set_cliprect(x, 0, w, bbheight);
			draw_text(theme->taskbar.font, theme->taskbar.text_align, x, w,
				theme->taskbar.text_offset_x, theme->taskbar.text_offset_y,
				t->name, &theme->taskbar.text_color[state]);
			imlib_context_set_cliprect(0, 0, bbwidth, bbheight);

			/* draw separator if exists */
			if (t->next && t->next->desktop == activedesktop)
				draw_image(theme->taskbar.separator_img, x+w+gap+rgap);
		}
		t = t->next;
	}
}
Ejemplo n.º 3
0
void render_switcher(struct desktop *desktops)
{		
	tile_image(theme->tile_img, switcher_pos, switcher_width);
	if (!desktops)
		return;
	int ox = switcher_pos;
	int limgw, rimgw;
	ox += theme->switcher.space_gap;
	uint state;
	struct desktop *iter = desktops;
	state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
	if (!iter->next)
		draw_switcher_alone(state, ox, iter->width);
	else 
		draw_switcher_left_corner(state, ox, iter->width);
	limgw = get_image_width(theme->switcher.left_corner_img[state]);
	rimgw = get_image_width(theme->switcher.right_img[state]);
	ox += limgw;
	draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw,
			theme->switcher.text_offset_x, theme->switcher.text_offset_y,
			iter->name, &theme->switcher.text_color[state]);
	ox += iter->width - limgw;

	if (!iter->next)
		return;
	iter = iter->next;
	state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
	if (theme->switcher.separator_img) {
		draw_image(theme->switcher.separator_img, ox);
		ox += get_image_width(theme->switcher.separator_img);
	}

	limgw = get_image_width(theme->switcher.left_img[state]);
	while (iter->next) {
		draw_switcher_middle(state, ox, iter->width);
		ox += limgw;
		draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw,
				theme->switcher.text_offset_x, theme->switcher.text_offset_y,
				iter->name, &theme->switcher.text_color[state]);
		ox += iter->width - limgw;
		iter = iter->next;
		state = iter->focused ? BSTATE_PRESSED : BSTATE_IDLE;
		if (theme->switcher.separator_img) {
			draw_image(theme->switcher.separator_img, ox);
			ox += get_image_width(theme->switcher.separator_img);
		}
	}

	rimgw = get_image_width(theme->switcher.right_corner_img[state]);
	draw_switcher_right_corner(state, ox, iter->width);
	ox += limgw;
	draw_text(theme->switcher.font, theme->switcher.text_align, ox, iter->width - limgw - rimgw,
			theme->switcher.text_offset_x, theme->switcher.text_offset_y,
			iter->name, &theme->switcher.text_color[state]);
}
Ejemplo n.º 4
0
static void draw_tile_sequence(Imlib_Image left, Imlib_Image tile, Imlib_Image right,
		int ox, int width)
{
	int lw = get_image_width(left);
	int rw = get_image_width(right);
	int tilew = width - lw - rw;
	if (tilew < 0)
		return;

	draw_image(left, ox);
	ox += lw;
	tile_image(tile, ox, tilew);
	ox += tilew;
	draw_image(right, ox);
}
Ejemplo n.º 5
0
void render_panel(struct panel *p)
{
	int ox = 0;
	char *e = theme->elements;
	while (*e) {
		switch (*e) {
		case 'c':
			render_clock();
			ox += clock_width;
			break;
		case 's':
			render_switcher(p->desktops);
			ox += switcher_width;
			break;
		case 't':
			if (!p->trayicons) {
				/* we're skipping if no tray icons here, separator is being drawn only once */
				e++;
				continue;
			}
			if (tray_width)
				tile_image(theme->tile_img, tray_pos, tray_width);
			ox += tray_width;
			break;
		case 'b':
			render_taskbar(p->tasks, p->desktops);
			ox += taskbar_width;
			break;
		}
		if (*++e && theme->separator_img) {
			draw_image(theme->separator_img, ox);
			ox += get_image_width(theme->separator_img);
		}
	}
	render_present();
}
Ejemplo n.º 6
0
static void
loadtiles(void) {
    int lx, rx, ty, by;	/* image bounding box */
    static int ox = TILES*TILESIZE/2, oy = TILES*TILESIZE/2;  /* image origin */
    static int ot = 0, os = 0;
    int dx = 0, dy = 0, nx = -1, ny = -1;
    float trx, try;
#define S_TSIZE	(TSIZE-TILESIZE)	/* visible portion of texture = TSIZE less one tile for slop */

    /* calculate tile #'s at corners of visible region */
    lx = x - S_TSIZE/2;
    rx = lx + S_TSIZE;
    by = y - S_TSIZE/2;
    ty = by + S_TSIZE;
    lx /= TILESIZE; rx /= TILESIZE;
    by /= TILESIZE; ty /= TILESIZE;

    dx = ((x - S_TSIZE/2)/TILESIZE) - ((ox - S_TSIZE/2)/TILESIZE);
    
    nx = lx; ny = by;
    if (dx < 0) {
	/* add on left */
	os -= TILESIZE;
	if (os < 0) os += TSIZE;
	nx = lx;
    } else if (dx > 0) {
	nx = rx;
    }

    dy = ((y - S_TSIZE/2) / TILESIZE) - ((oy - S_TSIZE/2) / TILESIZE);
    if (dy > 0) {
	/* add on bottom */
	ny = ty;
    } else if (dy < 0) {
	/* add on top */
	ot -= TILESIZE;
	if (ot < 0) ot += TSIZE;
	ny = by;
    }
if (dx || dy) printf("dx %d dy %d   lx %d rx %d   by %d ty %d   nx %d ny %d   os %d ot %d\n", dx, dy, lx, rx, by, ty, nx, ny, os, ot);
    if (dx) {
	int t;
	for(t = 0; t < TSIZE; t += TILESIZE) {
	    glTexSubImage2D(GL_TEXTURE_2D, 0, os, (t+ot) % TSIZE, TILESIZE,
                 TILESIZE, GL_RGBA, GL_UNSIGNED_BYTE,
                 tiles[ny+t/TILESIZE][nx].data);
printf("load %d %d  %d %d\n", nx, ny+t/TILESIZE, os, (t+ot) % TSIZE);
	}
    }

    if (dy) {
	int s;
	for(s = 0; s < TSIZE; s += TILESIZE) {
	    glTexSubImage2D(GL_TEXTURE_2D, 0, (s+os) % TSIZE, ot, TILESIZE,
                 TILESIZE, GL_RGBA, GL_UNSIGNED_BYTE,
                 tiles[ny][nx+s/TILESIZE].data);
printf("load %d %d  %d %d\n", nx+s/TILESIZE, ny, (s+os) % TSIZE, ot);
	}
    }
    if (dx > 0) {
	os += TILESIZE;
	if (os >= TSIZE) os -= TSIZE;
    }
    if (dy > 0) {
	ot += TILESIZE;
	if (ot >= TSIZE) ot -= TSIZE;
    }
    ox = x; oy = y;
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    trx = (float)((x-TILES*TILESIZE/2) % TSIZE)/TSIZE;
    try = (float)((y-TILES*TILESIZE/2) % TSIZE)/TSIZE;
    glTranslatef(trx, try, 0.f);
    glMatrixMode(GL_MODELVIEW);
}

static void
init(char *filename) {
    int i;

    mesh0(-1.f,1.f,-1.f,1.f,0.f,1.f,0.f,1.f,0.f,64,64);
    if (filename) {
	image = read_texture(filename, &width, &height, &components);
	if (image == NULL) {
	    fprintf(stderr, "Error: Can't load image file \"%s\".\n",
		    filename);
	    exit(EXIT_FAILURE);
	} else {
	    printf("%d x %d image loaded\n", width, height);
	}
	if (components < 3 || components > 4) {
	    printf("must be RGB or RGBA image\n");
	    exit(EXIT_FAILURE);
	}
    } else {
	int i, j;
	components = 4; width = height = TSIZE;
	image = (unsigned *) malloc(width*height*sizeof(unsigned));
	for (j = 0; j < height; j++)
	    for (i = 0; i < width; i++) {
		if (i & 1)
		    image[i+j*width] = 0xff;
		else
		    image[i+j*width] = 0xff00;
		if (j&1)
		    image[i+j*width] |= 0xff0000;
	    }

    }
    if (width % TILESIZE || height % TILESIZE) {
#define TXSIZE 192
	unsigned *newimage = malloc(TXSIZE*TXSIZE*sizeof *newimage);
	gluScaleImage(GL_RGBA, width, height, GL_UNSIGNED_BYTE, image,
		TXSIZE, TXSIZE, GL_UNSIGNED_BYTE, newimage);
	free(image);
	image = newimage; width = height = TXSIZE; components = 4;
    }
    tile_image(image);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE,
                 TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    for(i = 0; i < TILES; i++) {
	int j;
	for(j = 0; j < TILES; j++) {
	    glTexSubImage2D(GL_TEXTURE_2D, 0, i*TILESIZE, j*TILESIZE, TILESIZE,
		 TILESIZE, GL_RGBA, GL_UNSIGNED_BYTE, 
		 tiles[(TILES-TSIZE/TILESIZE)/2+j][(TILES-TSIZE/TILESIZE)/2+i].data);
	}
    }
    glEnable(GL_TEXTURE_2D);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.,1.,.1,10.);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.,0.,-1.0);
    glLineWidth(3.0);
    glClearColor(.25, .25, .25, .25);

    /* start at center of image */
    x = TILES*TILESIZE/2;
    y = TILES*TILESIZE/2;
}
Ejemplo n.º 7
0
static void
init(char *filename) {
    int i;

    mesh0(-1.f,1.f,-1.f,1.f,0.f,1.f,0.f,1.f,0.f,64,64);
    if (filename) {
	image = read_texture(filename, &width, &height, &components);
	if (image == NULL) {
	    fprintf(stderr, "Error: Can't load image file \"%s\".\n",
		    filename);
	    exit(EXIT_FAILURE);
	} else {
	    printf("%d x %d image loaded\n", width, height);
	}
	if (components < 3 || components > 4) {
	    printf("must be RGB or RGBA image\n");
	    exit(EXIT_FAILURE);
	}
    } else {
	int i, j;
	components = 4; width = height = TSIZE;
	image = (unsigned *) malloc(width*height*sizeof(unsigned));
	for (j = 0; j < height; j++)
	    for (i = 0; i < width; i++) {
		if (i & 1)
		    image[i+j*width] = 0xff;
		else
		    image[i+j*width] = 0xff00;
		if (j&1)
		    image[i+j*width] |= 0xff0000;
	    }

    }
    if (width % TILESIZE || height % TILESIZE) {
#define TXSIZE 192
	unsigned *newimage = malloc(TXSIZE*TXSIZE*sizeof *newimage);
	gluScaleImage(GL_RGBA, width, height, GL_UNSIGNED_BYTE, image,
		TXSIZE, TXSIZE, GL_UNSIGNED_BYTE, newimage);
	free(image);
	image = newimage; width = height = TXSIZE; components = 4;
    }
    tile_image(image);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TSIZE,
                 TSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    for(i = 0; i < TILES; i++) {
	int j;
	for(j = 0; j < TILES; j++) {
	    glTexSubImage2D(GL_TEXTURE_2D, 0, i*TILESIZE, j*TILESIZE, TILESIZE,
		 TILESIZE, GL_RGBA, GL_UNSIGNED_BYTE, 
		 tiles[(TILES-TSIZE/TILESIZE)/2+j][(TILES-TSIZE/TILESIZE)/2+i].data);
	}
    }
    glEnable(GL_TEXTURE_2D);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.,1.,.1,10.);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.,0.,-1.0);
    glLineWidth(3.0);
    glClearColor(.25, .25, .25, .25);

    /* start at center of image */
    x = TILES*TILESIZE/2;
    y = TILES*TILESIZE/2;
}