Esempio n. 1
0
GdkCursor *
gl_view_line_get_create_cursor (void)
{
	GdkCursor       *cursor = NULL;
	GdkPixmap       *pixmap_data, *pixmap_mask;
	GdkColor         fg = { 0, 0, 0, 0 };
	GdkColor         bg = { 0, 65535, 65535, 65535 };

	gl_debug (DEBUG_VIEW, "START");

        pixmap_data = gdk_bitmap_create_from_data (NULL,
                                                   (gchar *)cursor_line_bits,
                                                   cursor_line_width,
                                                   cursor_line_height);
        pixmap_mask = gdk_bitmap_create_from_data (NULL,
                                                   (gchar *)cursor_line_mask_bits,
                                                   cursor_line_mask_width,
                                                   cursor_line_mask_height);
        cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
                                             &bg, cursor_line_x_hot,
                                             cursor_line_y_hot);

	gl_debug (DEBUG_VIEW, "END");

	return cursor;
}
Esempio n. 2
0
static void
gtk_ui_load_cursor(const char *name, int masked, MCursor **cursorp) {
	MCursor *cursor;
	GdkBitmap *bitmap, *mask;
	cursormap *c;

	cursor = xalloc(sizeof *cursor);

	for (c = cursors; c->name != NULL; c++)
		if (strcmp(name, c->name) == 0)
			break;
	if (c->name == NULL)
		fatal("couldn't load cursor: %s", name);
	bitmap = gdk_bitmap_create_from_data(field->window, c->data,
					     c->width, c->height);

	if (masked == CURSOR_SEP_MASK)
		mask = gdk_bitmap_create_from_data(field->window, c->maskdata,
						   c->width, c->height);
	else
		mask = bitmap;
	cursor->cursor = gdk_cursor_new_from_pixmap(bitmap, mask, 
						    &black, &white,
						    c->width/2, c->height/2);
	*cursorp = cursor;
}
Esempio n. 3
0
static GdkCursor *
create_cursor(GdkWindow *window,
	      const gchar *data, int width, int height,
	      const gchar *mask, int hot_x, int hot_y)
{
  GdkBitmap *dbit, *mbit;
  GdkColor black, white;
  GdkCursor *cursor;

  g_return_val_if_fail(window != NULL, NULL);

  dbit = gdk_bitmap_create_from_data(window, data, width, height);
  mbit = gdk_bitmap_create_from_data(window, mask, width, height);
  g_assert(dbit != NULL && mbit != NULL);

  gdk_color_black(gdk_window_get_colormap(window), &black);
  gdk_color_white(gdk_window_get_colormap(window), &white);

  cursor = gdk_cursor_new_from_pixmap(dbit, mbit, &white,&black, hot_x,hot_y);
  g_assert(cursor != NULL);

  gdk_bitmap_unref(dbit);
  gdk_bitmap_unref(mbit);

  return cursor;
}
Esempio n. 4
0
/* load in the cursors */
static void ui_common_cursor_init(void) {

  GdkPixmap *source, *mask;
  GdkColor fg = { 0, 0, 0, 0 }; /* black. */
  GdkColor bg = { 0, 0, 0, 0 }; /* black */
  GdkCursor * small_dot;
 
  source = gdk_bitmap_create_from_data(NULL, small_dot_bits, small_dot_width, small_dot_height);
  mask = gdk_bitmap_create_from_data(NULL, small_dot_bits, small_dot_width, small_dot_height);
  small_dot = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 2,2);
  g_object_unref (source);
  g_object_unref (mask);
                                     
  /* load in the cursors */

  ui_common_cursor[UI_CURSOR_DEFAULT] = NULL;
  ui_common_cursor[UI_CURSOR_ROI_MODE] =  gdk_cursor_new(GDK_DRAFT_SMALL);
  ui_common_cursor[UI_CURSOR_ROI_RESIZE] = small_dot; /* was GDK_SIZING */
  ui_common_cursor[UI_CURSOR_ROI_ROTATE] = small_dot; /* was GDK_EXCHANGE */
  ui_common_cursor[UI_CURSOR_ROI_DRAW] = gdk_cursor_new(GDK_PENCIL);
  ui_common_cursor[UI_CURSOR_OBJECT_SHIFT] = small_dot; /* was GDK_FLEUR */
  ui_common_cursor[UI_CURSOR_ROI_ISOCONTOUR] = gdk_cursor_new(GDK_DRAFT_SMALL);
  ui_common_cursor[UI_CURSOR_ROI_ERASE] = gdk_cursor_new(GDK_DRAFT_SMALL);
  ui_common_cursor[UI_CURSOR_DATA_SET_MODE] = gdk_cursor_new(GDK_CROSSHAIR);
  ui_common_cursor[UI_CURSOR_FIDUCIAL_MARK_MODE] = gdk_cursor_new(GDK_DRAFT_SMALL);
  ui_common_cursor[UI_CURSOR_RENDERING_ROTATE_XY] = gdk_cursor_new(GDK_FLEUR);
  ui_common_cursor[UI_CURSOR_RENDERING_ROTATE_Z] = gdk_cursor_new(GDK_EXCHANGE);
  ui_common_cursor[UI_CURSOR_WAIT] = gdk_cursor_new(GDK_WATCH);
  

 
  ui_common_cursors_initialized = TRUE;
  return;
}
Esempio n. 5
0
static gboolean gonna_hide(gpointer data) {
	beforehiding--;

	if (beforehiding == 0) {
		static char source_data[] = { 0 };
		static char mask_data[] = { 0 };

		GdkCursor *cursor;
 		GdkPixmap *source, *mask;
		GdkColor fg = { 0, 65535, 65535, 65535 };
		GdkColor bg = { 0, 0, 0, 0 };
 
		source = gdk_bitmap_create_from_data(NULL, source_data, 1, 1);
		mask = gdk_bitmap_create_from_data(NULL, mask_data, 1, 1);
		cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, 1, 1);
		gdk_pixmap_unref(source);
		gdk_pixmap_unref(mask);

		gdk_window_set_cursor(GTK_WIDGET(data)->window, cursor);

		return FALSE;
	} else {
		return TRUE;
	}
}
Esempio n. 6
0
GdkCursor* create_blank_cursor(){
	GdkPixmap *pixmap;
	GdkBitmap *mask;
	char buffer [( 32 * 32 ) / 8];
	memset( buffer, 0, ( 32 * 32 ) / 8 );
	GdkColor white = {0, 0xffff, 0xffff, 0xffff};
	GdkColor black = {0, 0x0000, 0x0000, 0x0000};
	pixmap = gdk_bitmap_create_from_data( 0, buffer, 32, 32 );
	mask   = gdk_bitmap_create_from_data( 0, buffer, 32, 32 );
	GdkCursor *cursor = gdk_cursor_new_from_pixmap( pixmap, mask, &white, &black, 1, 1 );
	gdk_drawable_unref( pixmap );
	gdk_drawable_unref( mask );

	return cursor;
}
Esempio n. 7
0
/** Convert Dia color objects into GDK color objects.
 * If the highlight color is set, that will be used instead.  This allows
 * rendering of an object to do highlight rendering.
 * @param renderer The renderer to check for highlight color.
 * @param col A color object to convert.
 * @param gdk_col Resulting GDK convert.
 */
static void
renderer_color_convert(DiaGdkRenderer *renderer,
		       Color *col, GdkColor *gdk_col)
{
  if (renderer->highlight_color != NULL) {
    color_convert(renderer->highlight_color, gdk_col);
  } else {
    color_convert(col, gdk_col);
  }
  if (col->alpha != renderer->current_alpha) {
    if (col->alpha == 1.0)
      gdk_gc_set_fill(renderer->gc, GDK_SOLID);
    else {
      static gchar bits[9][4] = {
        { 0x00, 0x00, 0x00, 0x00 }, /*   0% */
	{ 0x20, 0x02, 0x20, 0x02 },
        { 0x22, 0x88, 0x22, 0x88 }, /*  25% */
	{ 0x4A, 0xA4, 0x4A, 0xA4 },
        { 0x5A, 0xA5, 0x5A, 0xA5 }, /*  50% */
	{ 0x57, 0xBA, 0x57, 0xBA },
        { 0xBE, 0xEB, 0xBE, 0xEB }, /*  75% */
	{ 0xEF, 0xFE, 0xEF, 0xFE },
        { 0xFF, 0xFF, 0xFF, 0xFF }, /* 100% */
      };
      GdkBitmap *stipple = gdk_bitmap_create_from_data (NULL, bits[(int)(9*col->alpha+.49)], 4, 4);
      gdk_gc_set_stipple (renderer->gc, stipple);
      g_object_unref (stipple);
      gdk_gc_set_fill(renderer->gc, GDK_STIPPLED);
    }
    renderer->current_alpha = col->alpha;
  }
}
Esempio n. 8
0
static GdkCursor* customCursorNew(CustomCursorType cursorType)
{
    CustomCursor cursor = CustomCursors[cursorType];
    GdkCursor* c = gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name);
    if (!c) {
        const GdkColor fg = { 0, 0, 0, 0 };
        const GdkColor bg = { 65535, 65535, 65535, 65535 };

        GdkPixmap* source = gdk_bitmap_create_from_data(NULL, cursor.bits, 32, 32);
        GdkPixmap* mask = gdk_bitmap_create_from_data(NULL, cursor.mask_bits, 32, 32);
        c = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, cursor.hot_x, cursor.hot_y);
        g_object_unref(source);
        g_object_unref(mask);
    }
    return c;
}
Esempio n. 9
0
/**
 * Grab the keyboard and mouse for the display. The mouse cursor is hidden and
 * moved to the centre of the window.
 *
 * @param win The window receiving the grab
 * @return TRUE if the grab was successful, FALSE on failure.
 */
gboolean video_window_grab_display( main_window_t win )
{
    GdkWindow *gdkwin = win->video->window;
    GdkColor color = { 0,0,0,0 };
    char bytes[32]; /* 16 * 16 / 8 */
    memset(bytes, 0, 32);
    GdkPixmap *pixmap = gdk_bitmap_create_from_data(NULL, bytes, 16, 16);
    GdkCursor *cursor = gdk_cursor_new_from_pixmap(pixmap, pixmap, &color, &color, 16, 16);
    gdk_pixmap_unref(pixmap);

    gboolean success =
        gdk_pointer_grab( gdkwin, FALSE, 
                GDK_POINTER_MOTION_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK, 
                gdkwin, cursor, GDK_CURRENT_TIME ) == GDK_GRAB_SUCCESS;
    gdk_cursor_unref(cursor);
    if( success ) {
        success = gdk_keyboard_grab( gdkwin, FALSE, GDK_CURRENT_TIME ) == GDK_GRAB_SUCCESS;
        if( !success ) {
            gdk_pointer_ungrab(GDK_CURRENT_TIME);
        }
    }
    win->is_grabbed = success;
    main_window_set_running(win, dreamcast_is_running());
    return success;
}
Esempio n. 10
0
int
hide_cursor (GtkWindow* window)
{
  GdkCursor* cursor;
  GdkPixmap* source, *mask;
  GdkColor fg = { 0, 0, 0, 0 }; /* Transparent. */
  GdkColor bg = { 0, 0, 0, 0 }; /* Transparent. */  

  source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
					cursor1_width, cursor1_height);
  mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
				      cursor1_width, cursor1_height);
  cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
  gdk_pixmap_unref (source);
  gdk_pixmap_unref (mask);   
  gdk_window_set_cursor (((GtkWidget*)window)->window, cursor);
}
Esempio n. 11
0
static 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, yofs;
    int transparent_color, black_color;

    sscanf (xpm [0], "%d %d %d %d", &height, &width, &colors, &pix);

    g_return_if_fail (height == 32);
    g_return_if_fail (width  == 32);
    g_return_if_fail (colors <= 3);

    transparent_color = ' ';
    black_color = '.';

    yofs = colors + 1;
    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 [y + yofs][x] != transparent_color) {
                    maskv |= 1 << pix;

                    /*
                     * Invert the colours here because it seems
                     * to workaround a bug the Matrox G100 Xserver?
                     * We reverse the foreground & background in the next
                     * routine to compensate.
                     */
                    if (xpm [y + yofs][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);
}
Esempio n. 12
0
static void
set_icon_bitmap(GtkWidget *w)
{
	GdkPixmap *icon_pixmap;

	gdk_window_set_icon_name(w->window, APPNAME);
	icon_pixmap = gdk_bitmap_create_from_data(
	    w->window, np2_bits, np2_width, np2_height);
	gdk_window_set_icon(w->window, NULL, icon_pixmap, NULL);
}
Esempio n. 13
0
void mouse_init_cursor(void)
{
#if !GTK_CHECK_VERSION(2, 2, 0)
    static char cursor[] = { 0x00 };
    GdkColor fg = { 0, 0, 0, 0 };
    GdkColor bg = { 0, 0, 0, 0 };
    GdkBitmap *source = gdk_bitmap_create_from_data (NULL, cursor, 1, 1);
    GdkBitmap *mask = gdk_bitmap_create_from_data (NULL, cursor, 1, 1);

    blankCursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 1, 1); 

    g_object_unref (source);
    g_object_unref (mask);
#else
    /* GDK_BLANK_CURSOR exists since 2.16 */
    /* FIXME: to support multiple screens, we must use gdk_cursor_new_for_display */
    blankCursor = gdk_cursor_new(GDK_BLANK_CURSOR);
#endif
}
Esempio n. 14
0
static void
gimp_canvas_realize (GtkWidget *widget)
{
  GimpCanvas *canvas = GIMP_CANVAS (widget);

  GTK_WIDGET_CLASS (parent_class)->realize (widget);

  canvas->stipple[0] =
    gdk_bitmap_create_from_data (widget->window,
                                 (const gchar *) stipples[0], 8, 8);
}
Esempio n. 15
0
/**
 * cursor_get:
 * @window: Window whose screen and colormap determine the cursor's.
 * @type: A cursor type.
 * 
 * Creates a cursor.
 * 
 * Return value: The newly-created cursor.
 **/
GdkCursor*
cursor_get (GtkWidget *window, CursorType type)
{
  GdkBitmap *data;
  GdkBitmap *mask;
  GdkCursor *cursor;
  GtkStyle *style;

  if (type == CURSOR_DEFAULT)
    return NULL;

  g_return_val_if_fail (window != NULL, NULL);
  g_return_val_if_fail (type >= 0 && type < CURSOR_NUM_CURSORS, NULL);

  g_assert (cursors[type].data_width == cursors[type].mask_width);
  g_assert (cursors[type].data_height == cursors[type].mask_height);

  data = gdk_bitmap_create_from_data (window->window,
                                      cursors[type].data,
                                      cursors[type].data_width,
                                      cursors[type].data_height);
  mask = gdk_bitmap_create_from_data (window->window,
                                      cursors[type].mask,
                                      cursors[type].mask_width,
                                      cursors[type].mask_height);

  g_assert (data != NULL && mask != NULL);

  style = gtk_widget_get_style (window);

  cursor = gdk_cursor_new_from_pixmap (data, mask,
                                       &style->white, &style->black,
                                       cursors[type].hot_x,
                                       cursors[type].hot_y);
  g_assert (cursor != NULL);

  g_object_unref (data);
  g_object_unref (mask);

  return cursor;
}
Esempio n. 16
0
static void	
zune_render_set_pattern (struct MUI_RenderInfo *mri, LONG pattern)
{
    SetAPen(mri->mri_RastPort, mri->mri_Pens[patternPens[pattern - MUII_BACKGROUND].fg]);
    SetBPen(mri->mri_RastPort, mri->mri_Pens[patternPens[pattern - MUII_BACKGROUND].bg]);    
    gdk_gc_set_fill(mri->mri_RastPort, GDK_OPAQUE_STIPPLED);
    if (!mri->mri_PatternStipple)
    {
	mri->mri_PatternStipple =
	    gdk_bitmap_create_from_data(mri->mri_Window, patstipple_bits,
					patstipple_width, patstipple_height);
    }
    gdk_gc_set_stipple(mri->mri_RastPort, mri->mri_PatternStipple);
}
Esempio n. 17
0
void* iupdrvImageCreateMask(Ihandle *ih)
{
#if GTK_CHECK_VERSION(3, 0, 0)
  return NULL;  /* not supported in GTK3 */
#else
  int bpp;
  GdkPixmap *mask;
  char *bits, *sb;
  int y, x, line_size = (ih->currentwidth+7)/8;
  int size_bytes = line_size*ih->currentheight;
  unsigned char* imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");
  unsigned char colors[256];

  bpp = iupAttribGetInt(ih, "BPP");
  if (bpp > 8)
    return NULL;

  bits = (char*)malloc(size_bytes);
  if (!bits) return NULL;
  memset(bits, 0, size_bytes);

  iupImageInitNonBgColors(ih, colors);

  sb = bits;
  for (y=0; y<ih->currentheight; y++)
  {
    for (x=0; x<ih->currentwidth; x++)
    {
      int byte = x/8;
      int bit = x%8;
      int index = (int)imgdata[y*ih->currentwidth+x];
      if (colors[index])
        sb[byte] = (char)(sb[byte] | (1<<bit));
    }

    sb += line_size;
  }

  mask = gdk_bitmap_create_from_data(NULL, bits, ih->currentwidth, ih->currentheight);

  free(bits);

  return mask;
#endif
}
Esempio n. 18
0
void create_cursors(void)
{
  static GdkColor color1={0,0xFFFF,0xFFFF,0xFFFF};
  static GdkColor color2={0,0x0000,0x0000,0x0000};
  GdkBitmap *curs_pix, *msk_pix;

  curs_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)point_bits,
					 point_width, point_height);
  msk_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)pointmsk_bits,
					pointmsk_width, pointmsk_height);
  cpoint = gdk_cursor_new_from_pixmap(curs_pix, msk_pix, &color2, &color1,
				      3,0);
  gdk_bitmap_unref(curs_pix);
  gdk_bitmap_unref(msk_pix);

  curs_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)pour_bits,
					 pour_width, pour_height);
  msk_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)pourmsk_bits,
					pourmsk_width, pourmsk_height);
  cfill = gdk_cursor_new_from_pixmap(curs_pix, msk_pix, &color2, &color1,
				     14, 13);
  gdk_bitmap_unref(curs_pix);
  gdk_bitmap_unref(msk_pix);

  curs_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)cross_bits,
					 cross_width, cross_height);
  msk_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)crossmsk_bits,
					crossmsk_width, crossmsk_height);
  ccross = gdk_cursor_new_from_pixmap(curs_pix, msk_pix, &color2, &color1,
				      8,8);
  gdk_bitmap_unref(curs_pix);
  gdk_bitmap_unref(msk_pix);

  curs_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)select_bits,
					 select_width, select_height);
  msk_pix = gdk_bitmap_create_from_data(NULL, (const gchar *)selectmsk_bits,
					selectmsk_width, selectmsk_height);
  cselect = gdk_cursor_new_from_pixmap(curs_pix, msk_pix, &color2, &color1,
				       0,select_height);
  gdk_bitmap_unref(curs_pix);
  gdk_bitmap_unref(msk_pix);
}
Esempio n. 19
0
/**
 * gimp_canvas_set_stipple_index:
 * @canvas: a #GimpCanvas widget
 * @style:  the #GimpCanvasStyle to alter
 * @index:  the new stipple index
 *
 * Some styles of the #GimpCanvas do a stipple fill. #GimpCanvas has a
 * set of %GIMP_CANVAS_NUM_STIPPLES stipple bitmaps. This function
 * allows you to change the bitmap being used. This can be used to
 * implement a marching ants effect. An older implementation used to
 * use this feature and so it is included since it might be useful in
 * the future. All stipple bitmaps but the default one are created on
 * the fly.
 */
void
gimp_canvas_set_stipple_index (GimpCanvas      *canvas,
                               GimpCanvasStyle  style,
                               guint            index)
{
  if (! gimp_canvas_ensure_style (canvas, style))
    return;

  index = index % GIMP_CANVAS_NUM_STIPPLES;

  if (! canvas->stipple[index])
    {
      canvas->stipple[index] =
        gdk_bitmap_create_from_data (GTK_WIDGET (canvas)->window,
                                     (const gchar *) stipples[index], 8, 8);
    }

  gdk_gc_set_stipple (canvas->gc[style], canvas->stipple[index]);
}
Esempio n. 20
0
static VALUE
gdkpmap_create_from_data(int argc, VALUE *argv, VALUE self)
{
    VALUE win, data, w, h, depth, fg, bg, ret;

    rb_scan_args(argc, argv, "43", &win, &data, &w, &h, &depth, &fg, &bg);

    Check_Type(data, T_STRING);
    if (NIL_P(depth)){
        ret = GOBJ2RVAL(gdk_bitmap_create_from_data(NIL_P(win) ? NULL : GDK_WINDOW(RVAL2GOBJ(win)),
                                                    RVAL2CSTR(data), NUM2INT(w), NUM2INT(h)));
    } else {
        ret = GOBJ2RVAL(gdk_pixmap_create_from_data(NIL_P(win) ? NULL : GDK_WINDOW(RVAL2GOBJ(win)),
                                                    RVAL2CSTR(data), NUM2INT(w), NUM2INT(h), 
                                                    NUM2INT(depth),
						    RVAL2GDKCOLOR(fg),
						    RVAL2GDKCOLOR(bg)));
    }
    return ret;
}
Esempio n. 21
0
static GdkCursor* gtkEmptyCursor(Ihandle* ih)
{
  /* creates an empty cursor */
  GdkColor cursor_color = {0L,0,0,0};
  char bitsnull[1] = {0x00};

  GdkWindow* window = ih->handle->window;
  GdkPixmap* pixmapnull = gdk_bitmap_create_from_data(
    (GdkDrawable*)window,
    bitsnull,
    1,1);
  GdkCursor* cur = gdk_cursor_new_from_pixmap(
    pixmapnull,
    pixmapnull,
    &cursor_color,
    &cursor_color,
    0,0);

  g_object_unref(pixmapnull);

  return cur;
}
Esempio n. 22
0
static GdkCursor*
make_blank_cursor                        (GdkDisplay *display)
{
	/* Taken and heavily modified from gdkcursor-x11.c */
	GdkCursor *cursor;
	GdkScreen *screen;
	GdkPixmap *pixmap;
	GdkColor colour = { 0, 0, 0, 0 };

	screen = gdk_display_get_default_screen (display);
	g_return_val_if_fail (screen, NULL);

	pixmap = gdk_bitmap_create_from_data (gdk_screen_get_root_window (screen), "\0\0\0\0\0\0\0\0", 1, 1);  
	
	if (display->closed)
		return NULL;
	else
		cursor = gdk_cursor_new_from_pixmap (pixmap, pixmap, &colour, &colour, 1, 1);

  	g_object_unref (pixmap);

  	return cursor;
}
Esempio n. 23
0
/**
 * @param stock_id	a valid stock icon name
 * @return		a window showing the stock icon
 *
 * Create a window displaying a stock icon which is transparent
 * according to the icon's alpha mask. Such windows are mostly
 * useful to implement drag-and-drop operations with stock icons.
 */
GtkWidget*
gxk_stock_icon_window (const gchar *stock_id)
{
  GtkWidget *drag_window, *image;
  GdkPixbuf *pixbuf;
  GdkBitmap *mask;
  guint8 *bitmap_data;
  gint width = 0, height = 0;

  g_return_val_if_fail (stock_id != NULL, NULL);

  pixbuf = gxk_stock_fallback_pixbuf (stock_id);
  if (!pixbuf)
    {
      g_warning ("%s: unregistered stock id: \"%s\"", G_STRLOC, stock_id);
      return NULL;
    }

  image = gtk_image_new_from_pixbuf (pixbuf);
  gtk_widget_show (image);

  drag_window = gtk_widget_new (GTK_TYPE_WINDOW,
				"type", GTK_WINDOW_POPUP,
				"child", image,
				NULL);
  gtk_widget_set_app_paintable (drag_window, TRUE);
  gtk_widget_realize (drag_window);
  gdk_window_raise (drag_window->window);
  bitmap_data = gdk_pixbuf_create_bitmap_data (pixbuf, &width, &height, 1);
  mask = gdk_bitmap_create_from_data (drag_window->window, bitmap_data, width, height);
  g_free (bitmap_data);
  gtk_widget_shape_combine_mask (drag_window, mask, 0, 0);
  gdk_pixmap_unref (mask);

  return drag_window;
}
Esempio n. 24
0
static GdkCursor *
get_cursor (void)
{
    GdkBitmap *empty_bitmap;
    GdkCursor *cursor;
    GdkColor   useless;
    char       invisible_cursor_bits [] = { 0x0 };

    useless.red = useless.green = useless.blue = 0;
    useless.pixel = 0;

    empty_bitmap = gdk_bitmap_create_from_data (NULL,
                   invisible_cursor_bits,
                   1, 1);

    cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
                                         empty_bitmap,
                                         &useless,
                                         &useless, 0, 0);

    g_object_unref (empty_bitmap);

    return cursor;
}
Esempio n. 25
0
void update_cursor(void)
{
  GdkPixmap *source, *mask;
  GdkColor fg = {0, 0, 0, 0}, bg = {0, 65535, 65535, 65535};

  ui.is_sel_cursor = FALSE;
  if (GTK_WIDGET(canvas)->window == NULL) return;
  
  if (ui.cursor!=NULL) { 
    gdk_cursor_unref(ui.cursor);
    ui.cursor = NULL;
  }
  if (ui.cur_item_type == ITEM_MOVESEL_VERT)
    ui.cursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW);
  else if (ui.cur_item_type == ITEM_MOVESEL)
    ui.cursor = gdk_cursor_new(GDK_FLEUR);
  else if (ui.toolno[ui.cur_mapping] == TOOL_PEN) {
    fg.red = (ui.cur_brush->color_rgba >> 16) & 0xff00;
    fg.green = (ui.cur_brush->color_rgba >> 8) & 0xff00;
    fg.blue = (ui.cur_brush->color_rgba >> 0) & 0xff00;
    source = gdk_bitmap_create_from_data(NULL, cursor_pen_bits, 16, 16);
    ui.cursor = gdk_cursor_new_from_pixmap(source, source, &fg, &bg, 7, 7);
    gdk_bitmap_unref(source);
  }
Esempio n. 26
0
wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy )
{
    wxCHECK_MSG( Ok(), wxNullBitmap, wxT("invalid bitmap") );

    if (newy==M_BMPDATA->m_width && newy==M_BMPDATA->m_height)
        return *this;
    
    int width = wxMax(newx, 1);
    int height = wxMax(newy, 1);
    width = wxMin(width, clipwidth);
    height = wxMin(height, clipheight);
        
    wxBitmap bmp;

#ifdef __WXGTK20__
    if (HasPixbuf())
    {
        bmp.SetWidth(width);
        bmp.SetHeight(height);
        bmp.SetDepth(GetDepth());
        bmp.SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB,
                                     gdk_pixbuf_get_has_alpha(GetPixbuf()),
                                     8, width, height));
        gdk_pixbuf_scale(GetPixbuf(), bmp.GetPixbuf(),
                         0, 0, width, height,
                         clipx, clipy, 
                         (double)newx/GetWidth(), (double)newy/GetHeight(),
                         GDK_INTERP_BILINEAR);
    }
    else
#endif // __WXGTK20__
    {
        GdkImage *img = (GdkImage*) NULL;
        if (GetPixmap())
            img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() );
        else if (GetBitmap())
            img = gdk_image_get( GetBitmap(), 0, 0, GetWidth(), GetHeight() );
        else
            wxFAIL_MSG( wxT("Ill-formed bitmap") );

        wxCHECK_MSG( img, wxNullBitmap, wxT("couldn't create image") );

        int bpp = -1;

        
        GdkGC *gc = NULL;
        GdkPixmap *dstpix = NULL;
        if (GetPixmap())
        {
            GdkVisual *visual = gdk_window_get_visual( GetPixmap() );
            if (visual == NULL)
                visual = wxTheApp->GetGdkVisual();

            bpp = visual->depth;
            bmp = wxBitmap(width,height,bpp);
            dstpix = bmp.GetPixmap();
            gc = gdk_gc_new( dstpix );
        }

        char *dst = NULL;
        long dstbyteperline = 0;
        
        if (GetBitmap())
        {
            bpp = 1;
            dstbyteperline = width/8*M_BMPDATA->m_bpp;
            if (width*M_BMPDATA->m_bpp % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
        }
                 
        // be careful to use the right scaling factor
        float scx = (float)M_BMPDATA->m_width/(float)newx;
        float scy = (float)M_BMPDATA->m_height/(float)newy;
        // prepare accel-tables
        int *tablex = (int *)calloc(width,sizeof(int));
        int *tabley = (int *)calloc(height,sizeof(int));

        // accel table filled with clipped values
        for (int x = 0; x < width; x++)
            tablex[x] = (int) (scx * (x+clipx));
        for (int y = 0; y < height; y++)
            tabley[y] = (int) (scy * (y+clipy));

        // Main rescaling routine starts here
        for (int h = 0; h < height; h++)
        {
            char outbyte = 0;
            int old_x = -1;
            guint32 old_pixval = 0;

            for (int w = 0; w < width; w++)
            {
                guint32 pixval;
                int x = tablex[w];
                if (x == old_x)
                    pixval = old_pixval;
                else
                {
                    pixval = gdk_image_get_pixel( img, x, tabley[h] );
                    old_pixval = pixval;
                    old_x = x;
                }
                    
                if (bpp == 1)
                {
                    if (!pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8==0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
                else
                {
                    GdkColor col;
                    col.pixel = pixval;
                    gdk_gc_set_foreground( gc, &col );
                    gdk_draw_point( dstpix, gc, w, h);
                }
            }
        
            // do not forget the last byte
            if ((bpp == 1) && (width % 8 != 0))
                dst[h*dstbyteperline+width/8] = outbyte;
        }
        
        gdk_image_destroy( img );
        if (gc) gdk_gc_unref( gc );

        if (bpp == 1)
        {
            bmp = wxBitmap( (const char *)dst, width, height, 1 );
            free( dst );
        }
        
        if (GetMask())
        {
            dstbyteperline = width/8;
            if (width % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
            img = gdk_image_get( GetMask()->GetBitmap(), 0, 0, GetWidth(), GetHeight() );

            for (int h = 0; h < height; h++)
            {
                char outbyte = 0;
                int old_x = -1;
                guint32 old_pixval = 0;
        
                for (int w = 0; w < width; w++)
                {
                    guint32 pixval;
                    int x = tablex[w];
                    if (x == old_x)
                        pixval = old_pixval;
                    else
                    {
                        pixval = gdk_image_get_pixel( img, x, tabley[h] );
                        old_pixval = pixval;
                        old_x = x;
                    }
                    
                    if (pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8 == 0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
            
                // do not forget the last byte
                if (width % 8 != 0)
                    dst[h*dstbyteperline+width/8] = outbyte;
            }
            wxMask* mask = new wxMask;
            mask->m_bitmap = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) dst, width, height );
            bmp.SetMask(mask);

            free( dst );
            gdk_image_destroy( img );
        }

        free( tablex );
        free( tabley );
    }
    
    return bmp; 
}
Esempio n. 27
0
main(int argc, char *argv[])
{
   int n;
   int rows, cols;
   int drawButtons;
   char *btn_font, *disp_font;
   /* GtkWidget *main_w; */
   GtkWidget *vbox;
   GtkWidget *menu;
   GtkWidget *mdisp;
   GtkWidget *lcd;
   GtkWidget *btns;
   GdkFont *new_font;
   GtkStyle *default_style, *new_style;
   GdkBitmap *icon_bitmap;
#ifdef USE_GNOME
   GnomeAppBar *appbar;
#endif

   setlocale(LC_ALL, "C");
#ifdef USE_GNOME
   gnome_init("grpn", "1.0", argc, argv);
   gnome_app_new("grpn", "grpn");
#else
   /* initialize gtk */
   gtk_init(&argc, &argv);
#endif

   /* initial values */
   drawButtons = 1;
   rows = 8;
   cols = 30;
   btn_font = disp_font = NULL;

   /* process command line args */
   n = 1;
   while(n < argc){
      if(0 == strcmp("-fn", argv[n])){
         n++;
         if(n >= argc){
            usage("Missing required argument for -fn.");
            exit(0);
         }
         btn_font = disp_font = argv[n];
      } else if(0 == strcmp("-btn-fn", argv[n])){
         n++;
         if(n >= argc){
            usage("Missing required argument for -btn-fn.");
            exit(0);
         }
         btn_font = argv[n];
      } else if(0 == strcmp("-disp-fn", argv[n])){
         n++;
         if(n >= argc){
            usage("Missing required argument for -disp-fn.");
            exit(0);
         }
         disp_font = argv[n];
      } else if(0 == strcmp("-rows", argv[n])){
         n++;
         if(n >= argc){
            usage("Missing required argument for -rows.");
            exit(0);
         }
         if(1 != sscanf(argv[n], "%d", &rows)){
            usage("Unable to read number or rows.");
            exit(0);
         }
      } else if(0 == strcmp("-cols", argv[n])){
         n++;
         if(n >= argc){
            usage("Missing required argument for -cols.");
            exit(0);
         }
         if(1 != sscanf(argv[n], "%d", &cols)){
            usage("Unable to read number or cols.");
            exit(0);
         }
      } else if(0 == strcmp("-b", argv[n])){
         drawButtons = 0;
      } else if(0 == strcmp("-bm", argv[n])){
         n++;
         if(n >= argc){
            usage("Missing required argument for -m.");
            exit(0);
         }
         if (0 == strcmp("dec", argv[n])){
             setBaseMode(DECIMAL);
	 } else if (0 == strcmp("eng", argv[n])){
             setBaseMode(DECIMAL_ENG);
	 } else if (0 == strcmp("bin", argv[n])){
             setBaseMode(BINARY);
	 } else if (0 == strcmp("oct", argv[n])){
             setBaseMode(OCTAL);
	 } else if (0 == strcmp("hex", argv[n])){
             setBaseMode(HEXADECIMAL);
	 } else {
             usage("Specify dec, eng, bin, oct or hex for -m.");
             exit(0);
         }
      } else {
         usage("Unknown Argument.");
         exit(0);
      }
      n++;
   }

   /* set up any constants we may use */
   setup_constant();

   /* initialize the undo system */
   initUndoSystem();

   /* setup the stack */
   if(0 == setup_stack()){
      fprintf(stderr, "Error: Could not initalize data structures.\n");
      exit(0);
   }

   /* set the font if told */
   if(btn_font != NULL){
      default_style = gtk_widget_get_default_style();
      if(NULL == (new_font = gdk_font_load(btn_font))){
         fprintf(stderr, "Unable to load font %s.\n", btn_font);
         exit(0);
      }
      new_style = gtk_style_copy(default_style);
      new_style->font_desc = new_font;
/* BDD - No longer in Gtk2.x */
/*      gtk_widget_set_default_style(new_style); */
   }
   

#ifdef USE_GNOME
   main_w = gnome_app_new("grpn", "grpn");
   setup_menu(main_w);

   appbar = GNOME_APPBAR(gnome_appbar_new(FALSE, FALSE, FALSE));
   gnome_app_set_statusbar(GNOME_APP(main_w), GTK_WIDGET(appbar));

   /*create the box that everyone goes in */
   vbox = gtk_vbox_new(FALSE, 0);
   gnome_app_set_contents(GNOME_APP(main_w), vbox);
   gtk_widget_show(vbox);

#else
   /* the main window contains the work area and the menubar */
   main_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_name(main_w, "grpn");

   /*create the box that everyone goes in */
   vbox = gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(main_w), vbox);
   gtk_widget_show(vbox);

   /* set up the menu bar */
   menu = setup_menu(vbox);
#endif

   /* handle window manager close */
   gtk_signal_connect(GTK_OBJECT(main_w), "delete_event",
      GTK_SIGNAL_FUNC(delete_event), NULL);
   gtk_signal_connect(GTK_OBJECT(main_w), "destroy",
      GTK_SIGNAL_FUNC(destroy), NULL);

   /* create the varrious subsystems */
   mdisp = setupModeDisplay(vbox);
   if(drawButtons) btns = setupButtons(vbox);
   lcd = setupLCD(vbox, rows, cols, disp_font);

   /* Create pixmap of depth 1 (bitmap) for icon */
   gtk_widget_realize(main_w);
   icon_bitmap = gdk_bitmap_create_from_data(main_w->window,
      icon_bitmap_bits, icon_bitmap_width, icon_bitmap_height);
   gdk_window_set_icon(main_w->window, NULL, icon_bitmap, NULL);

   gtk_widget_show(main_w);

   gtk_main();

}
Esempio n. 28
0
void resource_format_type_image(GtkImage * image, const gint * resources,
				gint max_width)
{
	gint num_res, tot_res, idx, i, pos;

	GdkPixmap *p, *pdest;
	GdkBitmap *b, *bdest;
	gchar *data;
	gint size, step;
	gint width;
	cairo_t *cr;
	GdkRectangle r;

	num_res = tot_res = 0;
	for (idx = 0; idx < NO_RESOURCE; idx++) {
		if (resources[idx]) {
			num_res++;
			tot_res += resources[idx];
		}
	}

	if (tot_res == 0) {
		tot_res = 1;	/* Avoid division by zero */
	}

	size = gui_get_resource_pixmap_res();
	pos = 0;

	if (max_width <= 0 || tot_res == num_res
	    || max_width >= size * tot_res) {
		step = size;
		width = size * num_res + step * (tot_res - num_res);
		if (width < max_width)
			width = max_width;
	} else {
		step = (max_width - num_res * size) / (tot_res - num_res);
		if (step <= 0)
			step = 1;
		width = max_width;
	}

	pdest =
	    gdk_pixmap_new(NULL,
			   width, size, gdk_visual_get_system()->depth);
	data = g_malloc0((((width + 7) >> 3) * size));
	bdest =
	    gdk_bitmap_create_from_data(NULL, data,
					size * num_res + step * (tot_res -
								 num_res),
					size);
	g_free(data);

	r.x = 0;
	r.y = 0;
	r.width = width;
	r.height = width;
	for (idx = 0; idx < NO_RESOURCE; idx++) {
		if (!resources[idx])
			continue;
		gui_get_resource_pixmap(idx, &p, &b);
		for (i = 0; i < resources[idx]; i++) {
			cr = gdk_cairo_create(pdest);
			gdk_cairo_set_source_pixmap(cr, p, pos, 0);
			gdk_cairo_rectangle(cr, &r);
			cairo_fill(cr);
			cairo_destroy(cr);

			cr = gdk_cairo_create(bdest);
			gdk_cairo_set_source_pixmap(cr, b, pos, 0);
			gdk_cairo_rectangle(cr, &r);
			cairo_fill(cr);
			cairo_destroy(cr);

			pos += step;
		}
		pos += size - step;
	}

	gtk_image_set_from_pixmap(image, pdest, bdest);

	g_object_unref(pdest);
	g_object_unref(bdest);
}
Esempio n. 29
0
void* iupdrvImageCreateCursor(Ihandle *ih)
{
  GdkCursor *cursor;
  int hx, hy, bpp;

  hx=0; hy=0;
  iupStrToIntInt(iupAttribGet(ih, "HOTSPOT"), &hx, &hy, ':');

  bpp = iupAttribGetInt(ih, "BPP");

  if (bpp == 8 && !iupAttribGet(ih, "3"))
  {
    GdkPixmap *source, *mask;
    GdkColor fg, bg;
    unsigned char r, g, b;
    char *sbits, *mbits, *sb, *mb;
    int y, x, line_size = (ih->currentwidth+7)/8;
    int size_bytes = line_size*ih->currentheight;
    unsigned char* imgdata = (unsigned char*)iupAttribGetStr(ih, "WID");

    r = 255; g = 255; b = 255;
    iupStrToRGB(iupAttribGet(ih, "1"), &r, &g, &b );
    iupgdkColorSet(&fg, r, g, b);

    r = 0; g = 0; b = 0;
    iupStrToRGB(iupAttribGet(ih, "2"), &r, &g, &b );
    iupgdkColorSet(&bg, r, g, b);

    sbits = (char*)malloc(2*size_bytes);
    if (!sbits) return NULL;
    memset(sbits, 0, 2*size_bytes);
    mbits = sbits + size_bytes;

    sb = sbits;
    mb = mbits;
    for (y=0; y<ih->currentheight; y++)
    {
      for (x=0; x<ih->currentwidth; x++)
      {
        int byte = x/8;
        int bit = x%8;
        int index = (int)imgdata[y*ih->currentwidth+x];
        /* index==0 is transparent */
        if (index == 1)
          sb[byte] = (char)(sb[byte] | (1<<bit));
        if (index != 0)
          mb[byte] = (char)(mb[byte] | (1<<bit));
      }

      sb += line_size;
      mb += line_size;
    }
  
    source = gdk_bitmap_create_from_data(NULL, sbits, ih->currentwidth, ih->currentheight);
    mask = gdk_bitmap_create_from_data(NULL, mbits, ih->currentwidth, ih->currentheight);

    cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, hx, hy);

    gdk_pixmap_unref(source);
    gdk_pixmap_unref(mask);
    free(sbits);
  }
  else
  {
    GdkPixbuf* pixbuf = iupdrvImageCreateImage(ih, NULL, 0);
    cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, hx, hy);
    g_object_unref(pixbuf);
  }

  return cursor;
}
Esempio n. 30
0
void initGui( JunoControl* _junoControl, 
	      Settings* _settings, 
	      MidiInput* _midiInput, 
	      int numVoices)
{
    junoControl = _junoControl;
    settings    = _settings;
    midiInput   = _midiInput;

    keyboard = new JunoKeyboard(numVoices);
    
    mainMenu = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", NULL);
    gtk_item_factory_create_items(mainMenu, mainwin_general_menu_entry_count,
				  mainwin_general_menu_entries, NULL);
    GtkStyle* menuStyle = gtk_style_new(); // a default style
    gtk_widget_set_style( mainMenu->widget, menuStyle );

    GtkWidget* mainContainer;

    mainWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );

    gtk_widget_add_events( GTK_WIDGET( mainWindow ), 
			   GDK_BUTTON_RELEASE_MASK |
			   GDK_POINTER_MOTION_MASK | 
			   GDK_POINTER_MOTION_HINT_MASK |
			   GDK_ENTER_NOTIFY_MASK | 
			   GDK_LEAVE_NOTIFY_MASK | 
			   GDK_KEY_PRESS_MASK | 
			   GDK_KEY_RELEASE_MASK	);

    gtk_window_set_default_size( GTK_WINDOW( mainWindow ), 940, 224 );
    gtk_window_set_policy(GTK_WINDOW(mainWindow), FALSE, FALSE, TRUE);

    gtk_widget_realize( mainWindow );
    gdk_window_set_decorations( mainWindow->window, (GdkWMDecoration)0 );
    gtk_widget_set_app_paintable(mainWindow, TRUE);

    gtk_signal_connect(GTK_OBJECT(mainWindow), "button_press_event", 
		       GTK_SIGNAL_FUNC(mainWindow_press), NULL);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "button_release_event", 
		       GTK_SIGNAL_FUNC(mainWindow_release), NULL);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "motion_notify_event", 
		       GTK_SIGNAL_FUNC(mainWindow_motion), NULL);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "enter_notify_event",
		       GTK_SIGNAL_FUNC(mainWindow_enter), NULL);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "leave_notify_event",
		       GTK_SIGNAL_FUNC(mainWindow_leave), NULL);

    mainContainer = gtk_fixed_new();

    gtk_widget_show( mainWindow );
    gtk_widget_show( mainContainer );

    GdkPixmap* image = gdk_pixmap_create_from_xpm_d( mainWindow->window, 
						     NULL, 
						     NULL, 
						     juno_background_data );
    GtkWidget* pixmap = gtk_pixmap_new( image, NULL );
    gtk_widget_show( pixmap );
    gtk_fixed_put( GTK_FIXED( mainContainer ), pixmap, 0, 0 );

    gtk_container_add( GTK_CONTAINER( mainWindow ), mainContainer );

    init();
    layout( GTK_FIXED( mainContainer ) );

    GdkBitmap* mask = gdk_bitmap_create_from_data( mainWindow->window, 
						   juno_background_mask_bits,
						   juno_background_mask_width,
						   juno_background_mask_height );

    gtk_widget_shape_combine_mask( mainWindow, mask, 0, 0 );
}