1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
/* *************************************************************************
Module: lexhand.c
Author: Matt Simpson
Arlington, TX
matthewsimpson@home.com
Date: August, 2000
Description:
Eric Harlow's code from his book,
used to create a hand cursor. Also
contains Harlow's CreateWidgetFromXpm
for the icons used in pup.
Changes:
****************************************************************************
COPYRIGHT (C) 1999, 2000 Matt Simpson
GNU General Public License
See lexgui.c for full notice.
****************************************************************************
The portions of this file extracted from
Eric Harlow's cursors.c from the book
"Developing Linux Applications with GTK+ and GDK",
ISBN 0-7357-0021-4
COPYRIGHT (c) 1999 New Riders Publishing
This statement appears on the copyright page:
"All of the code examples included in this book
are distributed under the terms of the General
Public License."
**************************************************************************** */
#include <gtk/gtk.h>
#include <stdio.h>
#include "lexgui.h"
/* -------------------------------------------------------------------------
create_bitmap_and_mask_from_xpm()
------------------------------------------------------------------------- */
void create_bitmap_and_mask_from_xpm (GdkBitmap **bitmap,
GdkBitmap **mask, gchar **xpm)
{
int height, width, colors;
char pixmap_buffer [(32 * 32)/8];
char mask_buffer [(32 * 32)/8];
int x, y, pix;
int transparent_color, black_color;
sscanf (xpm [0], "%d %d %d %d", &height, &width, &colors, &pix);
g_assert (height == 32);
g_assert (width == 32);
g_assert (colors == 3);
transparent_color = ' ';
black_color = '.';
for (y = 0; y < 32; y++){
for (x = 0; x < 32;){
char value = 0, maskv = 0;
for (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);
}
/* -------------------------------------------------------------------------
create_hand_cursor()
------------------------------------------------------------------------- */
GdkCursor* create_hand_cursor(void)
{
static char * cursor_hand[] = {
"32 32 3 1",
" c None",
". c #000000",
"+ c #FFFFFF",
" ",
" ",
" ... ",
" .+++. ... ",
" .+++. .+++. ... ",
" ... .+++. .+++. .+++. ",
" .+++. .+++. .+++. .+++. ",
" .+++. .+++. .+++. .+++. ",
" .+++. .+++. .+++. .+++. ",
" .+++. .+++..+++. .+++. ",
" .+++..+++..+++. .+++. ",
" .+++.+++..+++..+++. ",
" ... .++++++++++++++++. ",
" .+++. .+++++++++++++++. ",
" .++++..+++++++++++++++. ",
" ..+++++++++++++++++++. ",
" .++++++++++++++++++. ",
" .+++++++++++++++++. ",
" ..++++++++++++++. ",
" .++++++++++++. ",
" .++++++++++. ",
" .......... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
GdkColor white = {0, 0xffff, 0xffff, 0xffff};
GdkColor red = {0, 0xffff, 0x0000, 0x0000};
GdkBitmap *bitmap;
GdkBitmap *mask;
GdkCursor *cursor;
create_bitmap_and_mask_from_xpm (&bitmap, &mask, cursor_hand);
cursor = gdk_cursor_new_from_pixmap (bitmap, mask, &white, &red, 16, 8);
return(cursor);
}
/* -------------------------------------------------------------------------
create_hand_g_cursor() modified from above, to simulate grabbing
------------------------------------------------------------------------- */
GdkCursor* create_hand_g_cursor(void)
{
static char * cursor_handg[] = {
"32 32 3 1",
" c None",
". c #000000",
"+ c #FFFFFF",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ... ... ",
" .. .+++..+++. ... ",
" .++..+++..+++..+++. ",
" .++..+++..+++..+++. ",
" ..+++.+++..+++..+++. ",
" .++.++++++++++++++++. ",
" .+++.+++++++++++++++. ",
" .+++.+++++++++++++++. ",
" .+++++++++++++++++++. ",
" .++++++++++++++++++. ",
" .+++++++++++++++++. ",
" ..++++++++++++++. ",
" .++++++++++++. ",
" .++++++++++. ",
" .......... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
GdkColor white = {0, 0xffff, 0xffff, 0xffff};
GdkColor red = {0, 0xffff, 0x0000, 0x0000};
GdkBitmap *bitmap;
GdkBitmap *mask;
GdkCursor *cursor;
create_bitmap_and_mask_from_xpm (&bitmap, &mask, cursor_handg);
cursor = gdk_cursor_new_from_pixmap (bitmap, mask, &white, &red, 16, 8);
return(cursor);
}
/* -------------------------------------------------------------------------
create_thumb_cursor() modified from above, for a thumbs up cursor
------------------------------------------------------------------------- */
GdkCursor* create_thumb_cursor(void)
{
static char * thumb_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 3 1",
/* colors */
" s None c None",
". c #000000",
"a c #ffffff",
/* pixels */
" ",
" ",
" ",
" ",
" .. ",
" .a.. ",
" .aaa. ",
" .aaa. ",
" .aaaa. ",
" .aaa.. ",
" .aaaa. ",
" .aaaa.. ",
" .aaaaa. ",
" .aaaaa........ ",
" ...... .aaaaa...aaaaa... ",
" .aaa....aaaaaa.aaaaaaaaaa. ",
" .aaa....aaaaaa.aaaaaaaaaa. ",
" .aaa.aaaaaaaaaaaaa....aaaa. ",
" .aaa.aaaaaaaaaaa...aaaaaaa. ",
" .aaa.aaaaaaaa.aa.aaaaaa.... ",
" .aaa.aaaaaaaaaa........aaa. ",
" .aaa.aaaaaaa.a.aaaaaaaaaaa. ",
" .aaa.aaaaaa.aa.aaaaaaaaa... ",
" .aaa.aaaaaaaaa.aaaaaa...... ",
" .aaa.aaaaaaaaaaa.....aaaa.. ",
" .aaa.aaaaaaaaaaa.aaaaaa... ",
" .aaa.aaaaaaaaaaaa......a. ",
" .aaa...aaaaaaaaaa.aaaaa.. ",
" .aaa....aaaaaaaaa....... ",
" ...... ............... ",
" ",
" "};
GdkColor white = {0, 0xffff, 0xffff, 0xffff};
GdkColor black = {0, 0x0000, 0x0000, 0x0000};
GdkBitmap *bitmap;
GdkBitmap *mask;
GdkCursor *cursor;
create_bitmap_and_mask_from_xpm (&bitmap, &mask, thumb_xpm);
cursor = gdk_cursor_new_from_pixmap (bitmap, mask, &white, &black, 16, 8);
return(cursor);
}
/* -------------------------------------------------------------------------
CreateWidgetFromXpm() Returns a pixmap widget from an xpm
------------------------------------------------------------------------- */
GtkWidget *CreateWidgetFromXpm (GtkWidget *window, gchar **xpm_data)
{
GdkBitmap *mask;
GdkPixmap *pixmap_data;
GtkWidget *pixmap_widget;
GtkStyle *style;
style = gtk_widget_get_style(window);
pixmap_data = gdk_pixmap_create_from_xpm_d (
window->window,
&mask,
&style->bg[GTK_STATE_NORMAL],
(gchar **) xpm_data);
pixmap_widget = gtk_pixmap_new (pixmap_data, mask);
gtk_widget_show (pixmap_widget);
return (pixmap_widget);
}
|