static VALUE
gdkwin_shape_combine_mask(VALUE self, VALUE shape_mask, VALUE offset_x, VALUE offset_y)
{
    gdk_window_shape_combine_mask(_SELF(self), 
                                  GDK_BITMAP(RVAL2GOBJ(shape_mask)), 
                                  NUM2INT(offset_x), NUM2INT(offset_y));
    return self;
}
Exemple #2
0
void UI_buildui(IBusHandwriteEngine * engine)
{
	GdkPixmap * pxmp;
	GdkGC * gc;
	GdkColor black, white;

	GdkColormap* colormap = gdk_colormap_get_system();

	gdk_color_black(colormap, &black);
	gdk_color_white(colormap, &white);

	g_object_unref(colormap);

	int R = 5;

	if (!engine->drawpanel)
	//建立绘图窗口, 建立空点
	{
		engine->drawpanel = gtk_window_new(GTK_WINDOW_POPUP);
		gtk_window_move((GtkWindow*) engine->drawpanel, 500, 550);
		gtk_widget_add_events(GTK_WIDGET(engine->drawpanel),
				GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK
						| GDK_BUTTON_PRESS_MASK | GDK_EXPOSURE_MASK);
		g_signal_connect_after(G_OBJECT(engine->drawpanel),"motion_notify_event",G_CALLBACK(on_mouse_move),engine);
		g_signal_connect(G_OBJECT(engine->drawpanel),"expose-event",G_CALLBACK(paint_ui),engine);
		g_signal_connect(G_OBJECT(engine->drawpanel),"button-release-event",G_CALLBACK(on_button),engine);
		g_signal_connect(G_OBJECT(engine->drawpanel),"button-press-event",G_CALLBACK(on_button),engine);

		gtk_window_resize(GTK_WINDOW(engine->drawpanel), 200, 250);

		gtk_widget_show(engine->drawpanel);

		pxmp = gdk_pixmap_new(NULL, 200, 250, 1);
		gc = gdk_gc_new(GDK_DRAWABLE(pxmp));

		gdk_gc_set_foreground(gc, &black);

		gdk_draw_rectangle(GDK_DRAWABLE(pxmp), gc, 1, 0, 0, 200, 250);

		gdk_gc_set_foreground(gc, &white);

		gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 0, 0, R*2, R*2, 0, 360 * 64);
		gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 200 - R*2, 0, R*2, R*2, 0, 360
				* 64);
		gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 200 - R*2, 250 - R*2, R*2, R*2, 0,
				360 * 64);
		gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 0, 250 - R*2, R*2, R*2, 0, 360
				* 64);
		gdk_draw_rectangle(GDK_DRAWABLE(pxmp), gc, 1, 0, R, 200, 250 - R*2);
		gdk_draw_rectangle(GDK_DRAWABLE(pxmp), gc, 1, R, 0, 200 - R*2, 250);
		gdk_window_shape_combine_mask(engine->drawpanel->window, pxmp, 0, 0);
		g_object_unref(gc);
		g_object_unref(pxmp);
		gtk_window_set_opacity(GTK_WINDOW(engine->drawpanel), 0.62);
		//	engine->GdkPoints = NULL;
	}
	//	gtk_widget_show_all(engine->drawpanel);
}
Exemple #3
0
void gMainWindow::drawMask()
{
	bool do_remap = false;
	 
	if (!isVisible())
		return;
	
#ifdef GTK3

	cairo_region_t *mask;

	if (_mask && _picture)
		mask = gdk_cairo_region_create_from_surface(_picture->getSurface());
	else
		mask = NULL;

	gdk_window_shape_combine_region(gtk_widget_get_window(border), mask, 0, 0);
	if (mask)
		cairo_region_destroy(mask);

	refresh();

#else

	GdkBitmap *mask = (_mask && _picture) ? _picture->getMask() : NULL;
	do_remap = !mask && _masked;

	gdk_window_shape_combine_mask(border->window, mask, 0, 0);

#endif

	if (_picture)
	{
		gtk_widget_set_app_paintable(border, TRUE);
		gtk_widget_realize(border);
		gtk_widget_realize(widget);
		for (int i = 0; i < controlCount(); i++)
			getControl(i)->refresh();
	}
	else if (!_transparent)
	{
		gtk_widget_set_app_paintable(border, FALSE);
		setRealBackground(background());
	}
	
	_masked = mask != NULL;
	
	if (do_remap)
		remap();
	else
	{
		if (!_skip_taskbar)
		{
			setSkipTaskBar(true);
			setSkipTaskBar(false);
		}
	}
}
Exemple #4
0
// helper
static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
{
    if (window)
    {
        if (region.IsEmpty())
        {
            gdk_window_shape_combine_mask(window, NULL, 0, 0);
        }
        else
        {
            wxBitmap bmp = region.ConvertToBitmap();
            bmp.SetMask(new wxMask(bmp, *wxBLACK));
            GdkBitmap* mask = bmp.GetMask()->GetBitmap();
            gdk_window_shape_combine_mask(window, mask, 0, 0);
            return true;
        }
    }
    return false;
}
Exemple #5
0
    virtual bool DoSetShape(GdkWindow *window)
    {
        GdkBitmap* bitmap = m_mask.GetBitmap();
        if ( !bitmap )
            return false;

        gdk_window_shape_combine_mask(window, bitmap, 0, 0);

        return true;
    }
static gboolean
paint_window(GtkWidget *widget,
			 GdkEventExpose *event,
			 WindowData *windata)
{
	if (windata->width == 0) {
		windata->width = windata->win->allocation.width;
		windata->height = windata->win->allocation.height;
	}
	
	if (!(windata->enable_transparency))
	{
			GdkPixmap *mask;
			cairo_t *mask_cr;
			mask = gdk_pixmap_new (NULL, windata->width, 
						     windata->height, 1);
			mask_cr = gdk_cairo_create ((GdkDrawable *) mask);
			cairo_set_operator (mask_cr, CAIRO_OPERATOR_CLEAR);
			cairo_paint (mask_cr);

			cairo_set_operator (mask_cr, CAIRO_OPERATOR_OVER);
			cairo_set_source_rgba (mask_cr, 1, 1, 1, 1);
            nodoka_rounded_rectangle (mask_cr, 0, 0, 
                windata->width, windata->height, 6);
			cairo_fill (mask_cr);
			gdk_window_shape_combine_mask (windata->win->window,
						       (GdkBitmap *) mask, 0,0);
			gdk_pixmap_unref (mask);
			cairo_destroy (mask_cr);
	}

	cairo_t *context;
	cairo_surface_t *surface;
	cairo_t *cr;

	context = gdk_cairo_create(widget->window);

	cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
	surface = cairo_surface_create_similar(cairo_get_target(context),
										   CAIRO_CONTENT_COLOR_ALPHA,
										   widget->allocation.width,
										   widget->allocation.height);
	cr = cairo_create(surface);

	fill_background(widget, windata, cr);

	cairo_destroy(cr);
	cairo_set_source_surface(context, surface, 0, 0);
	cairo_paint(context);
	cairo_surface_destroy(surface);
	cairo_destroy(context);

	return FALSE;
}
static void
update_shape (GsdLocatePointerData *data)
{
  cairo_t *cr;
  GdkBitmap *mask;

  mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1);
  cr = gdk_cairo_create (mask);
  locate_pointer_paint (data, cr, FALSE);
  gdk_window_shape_combine_mask (data->window, mask, 0, 0);
  g_object_unref (mask);
  cairo_destroy (cr);
}
Exemple #8
0
    virtual bool DoSetShape(GdkWindow *window)
    {
        if (!m_mask)
            return false;

#ifdef __WXGTK3__
        cairo_region_t* region = gdk_cairo_region_create_from_surface(m_mask);
        gdk_window_shape_combine_region(window, region, 0, 0);
        cairo_region_destroy(region);
#else
        gdk_window_shape_combine_mask(window, m_mask, 0, 0);
#endif

        return true;
    }
Exemple #9
0
Error GTKWindow::VulcanMindMeld(Window *pOther)
{
    Error eRet;
    Rect  oRect;

    m_pMindMeldMutex->Acquire();

    gdk_threads_enter();
    gdk_flush();
    gdk_threads_leave();

    oRect.x1 = oRect.x2 = oRect.y1 = oRect.y2 = 0;
    GetWindowPosition(oRect);

    eRet = Window::VulcanMindMeld(pOther);

    if (IsError(eRet)) {
        m_pMindMeldMutex->Release();
        return eRet;
    }

    Rect oNewRect, oSize;
    
    m_pCanvas->GetBackgroundRect(oSize);
    GdkBitmap *mask = ((GTKCanvas *)m_pCanvas)->GetMask();

    GetReloadWindowPos(oRect, oSize.Width(), oSize.Height(), oNewRect);

    gdk_threads_enter();
    gtk_widget_set_uposition(mainWindow, oNewRect.x1, oNewRect.y1);
    gtk_widget_set_usize(mainWindow, oNewRect.Width(), oNewRect.Height());
    if (mask)
        gdk_window_shape_combine_mask(mainWindow->window, mask, 0, 0);
    gdk_threads_leave();

    Pos NewPos;
    NewPos.x = oNewRect.x1;
    NewPos.y = oNewRect.y1;

    SaveWindowPos(NewPos);

    ((GTKCanvas *)m_pCanvas)->SetParent(this);
    m_pCanvas->Update();
 
    m_pMindMeldMutex->Release();

    return kError_NoErr;
}
Exemple #10
0
// helper
static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
{
    if (window)
    {
        if (region.IsEmpty())
        {
            gdk_window_shape_combine_mask(window, NULL, 0, 0);
        }
        else
        {
            gdk_window_shape_combine_region(window, region.GetRegion(), 0, 0);
            return true;
        }
    }
    return false;
}
static void
set_transparent_shape (GdkWindow *window)
{
  GdkBitmap *mask;
  cairo_t *cr;

  mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1);
  cr = gdk_cairo_create (mask);

  cairo_set_source_rgba (cr, 1., 1., 1., 0.);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);

  gdk_window_shape_combine_mask (data->window, mask, 0, 0);
  g_object_unref (mask);
  cairo_destroy (cr);
}
Exemple #12
0
void GTKWindow::PanelStateChanged(void)
{
    Rect       oRect;
    GdkBitmap *mask;

    GetCanvas()->SetNoScreenUpdate(true);

    Window::PanelStateChanged();

    GetCanvas()->GetBackgroundRect(oRect);
    mask = ((GTKCanvas *)m_pCanvas)->GetMask();

    gdk_threads_enter();
    if (mask)
        gdk_window_shape_combine_mask(mainWindow->window, mask, 0, 0);
    gtk_widget_set_usize(mainWindow, oRect.Width(), oRect.Height());
    gdk_threads_leave();

    GetCanvas()->SetNoScreenUpdate(false);

    ((GTKCanvas *)GetCanvas())->Paint(oRect);
}
Exemple #13
0
// set the shape and background of the main window
void set_window_shape(char *filepad) {
    GtkRcStyle *style;
    GError *error=NULL;

    pixelbuffer = gdk_pixbuf_new_from_file(filepad, &error);

    if (error)
		fprintf(stderr, "set windowshape error: %s\n", error->message);

    gdk_pixbuf_render_pixmap_and_mask(pixelbuffer, &gdk_pixmap, &win_mask, 1);

    // set background image
    style = gtk_widget_get_modifier_style(GTK_WIDGET(window));
    style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup(filepad);
    gtk_widget_modify_style(GTK_WIDGET(window), style);

    // set the shape
    gdk_window_shape_combine_mask(window->window, win_mask,0,0);

    // set the size
    width = gdk_pixbuf_get_width(pixelbuffer);
    height = gdk_pixbuf_get_height(pixelbuffer);
    gtk_widget_set_usize(window, width, height);
}
Exemple #14
0
G_MODULE_EXPORT gboolean
display_show(NOTIFICATION_INFO* ni) {
  GdkColor color;
  GtkWidget* vbox;
  GtkWidget* hbox;
  GtkWidget* label;
  GtkWidget* image;
  GdkScreen* screen;
  gint n, pos, len;
  gint x, y;
  gint monitor_num;
  GdkRectangle rect;

  DISPLAY_INFO* di = g_new0(DISPLAY_INFO, 1);
  if (!di) {
    perror("g_new0");
    return FALSE;
  }
  di->ni = ni;

  len = g_list_length(notifications);
  for (pos = 0; pos < len; pos++) {
    DISPLAY_INFO* p = g_list_nth_data(notifications, pos);
    if (pos != p->pos) break;
  }

  screen = gdk_screen_get_default();
  monitor_num = gdk_screen_get_primary_monitor(screen);
  gdk_screen_get_monitor_geometry(screen, monitor_num, &rect);

  x = rect.x + rect.width - 250;
  y = rect.y + rect.height - 110;
  for (n = 0; n < pos; n++) {
    y -= 110;
    if (y < 0) {
      x -= 250;
      if (x < 0) {
        return FALSE;
      }
      y = rect.y + rect.height - 110;
    }
  }

  di->pos = pos;
  notifications = g_list_insert_sorted(notifications, di, notifications_compare);
  di->x = x;
  di->y = y;

  di->popup = gtk_window_new(GTK_WINDOW_POPUP);
  gtk_window_set_title(GTK_WINDOW(di->popup), "growl-for-linux");
  gtk_window_set_resizable(GTK_WINDOW(di->popup), FALSE);
  gtk_window_set_decorated(GTK_WINDOW(di->popup), FALSE);
  gtk_window_set_keep_above(GTK_WINDOW(di->popup), TRUE);

  gtk_window_stick(GTK_WINDOW(di->popup));

  vbox = gtk_vbox_new(FALSE, 5);
  gtk_container_set_border_width(GTK_CONTAINER(vbox), 18);
  gtk_container_add(GTK_CONTAINER(di->popup), vbox);

  hbox = gtk_hbox_new(FALSE, 5);
  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);

  if (di->ni->icon && *di->ni->icon) {
    GdkPixbuf* pixbuf;
    if (di->ni->local) {
      gchar* newurl = g_filename_from_uri(di->ni->icon, NULL, NULL);
      GError* error = NULL;
      pixbuf = gdk_pixbuf_new_from_file(newurl ? newurl : di->ni->icon, &error);
      if (newurl) g_free(newurl);
    } else
      pixbuf = url2pixbuf(di->ni->icon, NULL);
    if (pixbuf) {
      GdkPixbuf* tmp = gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_TILES);
      if (tmp) {
        g_object_unref(pixbuf);
        pixbuf = tmp;
      }
      image = gtk_image_new_from_pixbuf(pixbuf);
      gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
      g_object_unref(pixbuf);
    }
  }

  PangoFontDescription* font_desc;
  
  font_desc = pango_font_description_new();
  pango_font_description_set_family(font_desc, "Sans");
  pango_font_description_set_size(font_desc, 12 * PANGO_SCALE);

  label = gtk_label_new(di->ni->title);
  gdk_color_parse("white", &color);
  gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color);
  gtk_widget_modify_font(label, font_desc);
  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);

  pango_font_description_free(font_desc);

  font_desc = pango_font_description_new();
  pango_font_description_set_family(font_desc, "Sans");
  pango_font_description_set_size(font_desc, 8 * PANGO_SCALE);

  label = gtk_label_new(di->ni->text);
  gdk_color_parse("white", &color);
  gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color);
  gtk_widget_modify_font(label, font_desc);
  g_signal_connect(G_OBJECT(label), "size-allocate", G_CALLBACK(label_size_allocate), NULL);
  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
  gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
  gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_CHAR);
  gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, FALSE, 0);

  pango_font_description_free(font_desc);

  gtk_widget_set_events(di->popup, GDK_BUTTON_PRESS_MASK);
  g_signal_connect(G_OBJECT(di->popup), "button-press-event", G_CALLBACK(display_clicked), di);

  di->offset = 0;
  di->timeout = 500;

  gtk_window_move(GTK_WINDOW(di->popup), di->x, di->y);
  gtk_window_set_opacity(GTK_WINDOW(di->popup), 0);
  gtk_widget_set_app_paintable(di->popup, TRUE);
  gtk_widget_show_all(di->popup);

  if (pixmap == NULL) {
     pixmap = gdk_pixmap_create_from_xpm_d(di->popup->window, &bitmap, NULL, balloon);
  }
  gdk_drawable_get_size(pixmap, &pixmap_width, &pixmap_height);
  gtk_widget_set_size_request(di->popup, pixmap_width, pixmap_height);
  gdk_window_shape_combine_mask(di->popup->window, bitmap, 0, 0);
  g_signal_connect(G_OBJECT(di->popup), "expose-event", G_CALLBACK(display_expose), di);

  g_timeout_add(10, display_animation_func, di);

  return FALSE;
}
Exemple #15
0
G_MODULE_EXPORT gboolean
display_show(NOTIFICATION_INFO* ni) {

  DISPLAY_INFO* di = g_new0(DISPLAY_INFO, 1);
  if (!di) {
    perror("g_new0");
    return FALSE;
  }
  di->ni = ni;

  notifications = g_list_append(notifications, di);

  di->popup = gtk_window_new(GTK_WINDOW_POPUP);
  gtk_window_set_title(GTK_WINDOW(di->popup), "growl-for-linux");
  gtk_window_set_resizable(GTK_WINDOW(di->popup), TRUE);
  gtk_window_set_decorated(GTK_WINDOW(di->popup), FALSE);
  gtk_window_set_keep_above(GTK_WINDOW(di->popup), TRUE);

  gtk_widget_modify_bg(di->popup, GTK_STATE_NORMAL, colors + (rand() % lengthof(available_colors)));

  gtk_window_stick(GTK_WINDOW(di->popup));

  GtkWidget* ebox = gtk_event_box_new();
  gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
  gtk_container_add(GTK_CONTAINER(di->popup), ebox);

  GtkWidget* fixed = gtk_fixed_new();
  gtk_container_set_border_width(GTK_CONTAINER(fixed), 0);
  gtk_container_add(GTK_CONTAINER(ebox), fixed);

  GtkWidget* image = NULL;
  if (di->ni->icon && *di->ni->icon) {
    GdkPixbuf* pixbuf;
    if (di->ni->local) {
      gchar* newurl = g_filename_from_uri(di->ni->icon, NULL, NULL);
      GError* error = NULL;
      pixbuf = gdk_pixbuf_new_from_file(newurl ? newurl : di->ni->icon, &error);
      g_free(newurl);
    } else {
      pixbuf = pixbuf_from_url(di->ni->icon, NULL);
    }

    if (pixbuf) {
      GdkPixbuf* tmp = gdk_pixbuf_scale_simple(pixbuf, 32, 32, GDK_INTERP_TILES);
      if (tmp) {
        g_object_unref(pixbuf);
        pixbuf = tmp;
      }
      image = gtk_image_new_from_pixbuf(pixbuf);
      gtk_container_add(GTK_CONTAINER(fixed), image);
      g_object_unref(pixbuf);
    }
  }

  PangoContext* context = gtk_widget_get_pango_context(di->popup) ;
  PangoLayout* layout = pango_layout_new(context);

  gchar* text = g_strconcat(di->ni->title, "\n", di->ni->text, NULL);
  pango_layout_set_text(layout, text, -1);
  g_free(text);
  pango_layout_set_font_description(layout, font_sans20_desc);
  pango_layout_get_pixel_size(layout, &di->width, &di->height);

  di->x = screen_rect.width;
  di->y = screen_rect.y + rand() % (screen_rect.height - di->height);
  di->width += 32 + 5;

  if (image)
    gtk_fixed_move(GTK_FIXED(fixed), image, 0, di->height / 2 - 16);
  GdkBitmap* bitmap = gdk_pixmap_new(di->popup->window, di->width, di->height, 1);
  GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(bitmap));
  GdkColormap* colormap = gdk_colormap_get_system();
  gdk_gc_set_colormap(gc, colormap);

  gdk_colormap_alloc_color(colormap, color_black, TRUE, TRUE);
  gdk_gc_set_foreground (gc, color_black);
  gdk_draw_rectangle(bitmap, gc, TRUE, 0, 0, di->width, di->height);

  gdk_colormap_alloc_color(colormap, color_white, TRUE, TRUE);
  gdk_gc_set_foreground (gc, color_white);
  if (image)
    gdk_draw_rectangle(bitmap, gc, TRUE, 0, di->height / 2 - 16, 32, 32);
  gdk_draw_layout(bitmap, gc, 32 + 5, 0, layout);

  g_signal_connect(G_OBJECT(ebox), "button-press-event", G_CALLBACK(display_clicked), di);
  g_signal_connect(G_OBJECT(ebox), "enter-notify-event", G_CALLBACK(display_enter), di);
  g_signal_connect(G_OBJECT(ebox), "leave-notify-event", G_CALLBACK(display_leave), di);

  gtk_window_move(GTK_WINDOW(di->popup), di->x, di->y);
  gtk_widget_show_all(di->popup);

  gtk_widget_set_size_request(fixed, di->width, di->height);
  gdk_window_set_back_pixmap(di->popup->window, NULL, FALSE);
  gdk_window_shape_combine_mask(di->popup->window, bitmap, 0, 0);

  g_object_unref(gc);
  g_object_unref(layout);
  g_object_unref(context);
  g_object_unref(bitmap);

  g_object_ref(di->popup);
  g_timeout_add(100, display_animation_func, di);

  return FALSE;
}
Exemple #16
0
static gboolean
draw_simple_image (GtkStyle       *style,
                   GdkWindow      *window,
                   GdkRectangle   *area,
                   GtkWidget      *widget,
                   ThemeMatchData *match_data,
                   gboolean        draw_center,
                   gint            x,
                   gint            y,
                   gint            width,
                   gint            height)
{
  gboolean maemo_position_theming;
  ThemeImage *image;

  if ((width == -1) && (height == -1))
    gdk_drawable_get_size (window, &width, &height);
  else if (width == -1)
    gdk_drawable_get_size (window, &width, NULL);
  else if (height == -1)
    gdk_drawable_get_size (window, NULL, &height);

  if (!(match_data->flags & THEME_MATCH_ORIENTATION))
    {
      match_data->flags |= THEME_MATCH_ORIENTATION;

      if (height > width)
	match_data->orientation = GTK_ORIENTATION_VERTICAL;
      else
	match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
    }

  /* Check for maemo-position-theming to update the position data */
  if (widget && widget->parent &&
      gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget->parent),
                                            "maemo-position-theming"))
    {
      gtk_widget_style_get (widget->parent,
			    "maemo-position-theming", &maemo_position_theming,
			    NULL);
      if (maemo_position_theming)
	{
	  if (GTK_IS_BUTTON_BOX (widget->parent))
	    check_buttonbox_child_position (widget, match_data);
	  else
	    {
              /* Generic code for other kinds of containers */
	      GList *children;

	      children = gtk_container_get_children (GTK_CONTAINER (widget->parent));
	      check_child_position (widget, children, match_data);
	      g_list_free (children);
	    }
	}
    }

  image = match_theme_image (style, match_data);
  if (image)
    {
      if (image->background)
	{
	  GdkWindow *maskwin;
	  GdkBitmap *mask = NULL;
	  gboolean valid;

	  maskwin = get_window_for_shape (image, window, widget, x, y, width, height);
	  if (maskwin)
	    mask = gdk_pixmap_new (maskwin, width, height, 1);

          valid = theme_pixbuf_render (image->background, G_OBJECT_TYPE (widget),
				       window, mask, area,
				       draw_center ? COMPONENT_ALL : COMPONENT_ALL | COMPONENT_CENTER,
				       FALSE,
				       x, y, width, height);

	  if (mask)
	    {
	      if (valid)
		gdk_window_shape_combine_mask (maskwin, mask, 0, 0);
	      g_object_unref (mask);
	    }
	}

      if (image->overlay && draw_center)
        theme_pixbuf_render (image->overlay, G_OBJECT_TYPE (widget),
			     window, NULL, area, COMPONENT_ALL,
			     TRUE, 
			     x, y, width, height);

      return TRUE;
    }
  else
    return FALSE;
}
Exemple #17
0
static void
draw (GtkWidget *hand, cairo_t *cr)
{
	int x, y;
	HandDisplay *handdisp = HAND_DISPLAY(hand);
	cairo_text_extents_t extents;
	cairo_font_extents_t fextents;
	GtkAllocation allocation;
	gtk_widget_get_allocation (hand, &allocation);

	cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);

	/* "card" mode for drap&drop icon */
	if (handdisp->mode == HAND_DISPLAY_MODE_CARD) {
		if (handdisp->style == HAND_DISPLAY_STYLE_CARDS) {
			if (card_width != handdisp->want_width) { /* adjust window */
				handdisp->want_width = card_width;
				gdk_window_resize (gtk_widget_get_parent_window (hand),
						card_width, card_height);

				/* shaped drag icon
				 * credits to Mirco "MacSlow" Mueller <*****@*****.**>
				 * http://macslow.thepimp.net/?p=26 */
				GdkBitmap *pShapeBitmap = (GdkBitmap*) gdk_pixmap_new (NULL, card_width, card_height, 1);
				assert (pShapeBitmap);
				cairo_t *pCairoContext = gdk_cairo_create (pShapeBitmap);
				assert (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS);
				render_card (pCairoContext, 0, 0, handdisp->table_card[0], HAND_DISPLAY_CARD);
				cairo_destroy (pCairoContext);
				gdk_window_shape_combine_mask (gtk_widget_get_parent_window (hand), pShapeBitmap, 0, 0);
				g_object_unref ((gpointer) pShapeBitmap);
			}
			render_card (cr, 0, 0, handdisp->table_card[0], HAND_DISPLAY_CARD);
			return;
		}

		char cs[6];
		int c = handdisp->table_card[0];
		int suit = c / 13;
		int rank = c % 13;

		snprintf (cs, 6, "%s%s", suit_str[suit], rank_str[rank]);
		cairo_set_font_size (cr, 20);
		cairo_text_extents (cr, cs, &extents);
#define XPAD 4
#define YPAD 2
		int w = extents.width + 2 * XPAD + 5;
		int h = extents.height + 2 * YPAD;

		cairo_set_source_rgb (cr, HAND_DISPLAY_FOCUS_BG);
		cairo_rectangle (cr, 1, 1, w, h);
		cairo_fill (cr);
		cairo_set_source_rgb (cr, HAND_DISPLAY_FONT);
		cairo_rectangle (cr, 1, 1, w, h);
		cairo_stroke (cr);

		cairo_move_to (cr, XPAD - extents.x_bearing + 1, YPAD - extents.y_bearing + 2);
		cairo_set_source_rgb (cr, suit_color[suit][0],
			suit_color[suit][1], suit_color[suit][2]);
		cairo_show_text (cr, suit_str[suit]);
		cairo_set_source_rgb (cr, HAND_DISPLAY_FONT);
		cairo_show_text (cr, rank_str[rank]);

		if (w + 2 != handdisp->want_width) { /* adjust window */
			handdisp->want_width = w + 2;
			gdk_window_resize (gtk_widget_get_parent_window (hand), w + 2, h + 2);
		}

		return;
	}

	cairo_set_source_rgb (cr, HAND_DISPLAY_TABLE_BG);
	cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
	cairo_fill (cr);

	/* "table" mode for displaying the already played cards in the middle of the screen */

	if (handdisp->mode == HAND_DISPLAY_MODE_TABLE &&
	    handdisp->style == HAND_DISPLAY_STYLE_CARDS) {
		int i;
		for (i = 0; i < 4; i++) {
			switch (handdisp->table_seat[i]) {
				case 1: x = allocation.width / 2 - card_width + 5;
				/*W*/	y = (allocation.height - card_height) / 2 + 5;
					break;
				case 2: x = (allocation.width - card_width) / 2 - 2;
				/*N*/	y = MAX (allocation.height / 2 - card_height + 10, 0);
					break;
				case 3: x = allocation.width / 2 - 5;
				/*E*/	y = (allocation.height - card_height) / 2 - 5;
					break;
				case 4: x = (allocation.width - card_width) / 2 + 2;
				/*S*/	y = MIN (allocation.height / 2 - 10, allocation.height - card_height);
					break;
				default:
					return; /* stop here */
			}

			render_card (cr, x, y, handdisp->table_card[i], HAND_DISPLAY_CARD);

		}
		return;
	}

	if (handdisp->mode == HAND_DISPLAY_MODE_TABLE) { /* text */
		cairo_set_font_size (cr, 20);

		int i;
		for (i = 0; i < 4; i++) {
			char cs[6];
			if (!handdisp->table_seat[i])
				return;
			int c = handdisp->table_card[i];
			int suit = c / 13;
			int rank = c % 13;
			snprintf (cs, 6, "%s%s", suit_str[suit], rank_str[rank]);
			cairo_text_extents (cr, cs, &extents);

#define XOFF 38
#define YOFF 23
#define WIDTH 52
#define HEIGHT 28
#define RAD 5
			switch (handdisp->table_seat[i]) { /* middle point */
				case 1: x = allocation.width / 2 - XOFF;
				/*W*/	y = allocation.height / 2;
					break;
				case 2: x = allocation.width / 2;
				/*N*/	y = allocation.height / 2 - YOFF;
					break;
				case 3: x = allocation.width / 2 + XOFF;
				/*E*/	y = allocation.height / 2;
					break;
				case 4: x = allocation.width / 2;
				/*S*/	y = allocation.height / 2 + YOFF;
					break;
				default:
					return; /* stop here */
			}

			cairo_new_path (cr);
			cairo_arc_negative (cr, x-WIDTH/2+RAD, y+HEIGHT/2 - RAD, RAD, M_PI, M_PI_2);
			cairo_arc_negative (cr, x+WIDTH/2-RAD, y+HEIGHT/2 - RAD, RAD, M_PI_2, 0.0);
			cairo_arc_negative (cr, x+WIDTH/2-RAD, y-HEIGHT/2 + RAD, RAD, 0.0, -M_PI_2);
			cairo_arc_negative (cr, x-WIDTH/2+RAD, y-HEIGHT/2 + RAD, RAD, -M_PI_2, M_PI);
			cairo_close_path (cr);
			cairo_set_source_rgb (cr, HAND_DISPLAY_FOCUS_BG);
			cairo_fill_preserve (cr);
			cairo_set_source_rgb (cr, HAND_DISPLAY_FONT);
			cairo_stroke (cr);

			cairo_move_to (cr, x - extents.width / 2 - 3,
					y + extents.height / 2 - 3);
			cairo_set_source_rgb (cr, suit_color[suit][0],
				suit_color[suit][1], suit_color[suit][2]);
			cairo_show_text (cr, suit_str[suit]);
			cairo_set_source_rgb (cr, HAND_DISPLAY_FONT);
			cairo_show_text (cr, rank_str[rank]);
		}
		return;
	}

	/* normal hands display */

	/* compute cached best card score for this hand */
	if (handdisp->best_card_score == HAND_DISPLAY_NO_SCORE) {
		int c;
		handdisp->best_card_score = handdisp->card_score_neg ? 14 : -14;
		for (c = 0; c < 52; c++) {
			if (handdisp->card_score_neg ?
				(handdisp->card_score[c] < handdisp->best_card_score) :
				(handdisp->card_score[c] > handdisp->best_card_score))
					handdisp->best_card_score = handdisp->card_score[c];
		}
	}

	/* "cards" style */

	if (handdisp->style == HAND_DISPLAY_STYLE_CARDS && handdisp->mode != HAND_DISPLAY_MODE_HAND_X) {
		/* we do not support MODE_X here, yet we still allow setting
		 * STYLE_CARDS there to have the right drag icon */
		y = MAX (allocation.height - card_height - 5, 15);
		int n = 0;
		int suit;
		for (suit = 0; suit < 4; suit++) {
			int c;
			for (c = 13 * (handdisp->suits[suit] + 1) - 1; c >= 13 * handdisp->suits[suit]; c--) {
				if (handdisp->cards[c]) {
					x = floor (n++ * (allocation.width - card_width) / 12.0);

					int sc = handdisp->card_score[c];
					int yy = c == handdisp->cur_focus ? y - 15 :
						(sc != HAND_DISPLAY_NO_SCORE &&
						 handdisp->best_card_score == sc ? y - 5 : y);
					yy = MAX (yy, 0);
					handdisp->l[c] = x;
					handdisp->r[c] = x + card_width;
					handdisp->t[c] = y - 15;
					handdisp->b[c] = y + card_height;

					if (handdisp->cards[c] & HAND_DISPLAY_INVISIBLE_CARD)
						continue;

					render_card (cr, x, yy, c, handdisp->cards[c]);

					if (handdisp->cards[c] == HAND_DISPLAY_HILIGHT_CARD) { /* draw triangular arrow */
						cairo_set_source_rgb (cr, HAND_DISPLAY_HILIGHT_FONT);
						cairo_move_to (cr, x + 3 + (allocation.width - card_width - 10) / 24.0, yy);
						cairo_rel_line_to (cr, -5, -5);
						cairo_rel_line_to (cr, 10, 0);
						cairo_fill (cr);
					}

					/* show card score */
					if (handdisp->card_score[c] == HAND_DISPLAY_NO_SCORE)
						continue;
					char *buf = overtricks (handdisp->card_score[c]);
					static int text_h = 0;
					if (!text_h) {
						cairo_font_extents (cr, &fextents);
						text_h = fextents.ascent;
					}
					cairo_text_extents (cr, buf, &extents);
					cairo_move_to (cr, x + 1 + text_h,
							yy + 30 + extents.width);
					cairo_set_source_rgb (cr, HAND_DISPLAY_DD_FONT);
					cairo_save (cr);
					cairo_rotate (cr, -G_PI_2);
					cairo_show_text (cr, buf);
					cairo_restore (cr);
				}
			}
		}

		return;
	}

	/* "text" style */

	/* draw suit symbols */
	cairo_set_font_size (cr, 20);
	int suit_width = 0;
	int suit;
	for (suit = 0; suit < 4; suit++) {
		x = 0;
		y = floor ((double) allocation.height * (3.8 - suit) / 4.0);
		cairo_move_to (cr, x, y);
		cairo_text_extents (cr, suit_str[suit], &extents);
		if (extents.x_advance > suit_width)
			suit_width = extents.x_advance;
		cairo_set_source_rgb (cr, suit_color[suit][0], suit_color[suit][1], suit_color[suit][2]);
		cairo_show_text (cr, suit_str[suit]);
	}

	/* draw cards */
	for (suit = 0; suit < 4; suit++) {
		x = 4 + suit_width;
		y = floor ((double) allocation.height * (3.8 - suit) / 4.0);
		cairo_move_to (cr, x, y);

		int c;
		for (c = 13 * suit + 12; c >= 13 * suit; c--) {
			if (handdisp->cards[c]) {
				cairo_text_extents (cr, rank_str[c % 13], &extents);
				handdisp->l[c] = x + extents.x_bearing;
				handdisp->r[c] = x + extents.x_bearing + extents.width;
				handdisp->t[c] = y + extents.y_bearing;
				handdisp->b[c] = y + extents.y_bearing + extents.height;
				if (!(handdisp->cards[c] & HAND_DISPLAY_INVISIBLE_CARD)) {
					if (c == handdisp->cur_focus) {
						cairo_set_source_rgb (cr, HAND_DISPLAY_FOCUS_BG);
						cairo_rectangle (cr, handdisp->l[c] - 1, handdisp->t[c] - 1,
							extents.width + 2, extents.height + 2);
						cairo_fill (cr);
					}
					if (handdisp->card_score[c] == HAND_DISPLAY_NO_SCORE) {
						if (handdisp->cards[c] == HAND_DISPLAY_CARD)
							cairo_set_source_rgb (cr, HAND_DISPLAY_FONT);
						else if (handdisp->cards[c] == HAND_DISPLAY_GREY_CARD)
							cairo_set_source_rgb (cr, HAND_DISPLAY_GREY_FONT);
						else if (handdisp->cards[c] == HAND_DISPLAY_OLD_CARD)
							cairo_set_source_rgb (cr, HAND_DISPLAY_OLD_FONT);
						else if (handdisp->cards[c] == HAND_DISPLAY_HILIGHT_CARD)
							cairo_set_source_rgb (cr, HAND_DISPLAY_HILIGHT_FONT);
					} else {
						/* invert colors if the score is for the opps */
						if (handdisp->card_score_neg ^ (handdisp->card_score[c] >= 0))
							if (handdisp->best_card_score == handdisp->card_score[c])
								cairo_set_source_rgb (cr, HAND_DISPLAY_BEST_POS_FONT);
							else
								cairo_set_source_rgb (cr, HAND_DISPLAY_POS_FONT);
						else
							if (handdisp->best_card_score == handdisp->card_score[c])
								cairo_set_source_rgb (cr, HAND_DISPLAY_BEST_NEG_FONT);
							else
								cairo_set_source_rgb (cr, HAND_DISPLAY_NEG_FONT);
					}
					cairo_move_to (cr, x, y);
					cairo_show_text (cr, rank_str[c % 13]);
				}
				x += extents.x_advance; y += extents.y_advance;
			} else {
				handdisp->l[c] = handdisp->r[c] = handdisp->t[c] = handdisp->b[c] = 0;
			}
		}

		/* MODE_X */
		if (handdisp->mode == HAND_DISPLAY_MODE_HAND_X) {
			c = 52 + suit;
			x += 3;
			cairo_text_extents (cr, "x", &extents);
			handdisp->l[c] = x + extents.x_bearing;
			handdisp->r[c] = x + extents.x_bearing + extents.width;
			handdisp->t[c] = y + extents.y_bearing;
			handdisp->b[c] = y + extents.y_bearing + extents.height;
			if (c == handdisp->cur_focus) {
				cairo_set_source_rgb (cr, HAND_DISPLAY_FOCUS_BG);
				cairo_rectangle (cr, handdisp->l[c] - 1, handdisp->t[c] - 1,
					extents.width + 2, extents.height + 2);
				cairo_fill (cr);
			}
			cairo_set_source_rgb (cr, HAND_DISPLAY_FONT);
			cairo_move_to (cr, x, y);
			cairo_show_text (cr, "x");
			x += extents.x_advance + 4;
		}

		if (x > handdisp->want_width) { /* grow window */
			handdisp->want_width = x;
			gtk_widget_queue_resize (hand);
		}
	}

	/* show card scores */
	cairo_set_font_size (cr, 10);
	int c;
	for (c = 51; c >= 0; c--) {
		char *buf;
		if (handdisp->card_score[c] != HAND_DISPLAY_NO_SCORE) {
			buf = overtricks (handdisp->card_score[c]);
			cairo_text_extents (cr, buf, &extents);
			cairo_move_to (cr, handdisp->r[c] - extents.x_advance, handdisp->b[c]);
			cairo_set_source_rgb (cr, HAND_DISPLAY_DD_FONT);
			cairo_show_text (cr, buf);
		}
	}
}
Exemple #18
0
    virtual bool DoSetShape(GdkWindow* window)
    {
        gdk_window_shape_combine_mask(window, NULL, 0, 0);

        return true;
    }
static void
unset_transparent_shape (GdkWindow *window)
{
  gdk_window_shape_combine_mask (data->window, NULL, 0, 0);
}
Exemple #20
0
Error GTKWindow::Run(Pos &oPos)
{
    Rect oRect;
    int iMaxX, iMaxY;

    m_oWindowPos = oPos;
    m_pCanvas->Init();

    GetCanvas()->GetBackgroundRect(oRect);

    gdk_threads_enter();

    GtkItemFactoryEntry popup_items[] = {
     {"/MyMusic ",     NULL,      (GtkItemFactoryCallback)mymusic_pop,  0, 0 },
     {"/Open",         NULL,      (GtkItemFactoryCallback)open_pop,     0, 0 },
     {"/sep1",         NULL,      0,                        0, "<Separator>" },
     {"/Edit Info",    NULL,      (GtkItemFactoryCallback)edit_pop,     0, 0 },
     {"/Suggest Playlist", NULL,  (GtkItemFactoryCallback)suggest_pop,  0, 0 },
     {"/Lookup at Bitzi", NULL,   (GtkItemFactoryCallback)bitzi_pop,       0, 0},
     {"/sep2",         NULL,      0,                        0, "<Separator>" },
     {"/Exit",         NULL,      (GtkItemFactoryCallback)exit_pop,      0, 0 },
    };

    int nmenu_items = sizeof(popup_items) / sizeof(popup_items[0]);

    contextPopup = gtk_item_factory_new(GTK_TYPE_MENU, "<context_popup>",
                                         NULL);
    gtk_item_factory_create_items(contextPopup, nmenu_items, popup_items,
                                  (void *)this);

    gtk_signal_connect(GTK_OBJECT(mainWindow), "motion_notify_event",
                       GTK_SIGNAL_FUNC(mouse_move), this);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "button_press_event",
                       GTK_SIGNAL_FUNC(button_down), this);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "button_release_event",
                       GTK_SIGNAL_FUNC(button_up), this);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "key_press_event",
                       GTK_SIGNAL_FUNC(key_press), this);
    gtk_drag_dest_set(mainWindow, GTK_DEST_DEFAULT_ALL, main_drop, 2,
                      GDK_ACTION_COPY);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "drag_data_received",
                       GTK_SIGNAL_FUNC(drop_file), this);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "enter_notify_event",
                       GTK_SIGNAL_FUNC(enter_notify), this);
    gtk_signal_connect(GTK_OBJECT(mainWindow), "leave_notify_event",
                       GTK_SIGNAL_FUNC(leave_notify), this);

    iMaxX = gdk_screen_width();
    iMaxY = gdk_screen_height();
 
    if (m_oWindowPos.x > iMaxX || m_oWindowPos.x + oRect.Width() < 0)
       m_oWindowPos.x = 0;
    if (m_oWindowPos.y > iMaxY || m_oWindowPos.y + oRect.Height() < 0)
       m_oWindowPos.y = 0;

    if (m_oWindowPos.x == -1 && m_oWindowPos.y == -1) {
        m_oWindowPos.x = (iMaxX - oRect.Width()) / 2;
        m_oWindowPos.y = (iMaxY - oRect.Height()) / 2;
    }

    gtk_widget_set_uposition(mainWindow, m_oWindowPos.x, m_oWindowPos.y);
    gtk_widget_set_usize(mainWindow, oRect.Width(), oRect.Height());
    gdk_threads_leave();

    Init();
    GdkBitmap *mask = ((GTKCanvas *)m_pCanvas)->GetMask();

    gdk_threads_enter();
    if (mask)
        gdk_window_shape_combine_mask(mainWindow->window, mask, 0, 0);
    gdk_threads_leave();

    ((GTKCanvas *)GetCanvas())->Paint(oRect);

    gdk_threads_enter();
    gtk_widget_show(mainWindow);
    gdk_flush(); 
    gtkTimer = gtk_timeout_add(250, do_timeout, this);
    gdk_threads_leave();
 
    initialized = true;

    quitLoop = false;
    while (!quitLoop) 
       sleep(1);

    oPos = m_oWindowPos;

    return kError_NoErr;
}