Example #1
0
static void
maybe_update_shape (GtkTooltip *tooltip)
{
  cairo_t *cr;
  cairo_surface_t *surface;
  cairo_region_t *region;

  /* fallback to XShape only for non-composited clients */
  if (gtk_widget_is_composited (tooltip->window))
    {
      gtk_widget_shape_combine_region (tooltip->window, NULL);
      return;
    }

  surface = gdk_window_create_similar_surface (gtk_widget_get_window (tooltip->window),
                                               CAIRO_CONTENT_COLOR_ALPHA,
                                               gtk_widget_get_allocated_width (tooltip->window),
                                               gtk_widget_get_allocated_height (tooltip->window));

  cr = cairo_create (surface);
  paint_background_and_frame (tooltip, cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  gtk_widget_shape_combine_region (tooltip->window, region);

  cairo_surface_destroy (surface);
  cairo_region_destroy (region);
}
Example #2
0
static gboolean
draw_cb (GtkWidget *widget,
         cairo_t   *cr)
{
  gint width, height;

  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  cairo_rectangle (cr, 0, 0, width, height);
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_fill (cr);

  draw_horizontal_scrollbar (widget, cr, 10, 10, width - 20, 10, 30, GTK_STATE_FLAG_NORMAL);
  draw_horizontal_scrollbar (widget, cr, 10, 30, width - 20, 10, 40, GTK_STATE_FLAG_PRELIGHT);
  draw_horizontal_scrollbar (widget, cr, 10, 50, width - 20, 10, 50, GTK_STATE_FLAG_ACTIVE|GTK_STATE_FLAG_PRELIGHT);

  draw_text (widget, cr, 10,  70, width - 20, 20, "Not selected", GTK_STATE_FLAG_NORMAL);
  draw_text (widget, cr, 10, 100, width - 20, 20, "Selected", GTK_STATE_FLAG_SELECTED);

  draw_check (widget, cr,  10, 130, GTK_STATE_FLAG_NORMAL);
  draw_check (widget, cr,  40, 130, GTK_STATE_FLAG_CHECKED);
  draw_radio (widget, cr,  70, 130, GTK_STATE_FLAG_NORMAL);
  draw_radio (widget, cr, 100, 130, GTK_STATE_FLAG_CHECKED);

  return FALSE;
}
Example #3
0
void qp_graph_grid_draw(struct qp_graph *gr, struct qp_plot *p,
    cairo_t *cr, int width, int height)
{
  int64_t
        xmin_mat, xmax_mat, xinc,
	ymin_mat, ymax_mat, yinc;
  double xpow_part, ypow_part;
  PangoLayout *pangolayout = NULL;
  int view_width, view_height;
  
  ASSERT(gr);
  ASSERT(p);
  ASSERT(gr->drawing_area);
  ASSERT(gr->qp);
  ASSERT(gr->qp->window);

  if(!gr->show_grid) return;

  PreDrawGrid(gr, p,
	  &xmin_mat, &xmax_mat, &xinc, &xpow_part,
	  &ymin_mat, &ymax_mat, &yinc, &ypow_part,
          width, height);

  view_width = gtk_widget_get_allocated_width(gr->drawing_area);
  view_height = gtk_widget_get_allocated_height(gr->drawing_area);


  if(gr->grid_numbers)
    pangolayout = get_pangolayout(gr, cr);



#if 0
  DEBUG("\nxmin=%g xmax=%g\n",
      qp_plot_get_xval(p, 0), qp_plot_get_xval(p, width));
  APPEND("ymin=%g ymax=%g\n",
      qp_plot_get_yval(p, height), qp_plot_get_yval(p, 0));
  APPEND("xmin_mat=%ld xmax_mat=%ld xinc=%ld xpow_part=%g \n",
      xmin_mat, xmax_mat, xinc, xpow_part);
  APPEND("ymin_mat=%ld ymax_mat=%ld yinc=%ld ypow_part=%g \n",
      ymin_mat, ymax_mat, yinc, ypow_part);
  APPEND("delta_x pixels between lines=%d\n",
      qp_plot_get_xpixel(p, xpow_part*(xmin_mat + xinc)) -
      qp_plot_get_xpixel(p, xpow_part*(xmin_mat)));
  APPEND("delta_y pixels between lines=%d\n",
      qp_plot_get_ypixel(p, ypow_part*ymin_mat) -
      qp_plot_get_ypixel(p, ypow_part*(ymin_mat + yinc)));
#endif

  if(gr->same_x_scale)
      DrawXGrid(cr, pangolayout, gr, p,
	    xmin_mat, xmax_mat, xinc, xpow_part,
	    ymin_mat, ymax_mat, yinc, ypow_part,
            width, height, view_height);
  if(gr->same_y_scale)
      DrawYGrid(cr, pangolayout, gr, p,
	    xmin_mat, xmax_mat, xinc, xpow_part,
	    ymin_mat, ymax_mat, yinc, ypow_part,
            width, height, view_width);
}
static gboolean
set_paned_position (GtkWidget *paned)
{
	gtk_paned_set_position (GTK_PANED (paned), gtk_widget_get_allocated_height (paned) / 2);
	g_object_unref (paned);
	return FALSE;
}
static void
my_intensity_box_realize (GtkWidget * widget)
{

    MyIntensityBox *self = MY_INTENSITY_BOX (widget);
    MyIntensityBoxPrivate *priv;

    priv = my_intensity_box_get_instance_private (self);

    GTK_WIDGET_CLASS(my_intensity_box_parent_class)->realize(widget);

    gint width, height;

    GtkWidget *label = gtk_label_new ("test");
    GdkRectangle rect;

    width = gtk_widget_get_allocated_width (widget);
    height = gtk_widget_get_allocated_height (widget);

    rect.x = 0;
    rect.y = height - (priv->y / (priv->y_max - priv->y_min)) * height;
    rect.height = 0;
    rect.width = width;

    /*priv->popover = gtk_popover_new (GTK_WIDGET (self));*/
    /*gtk_popover_set_modal (GTK_POPOVER (priv->popover), FALSE);*/
    /*gtk_popover_set_pointing_to (GTK_POPOVER (priv->popover), &rect);*/
    /*gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_TOP);*/
    /*gtk_container_add (GTK_CONTAINER (priv->popover), label);*/
    /*gtk_container_set_border_width (GTK_CONTAINER (priv->popover), 6);*/
    /*gtk_widget_show (label);*/
    /*gtk_widget_set_visible (GTK_WIDGET (priv->popover), TRUE);*/
}
static void
maybe_update_shape (GtkWidget *widget)
{
	cairo_t *cr;
	cairo_surface_t *surface;
	cairo_region_t *region;

	/* fallback to XShape only for non-composited clients */
	if (gtk_widget_is_composited (widget)) {
		gtk_widget_shape_combine_region (widget, NULL);
		return;
	}

	surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
						     CAIRO_CONTENT_COLOR_ALPHA,
						     gtk_widget_get_allocated_width (widget),
						     gtk_widget_get_allocated_height (widget));

	cr = cairo_create (surface);
	label_draw_background_and_frame (widget, cr, TRUE);
	cairo_destroy (cr);

	region = gdk_cairo_region_create_from_surface (surface);
	gtk_widget_shape_combine_region (widget, region);

	cairo_surface_destroy (surface);
	cairo_region_destroy (region);
}
static gboolean
handle_draw_cb (GtkWidget * widget, cairo_t * cr, gpointer user_data)
{
  GstVideoRectangle *r = &anim_state.rect;
  GtkStyle *style;
  int width, height;

  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  style = gtk_widget_get_style (widget);

  gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);

  /* we should only redraw outside of the video rect! */
  cairo_rectangle (cr, 0, 0, r->x, height);
  cairo_rectangle (cr, r->x + r->w, 0, width - (r->x + r->w), height);

  cairo_rectangle (cr, 0, 0, width, r->y);
  cairo_rectangle (cr, 0, r->y + r->h, width, height - (r->y + r->h));

  cairo_fill (cr);

  if (verbose) {
    g_print ("draw(%p)\n", widget);
  }
  gst_x_overlay_expose (anim_state.overlay);
  return FALSE;
}
Example #8
0
static gboolean
gtk_files_draw (GtkWidget *files, cairo_t *cr)
{
	cairo_text_extents_t extents;
	gint width = gtk_widget_get_allocated_width (files);
	gint height = gtk_widget_get_allocated_height (files);
	cairo_set_font_size (cr, 20);

	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_rectangle(cr, 0, 0, width, height);
	cairo_fill (cr);

	cairo_set_source_rgb (cr, .8, .4, .4);
	cairo_rectangle (cr, 0, 0, width, 50);
	cairo_fill (cr);

	cairo_set_source_rgb (cr, .8, .6, .8);
	cairo_rectangle (cr, 0, 60, width, 25);
	cairo_fill (cr);

	cairo_set_source_rgb (cr, .6, .6, .8);
	cairo_rectangle (cr, 0, 95, width,
			height - 25 - ((215 + 25) * (NUM_PANES - 1)));
	cairo_rectangle (cr, 0, height - 100, width, 100);
	cairo_fill (cr);

	// black indent
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_rectangle(cr, 0, 25, 25, height - 50);
	cairo_arc (cr, 0, 25, 25, 0, 2 * M_PI); // TODO
	cairo_arc (cr, 0, height - 25, 25, 0, 2 * M_PI); // TODO
	cairo_fill (cr);

	return TRUE;
}
Example #9
0
static gboolean
get_child_position (GtkOverlay    *overlay,
                    GtkWidget     *widget,
                    GtkAllocation *alloc,
                    GtkWidget     *relative)
{
  GtkRequisition req;
  GtkWidget *child;
  GtkAllocation main_alloc;
  gint x, y;

  child = gtk_bin_get_child (GTK_BIN (overlay));

  gtk_widget_translate_coordinates (relative, child, 0, 0, &x, &y);
  main_alloc.x = x;
  main_alloc.y = y;
  main_alloc.width = gtk_widget_get_allocated_width (relative);
  main_alloc.height = gtk_widget_get_allocated_height (relative);

  gtk_widget_get_preferred_size (widget, NULL, &req);

  alloc->x = main_alloc.x;
  alloc->width = MIN (main_alloc.width, req.width);
  if (gtk_widget_get_halign (widget) == GTK_ALIGN_END)
    alloc->x += main_alloc.width - req.width;

  alloc->y = main_alloc.y;
  alloc->height = MIN (main_alloc.height, req.height);
  if (gtk_widget_get_valign (widget) == GTK_ALIGN_END)
    alloc->y += main_alloc.height - req.height;

  return TRUE;
}
Example #10
0
static gboolean
render_cb(GtkGLArea* area,
          GdkGLContext* ctxt,
          gpointer udata)
{
    GtPlayerMpv* self = GT_PLAYER_MPV(udata);
    GtPlayerMpvPrivate* priv = gt_player_mpv_get_instance_private(self);

    int width;
    int height;
    int fbo;

    if (!priv->opengl_ready)
    {
        check_mpv_error(mpv_opengl_cb_init_gl(priv->mpv_opengl, NULL,
                                              get_proc_address, NULL));
        priv->opengl_ready = TRUE;
    }

    width = gtk_widget_get_allocated_height(priv->opengl_area);
    height = (-1)*gtk_widget_get_allocated_width(priv->opengl_area);
    fbo = -1;

    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
    mpv_opengl_cb_draw(priv->mpv_opengl, fbo, width, height);

    return TRUE;
}
Example #11
0
static gboolean window_menu_on_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data)
#endif
{
	WindowMenu* window_menu = data;

	if (gtk_widget_has_focus(window_menu->applet))
		gtk_paint_focus(gtk_widget_get_style(widget),
#if GTK_CHECK_VERSION (3, 0, 0)
						cr,
#else
						gtk_widget_get_window(widget),
#endif
						gtk_widget_get_state(widget),
#if !GTK_CHECK_VERSION (3, 0, 0)
						NULL,
#endif
						widget,
						"menu-applet",
						0, 0,
#if GTK_CHECK_VERSION (3, 0, 0)
						gtk_widget_get_allocated_width (widget),
						gtk_widget_get_allocated_height (widget));
#else
						-1, -1);
#endif

	return FALSE;
}
Example #12
0
/**************************************************************************
  Put the popup on a smart position, after the real size of the widget is
  known: left of the cursor if within the right half of the map, and vice
  versa; displace the popup so as not to obscure it by the mouse cursor;
  stay always within the map if possible. 
**************************************************************************/
static void popupinfo_positioning_callback(GtkWidget *w, GtkAllocation *alloc, 
					   gpointer data)
{
  struct tmousepos *mousepos = data;
  gint x, y;
  struct tile *ptile;

  ptile = canvas_pos_to_tile(mousepos->x, mousepos->y);
  if (tile_to_canvas_pos(&x, &y, ptile)) {
    gint minx, miny, maxy;

    gdk_window_get_origin(gtk_widget_get_window(map_canvas), &minx, &miny);
    maxy = miny + gtk_widget_get_allocated_height(map_canvas);

    if (x > mapview.width/2) {
      /* right part of the map */
      x += minx;
      y += miny + (tileset_tile_height(tileset) - alloc->height)/2;

      y = CLIP(miny, y, maxy - alloc->height);

      gtk_window_move(GTK_WINDOW(w), x - alloc->width, y);
    } else {
      /* left part of the map */
      x += minx + tileset_tile_width(tileset);
      y += miny + (tileset_tile_height(tileset) - alloc->height)/2;

      y = CLIP(miny, y, maxy - alloc->height);

      gtk_window_move(GTK_WINDOW(w), x, y);
    }
  }
}
Example #13
0
static gboolean vid_area_render_handler(	GtkGLArea *area,
						GdkGLContext *context,
						gpointer data )
{
	gmpv_handle *ctx = data;
	int width;
	int height;
	int fbo;

	if(!ctx->opengl_ready)
	{
		mpv_check_error(mpv_opengl_cb_init_gl(	ctx->opengl_ctx,
							NULL,
							get_proc_address,
							NULL ));

		ctx->opengl_ready = TRUE;
	}

	width = gtk_widget_get_allocated_width(GTK_WIDGET(area));
	height = (-1)*gtk_widget_get_allocated_height(GTK_WIDGET(area));
	fbo = -1;

	glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
	mpv_opengl_cb_draw(ctx->opengl_ctx, fbo, width, height);

	return TRUE;
}
Example #14
0
static gboolean
get_child_position (GtkOverlay     *overlay,
                    GtkWidget      *widget,
                    GtkAllocation  *allocation,
                    GtkColorEditor *editor)
{
  GtkRequisition req;
  GtkAllocation alloc;
  gint s, e;

  gtk_widget_get_preferred_size (widget, &req, NULL);

  allocation->x = 0;
  allocation->y = 0;
  allocation->width = req.width;
  allocation->height = req.height;

  if (widget == editor->priv->sv_popup)
    {
      if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
        allocation->x = 0;
      else
        allocation->x = gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width;
      allocation->y = req.height / 3;
    }
  else if (widget == editor->priv->h_popup)
    {
      gtk_widget_get_allocation (editor->priv->h_slider, &alloc);
      gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e);

      if (gtk_widget_get_direction (GTK_WIDGET (overlay)) == GTK_TEXT_DIR_RTL)
        gtk_widget_translate_coordinates (editor->priv->h_slider,
                                          gtk_widget_get_parent (editor->priv->grid),
                                          - req.width, (s + e - req.height) / 2,
                                          &allocation->x, &allocation->y);
      else
        gtk_widget_translate_coordinates (editor->priv->h_slider,
                                          gtk_widget_get_parent (editor->priv->grid),
                                          alloc.width, (s + e - req.height) / 2,
                                          &allocation->x, &allocation->y);
    }
  else if (widget == editor->priv->a_popup)
    {
      gtk_widget_get_allocation (editor->priv->a_slider, &alloc);
      gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e);

      gtk_widget_translate_coordinates (editor->priv->a_slider,
                                        gtk_widget_get_parent (editor->priv->grid),
                                        (s + e - req.width) / 2, - req.height,
                                        &allocation->x, &allocation->y);
    }
  else
    return FALSE;

  allocation->x = CLAMP (allocation->x, 0, gtk_widget_get_allocated_width (GTK_WIDGET (overlay)) - req.width);
  allocation->y = CLAMP (allocation->y, 0, gtk_widget_get_allocated_height (GTK_WIDGET (overlay)) - req.height);

  return TRUE;
}
Example #15
0
static void compute_viewport(window_state_t *state, viewport_t *v) {
    stream_t *stream = state->stream;
    double min;
    double max;
    double unit;

    compute_scale_factor(state, &v->sx, &v->sy);

    v->w = gtk_widget_get_allocated_width(state->drawing_area);
    v->h = gtk_widget_get_allocated_height(state->drawing_area);

    v->uox = 0.0f;
    v->uoy = 0.0f;
    v->udx = v->w;
    v->udy = v->h;
    v->uw = v->w;
    v->uh = v->h;
    v->updx = 1.0f;
    v->updy = 1.0f;

    // Find equivalent for the origin and window size in user coordinates
    cairo_matrix_transform_point(&state->window_to_user_inv, &v->uox, &v->uoy);
    cairo_matrix_transform_point(&state->window_to_user_inv, &v->udx, &v->udy);
    cairo_matrix_transform_distance(&state->window_to_user_inv, &v->uw, &v->uh);
    cairo_matrix_transform_distance(&state->window_to_user_inv, &v->updx, &v->updy);

    v->sox = v->uox;
    v->soy = v->uoy;
    v->sdx = v->udx;
    v->sdy = v->udy;
    v->sw = v->uw;
    v->sh = v->uh;
    v->spdx = v->updx;
    v->spdy = v->updy;

    // Find equivalent for the origin and window size in scaled coordinates
    cairo_matrix_transform_point(&state->user_to_scaled_inv, &v->sox, &v->soy);
    cairo_matrix_transform_point(&state->user_to_scaled_inv, &v->sdx, &v->sdy);
    cairo_matrix_transform_distance(&state->user_to_scaled_inv, &v->sw, &v->sh);
    cairo_matrix_transform_distance(&state->user_to_scaled_inv, &v->spdx, &v->spdy);

    if (v->soy < v->sdy) {
        min = v->soy;
        max = v->sdy;
    } else {
        min = v->sdy;
        max = v->soy;
    }

    // Determine offsets of first wedge in view and first wedge out of view
    unit = state->wedge_height * stream->sample_rate / powf(2.0f, v->sy);
    v->start = floor((min * stream->sample_rate) / unit) * unit;
    v->end = (floor((max * stream->sample_rate) / unit) + 1.0f) * unit;
    v->skip = unit;

    // Offsets of stream
    v->stream_start = 0;
    v->stream_end = stream->n_samples;
}
/**
 * gs_screenshot_image_draw:
 **/
static gboolean
gs_screenshot_image_draw (GtkWidget *widget, cairo_t *cr)
{
	GtkStyleContext *context;

	context = gtk_widget_get_style_context (widget);
	gtk_render_background (context, cr,
			       0, 0,
			       gtk_widget_get_allocated_width (widget),
			       gtk_widget_get_allocated_height (widget));
	gtk_render_frame (context, cr,
			  0, 0,
			  gtk_widget_get_allocated_width (widget),
			  gtk_widget_get_allocated_height (widget));

	return GTK_WIDGET_CLASS (gs_screenshot_image_parent_class)->draw (widget, cr);
}
Example #17
0
G_MODULE_EXPORT
gboolean chart_da_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer unused)
{	
	chart_draw (cr, gtk_widget_get_allocated_width (widget),
		gtk_widget_get_allocated_height (widget));
			
	return TRUE;
}
Example #18
0
static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data)
{
#ifdef HAVE_OPENGL
    CvWindow* window = (CvWindow*)data;

    if (window->useGl)
    {
        drawGl(window);
        return TRUE;
    }
#else
    (void)data;
#endif

  CvImageWidget *image_widget = NULL;
  GdkPixbuf *pixbuf = NULL;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE);

  image_widget = CV_IMAGE_WIDGET (widget);

  if( image_widget->scaled_image ){
      // center image in available region
      int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2;
      int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2;

      pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false,
          8, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(widget)),
          MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(widget)),
          image_widget->scaled_image->step, NULL, NULL);

      gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0);
  }
  else if( image_widget->original_image ){
      pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false,
          8, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(widget)),
          MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(widget)),
          image_widget->original_image->step, NULL, NULL);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
  }

  cairo_paint(cr);
  g_object_unref(pixbuf);
  return TRUE;
}
Example #19
0
static gboolean
drawing_area_draw (GtkWidget *widget,
                   cairo_t *cr)
{
  GtkStyleContext *context = gtk_widget_get_style_context (widget);

  gtk_render_background (context, cr,
                         0, 0,
                         gtk_widget_get_allocated_width (widget),
                         gtk_widget_get_allocated_height (widget));
  gtk_render_frame (context, cr,
                    0, 0,
                    gtk_widget_get_allocated_width (widget),
                    gtk_widget_get_allocated_height (widget));

  return FALSE;
}
Example #20
0
    static void
gtk_form_render_background(GtkWidget *widget, cairo_t *cr)
{
    gtk_render_background(gtk_widget_get_style_context(widget), cr,
			  0, 0,
			  gtk_widget_get_allocated_width(widget),
			  gtk_widget_get_allocated_height(widget));
}
Example #21
0
//!
//! @brief To be written
//!
static void gw_kanjipadwindow_annotate_drawingarea_stroke (GwKanjipadWindow *window, GList *stroke, cairo_t *cr, gint index)
{
    GwKanjipadWindowPrivate *priv;
    GdkPoint *cur, *old;

    // Annotate the stroke with the stroke number - the algorithm
    // for placing the digit is pretty simple. The text is inscribed
    // in a circle tangent to the stroke. The circle will be above
    // and/or to the left of the line
    priv = window->priv;

    if (stroke)
    {
      old = (GdkPoint *)stroke->data;
      do
      {
        cur = (GdkPoint *)stroke->data;
        stroke = stroke->next;
      }
      while (stroke && abs(cur->x - old->x) < 5 && abs (cur->y - old->y) < 5);
      
      if (stroke)
      {
        char buffer[16];
        int swidth, sheight;
        gint16 x, y;
        double r;
        double dx = cur->x - old->x;
        double dy = cur->y - old->y;
        double dl = sqrt(dx*dx+dy*dy);
        int sign = (dy <= dx) ? 1 : -1;

        swidth = 0;
        sheight = 0;

        sprintf (buffer, "%d", index);

        r = sqrt(swidth*swidth + sheight*sheight);
        
        x = 0.5 + old->x + 0.5*r*dx/dl + sign * 0.5*r*dy/dl;
        y = 0.5 + old->y + 0.5*r*dy/dl - sign * 0.5*r*dx/dl;
        
        x -= swidth/2;
        y -= sheight/2;

        x = CLAMP (x, 0, gtk_widget_get_allocated_width (GTK_WIDGET (priv->drawingarea)) - swidth);
        y = CLAMP (y, 0, gtk_widget_get_allocated_height (GTK_WIDGET (priv->drawingarea)) - sheight);

        cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
        cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
        cairo_set_font_size (cr, 10.0);
        cairo_move_to (cr, x, y);
        cairo_show_text (cr, buffer);
        cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
      }
    }
}
Example #22
0
static gboolean on_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) {
    if (surface != NULL) {
        cairo_surface_destroy(surface);
    }
    surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR,
            gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget));
    clear_surface();
    return TRUE;
}
Example #23
0
static gboolean
gdaui_bar_draw (GtkWidget *widget,
		cairo_t   *cr)
{
	GtkStyleContext *context;

	context = gtk_widget_get_style_context (widget);

	gtk_render_background (context, cr, 0, 0,
			       gtk_widget_get_allocated_width (widget),
			       gtk_widget_get_allocated_height (widget));
	gtk_render_frame (context, cr, 0, 0,
			  gtk_widget_get_allocated_width (widget),
			  gtk_widget_get_allocated_height (widget));

	GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);

	return FALSE;
}
Example #24
0
static void menu_position_cb (GtkMenu * menu, int * x, int * y, int * push, void * button)
{
    int xorig, yorig, xwin, ywin;

    gdk_window_get_origin (gtk_widget_get_window (window), & xorig, & yorig);
    gtk_widget_translate_coordinates (button, window, 0, 0, & xwin, & ywin);

    * x = xorig + xwin;
    * y = yorig + ywin + gtk_widget_get_allocated_height (button);
    * push = TRUE;
}
Example #25
0
gboolean ks_chart_draw(GtkWidget * widget, cairo_t * cr, KsChart * data)
{
   gint width = gtk_widget_get_allocated_width(widget);
   gint height = gtk_widget_get_allocated_height(widget);

   cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
   cairo_rectangle(cr, 0, 0, width, height);
   cairo_fill(cr);

   return TRUE;
}
Example #26
0
File: gtk.c Project: langwadt/slope
static gboolean on_draw (GtkWidget *widget, cairo_t *cr, gpointer *data)
{
    slope_rect_t rect;
    rect.x = 0.0;
    rect.y = 0.0;
    rect.width = (double) gtk_widget_get_allocated_width(widget);
    rect.height = (double) gtk_widget_get_allocated_height(widget);
    slope_scene_t *scene = (slope_scene_t*) data;
    slope_scene_draw(scene, cr, &rect);
    return TRUE;
}
Example #27
0
/** 
* @brief Get dimention
* 
* @param display gui_display instance
* @param width   memory to store width
* @param height  memory to store height
* 
* @retval WG_SUCCESS
* @retval WG_FAILURE
*/
wg_status
gui_display_get_size(Gui_display *display, wg_uint *width, wg_uint *height)
{
    CHECK_FOR_NULL_PARAM(display);
    CHECK_FOR_NULL_PARAM(width);
    CHECK_FOR_NULL_PARAM(height);

    *width  = gtk_widget_get_allocated_width(display->widget);
    *height = gtk_widget_get_allocated_height(display->widget);

    return WG_SUCCESS;
}
Example #28
0
static void main_window_real_size_allocate (GtkWidget* base, GtkAllocation* allocation) {
	MainWindow * self;
	GtkAllocation _tmp0_;
	GtkBox* _tmp1_;
	self = (MainWindow*) base;
	g_return_if_fail (allocation != NULL);
	_tmp0_ = *allocation;
	GTK_WIDGET_CLASS (main_window_parent_class)->size_allocate ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_WINDOW, GtkWindow), &_tmp0_);
	_tmp1_ = self->priv->hbox;
	if (_tmp1_ != NULL) {
		GtkBox* _tmp2_;
		gint _tmp3_ = 0;
		gint _tmp4_ = 0;
		GtkBox* _tmp5_;
		gint _tmp6_ = 0;
		gint _tmp7_ = 0;
		GtkBox* _tmp8_;
		gint _tmp9_ = 0;
		gint _tmp10_ = 0;
		GtkBox* _tmp11_;
		gint _tmp12_ = 0;
		gint _tmp13_ = 0;
		_tmp2_ = self->priv->hbox;
		_tmp3_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
		_tmp4_ = get_grid_offset (_tmp3_);
		gtk_widget_set_margin_left ((GtkWidget*) _tmp2_, _tmp4_ + grid_size);
		_tmp5_ = self->priv->hbox;
		_tmp6_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
		_tmp7_ = get_grid_offset (_tmp6_);
		gtk_widget_set_margin_right ((GtkWidget*) _tmp5_, _tmp7_);
		_tmp8_ = self->priv->hbox;
		_tmp9_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
		_tmp10_ = get_grid_offset (_tmp9_);
		gtk_widget_set_margin_top ((GtkWidget*) _tmp8_, _tmp10_);
		_tmp11_ = self->priv->hbox;
		_tmp12_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
		_tmp13_ = get_grid_offset (_tmp12_);
		gtk_widget_set_margin_bottom ((GtkWidget*) _tmp11_, _tmp13_);
	}
}
Example #29
0
static gboolean main_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
{
  guint width, height;
  dt_lib_colorpicker_t *d = (dt_lib_colorpicker_t *)data;

  width = gtk_widget_get_allocated_width(widget);
  height = gtk_widget_get_allocated_height(widget);
  gdk_cairo_set_source_rgba (cr, &d->rgb);
  cairo_rectangle(cr, 0, 0, width, height);
  cairo_fill (cr);

  return FALSE;
}
Example #30
0
gboolean configure(GtkWidget *w, GdkEvent *event, gpointer data)
{
	GtkLayout *l = (GtkLayout *) layout;
	gint width, height;

	gtk_window_get_size(GTK_WINDOW(w), &width, &height);
	if (layoutSize) {
		width = gtk_widget_get_allocated_width(layout);
		height = gtk_widget_get_allocated_height(layout);
	}
	resize(l, width, height);
	return FALSE;
}