Beispiel #1
0
RECT_T GMsgBox::GetButtonRect(void)
{
	RECT_T brect;
	POINT_T bs = get_border_size();
	int distance = 4*font->hdistance + 2*bs.x;
	for(unsigned char mask =1, i=0; mask < MBF_LAST_BTN; mask <<=1, i++)
	{
		if(type & mask)
			brect.x1 += (strlen(MB_IDS[i]) * font->hspacing) + distance;
	}
	brect.y1 = font->vspacing + 2*font->vdistance + 2*bs.y;
	brect.Deflate(0, 2);
	brect.Offset(client_rect.x0, client_rect.y1 - brect.y1);
	return brect;
}
Beispiel #2
0
static void
gtk_numerable_icon_ensure_emblem (GtkNumerableIcon *self)
{
  cairo_t *cr;
  cairo_surface_t *surface;
  PangoLayout *layout;
  GEmblem *emblem;
  gint width, height;
  gdouble scale;
  PangoAttrList *attr_list;
  PangoAttribute *attr;
  GdkPixbuf *pixbuf;

  /* don't draw anything if the count is zero */
  if (self->priv->rendered_string == NULL)
    {
      g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
      return;
    }

  surface = get_image_surface (self);
  cr = cairo_create (surface);

  layout = get_pango_layout (self);
  pango_layout_get_pixel_size (layout, &width, &height);

  /* scale the layout to be 0.75 of the size still available for drawing */
  scale = ((get_surface_size (surface) - 2 * get_border_size (self)) * 0.75) / (MAX (height, width));
  attr_list = pango_attr_list_new ();

  attr = pango_attr_scale_new (scale);
  pango_attr_list_insert (attr_list, attr);

  attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
  pango_attr_list_insert (attr_list, attr);

  pango_layout_set_attributes (layout, attr_list);

  /* update these values */
  pango_layout_get_pixel_size (layout, &width, &height);

  /* move to the center */
  cairo_move_to (cr,
                 get_surface_size (surface) / 2. - (gdouble) width / 2.,
                 get_surface_size (surface) / 2. - (gdouble) height / 2.);

  gdk_cairo_set_source_rgba (cr, self->priv->foreground);
  pango_cairo_show_layout (cr, layout);

  cairo_destroy (cr);

  pixbuf =
    gdk_pixbuf_get_from_surface (surface, 0, 0,
                                 get_surface_size (surface), get_surface_size (surface));

  emblem = g_emblem_new (G_ICON (pixbuf));
  g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
  g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (self), emblem);

  g_object_unref (layout);
  g_object_unref (emblem);
  g_object_unref (pixbuf);

  cairo_surface_destroy (surface);
  pango_attr_list_unref (attr_list);
}
Beispiel #3
0
unsigned int GMsgBox::initialize (GMessage& msg)
{
	LCD_MODULE* lcd = ((LCD_MODULE **)msg.lparam)[0];
	id = ID_MB_DLG;
	rect = lcd->rect;
	flags = GO_FLG_BORDER|GO_FLG_ENABLED|GO_FLG_SHOW|GO_FLG_SELECTED;

	RECT_T button_rect;
	RECT_T title_rect;
	RECT_T message_rect;

	int bnum =0;
	for(int mask = 1; type && mask < MBF_LAST_BTN; mask <<=1)
		if(type & mask)
			bnum++;

	if(body.empty() && !init_size.as_int )
	{
		for(int i=0; i < lcd->chars_per_row/2; i++)
			body += '.';
		type |= MBF_CLR;
	}

	POINT_T bs = get_border_size();
	text_metrics_t msg_size;
    int x_offset, y_offset;
	while(1)
	{
		allocate_border();
		if(bnum)
			button_rect = GetButtonRect();
		title_rect = GetTitleRect();
		message_rect =client_rect;

		message_rect.y0 += title_rect.height()+1; 								// title to message spacing 1 dot
		message_rect.y1 -= (button_rect.height())?(button_rect.height()):1;		// message to buttons spacing 1 dot

		int width=0;
		int dec = message_rect.width();
		if(type & MBF_EDIT)
			dec -= 2*bs.x;

		if(init_size.as_int)
			msg_size.as_int = init_size.as_int;
		else
			msg_size = get_text_metrics(body.c_str(), dec, font);

		if(msg_size.height + font->vspacing < message_rect.height())
		{
			rect.y1 -= message_rect.height() - (msg_size.height + font->vspacing);
			continue;
		}
		else
		{
			if(message_rect.height() < msg_size.height)
			{
				flags |= GO_FLG_VSCROLL;
				x_offset = message_rect.height();
				if(client_rect.height() > msg_size.height)
					message_rect.y1 = message_rect.y0 + msg_size.height;
				else
					message_rect.y1 = message_rect.y0 + client_rect.height();// +client_rect.y1;
				x_offset = message_rect.height() - x_offset;
				if(button_rect)
				{
					button_rect.Offset(0, x_offset);
				}
			}
		}
		if(dec > msg_size.width + 3*font->hdistance)
		{
			message_rect.x1 -= dec - msg_size.width - 3*font->hdistance;
			text_metrics_t new_msg_size;
			new_msg_size = get_text_metrics(body.c_str(), message_rect.width(), font);
			while(new_msg_size.height != msg_size.height )
			{
				message_rect.x1 += 3*font->hdistance;
				new_msg_size = get_text_metrics(body.c_str(), message_rect.width(), font);
			}
		}
		width = message_rect.width();
		if( title_rect.width() > width)
			width = title_rect.width();
		if(button_rect.width() + bnum * bs.x > width)
			width = button_rect.width() + bnum * bs.x ;
		if(client_rect.width() > width)
		{
			rect.x1 -= client_rect.width() - width;
			continue;
		}
		break;
	}
	if(type & MBF_CLR)
		body.clear();

    x_offset = (lcd->rect.width() - rect.width())/2;
    y_offset = (lcd->rect.height() - rect.height())/2;

    rect.Offset(x_offset, y_offset);
    client_rect.Offset(x_offset, y_offset);
    button_rect.Offset(x_offset, y_offset);
    if(title_rect)
    {
    	title_rect.x0 = rect.x0;
    	title_rect.x1 = rect.x1;
    	title_rect.Offset(0, y_offset);
    	GFlags flg = GO_FLG_SHOW|GO_FLG_TRANSPARENT;
    	if(message_rect.height() >= client_rect.height())
    		flg |= GO_FLG_ENABLED;
    	title_box = new GTitle(	ID_MB_TITLE, title_rect, title, nullptr,
    							flg, SS_CENTER|SS_TOP);
    	addChild(title_box);
    }
    if(message_rect.width() < client_rect.width())
    	x_offset += (client_rect.width() - message_rect.width())/2;
    message_rect.Offset(x_offset, y_offset);

    if(type & MBF_EDIT)
    {
    	edit_box = new GEdit(ID_MB_TEXT_BOX, message_rect, body, nullptr,
    			((bnum)?0:GO_FLG_SELECTED)|
				 GO_FLG_BORDER|GO_FLG_VSCROLL|GO_FLG_TRANSPARENT|GO_FLG_DEFAULT,
				 GET_MBF_EDIT_FLAGS(type),
				font);
		if(addChild(edit_box))
		{
			edit_box->shift = GET_MBF_INPUT_TYPE(type);
			text_box = edit_box;
		}
    }
    else
    {
    	text_box = new GText(ID_MB_TEXT_BOX, message_rect, body, nullptr,
 				GO_FLG_VSCROLL|GO_FLG_TRANSPARENT|GO_FLG_SHOW,SS_DEFAULT,font);
		if(addChild( text_box ))
		{
			if(message_rect.height() < msg_size.height)
				text_box->flags |= GO_FLG_ENABLED;
		}
    }
	int bdistance = client_rect.width();

	if ( bnum )
	{
		if(bdistance > button_rect.width())
		{
			bdistance -= button_rect.width();
			bdistance /= bnum+1;
		}
		else
			bdistance = 0;
		int distance = 4*font->hdistance + 2*bs.x;
		button_rect.Inflate(0,2);
		button_rect.Offset(0,1);
		for(unsigned char mask =1, i=0; mask < MBF_LAST_BTN; mask <<=1, i++)
		{
			if(type & mask)
			{
				if(!default_button)
					default_button = mask;

				button_rect.x0 += bdistance;
				button_rect.x1 = button_rect.x0 + (strlen(MB_IDS[i]) * font->hspacing) + distance;
				addChild(new GButton(mask/*ret_codes[i]*/, button_rect, ret_codes[i], MB_IDS[i],
						GO_FLG_DEFAULT|GO_FLG_BORDER|GO_FLG_TRANSPARENT|
						((default_button&mask)?GO_FLG_SELECTED:0 )));
				button_rect.x0 += button_rect.width();
			}
		}
	}
	weak_gui_message_beep(GET_MBF_BEEP_TYPE(type));
	return GDialog::initialize(msg);
}