sp-cursor.cpp revision 66632b492f9cd54e5667fd4e1fca8e457f59b282
649N/A#define __SP_CURSOR_C__
649N/A
649N/A/*
649N/A * Some convenience stuff
943N/A *
649N/A * Authors:
649N/A * Lauris Kaplinski <lauris@kaplinski.com>
919N/A *
919N/A * Copyright (C) 1999-2002 authors
919N/A * Copyright (C) 2001-2002 Ximian, Inc.
919N/A *
919N/A * Released under GNU GPL, read the file 'COPYING' for more information
919N/A */
919N/A
919N/A#include <cstdio>
919N/A#include <cstring>
919N/A#include <string>
919N/A#include <ctype.h>
919N/A#include "sp-cursor.h"
919N/A
919N/Avoid
919N/Asp_cursor_bitmap_and_mask_from_xpm(GdkBitmap **bitmap, GdkBitmap **mask, gchar const *const *xpm)
919N/A{
919N/A int height;
649N/A int width;
649N/A int colors;
649N/A int pix;
649N/A sscanf(xpm[0], "%d %d %d %d", &height, &width, &colors, &pix);
649N/A
649N/A g_return_if_fail (height == 32);
649N/A g_return_if_fail (width == 32);
649N/A g_return_if_fail (colors >= 3);
649N/A
649N/A int transparent_color = ' ';
649N/A int black_color = '.';
649N/A
970N/A char pixmap_buffer[(32 * 32)/8];
970N/A char mask_buffer[(32 * 32)/8];
970N/A
970N/A for (int i = 0; i < colors; i++) {
970N/A
970N/A char const *p = xpm[1 + i];
970N/A char const ccode = *p;
970N/A
649N/A p++;
649N/A while (isspace(*p)) {
649N/A p++;
649N/A }
649N/A p++;
649N/A while (isspace(*p)) {
649N/A p++;
649N/A }
649N/A
649N/A if (strcmp(p, "None") == 0) {
649N/A transparent_color = ccode;
649N/A }
970N/A
970N/A if (strcmp(p, "#000000") == 0) {
970N/A black_color = ccode;
649N/A }
}
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; ) {
char value = 0;
char maskv = 0;
for (int pix = 0; pix < 8; pix++, x++){
if (xpm[4+y][x] != transparent_color) {
maskv |= 1 << pix;
if (xpm[4+y][x] == black_color) {
value |= 1 << pix;
}
}
}
pixmap_buffer[(y * 4 + x/8)-1] = value;
mask_buffer[(y * 4 + x/8)-1] = maskv;
}
}
*bitmap = gdk_bitmap_create_from_data(NULL, pixmap_buffer, 32, 32);
*mask = gdk_bitmap_create_from_data(NULL, mask_buffer, 32, 32);
}
GdkCursor *
sp_cursor_new_from_xpm(gchar const *const *xpm, gint hot_x, gint hot_y)
{
GdkColor const fg = { 0, 0, 0, 0 };
GdkColor const bg = { 0, 65535, 65535, 65535 };
GdkBitmap *bitmap = NULL;
GdkBitmap *mask = NULL;
sp_cursor_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm);
if ( bitmap != NULL && mask != NULL ) {
GdkCursor *new_cursor = gdk_cursor_new_from_pixmap (bitmap, mask,
&fg, &bg,
hot_x, hot_y);
g_object_unref (bitmap);
g_object_unref (mask);
return new_cursor;
}
return NULL;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :