Esempio n. 1
0
func RedrawWindow(W *XWindow, tweetsList []*TweetInfo, mouseClick [2]int) {
	var Attribs C.XWindowAttributes
	C.XGetWindowAttributes(W.Display, W.Window, &Attribs)
	// TODO -- Do this only when resizing?
	C.cairo_xlib_surface_set_size(W.Surface, Attribs.width, Attribs.height)

	C.cairo_set_source_rgb(W.Cairo, 0.1, 0.1, 0.1)
	C.cairo_paint(W.Cairo)

	var Rect C.PangoRectangle
	yPos := 10.0 + W.Scroll

	WindowWidth := Attribs.width

	maxTweetWidth := PixelsToPango(float64(WindowWidth - 5*UIPadding - UserImageSize))

	for i := 0; i < len(tweetsList); i++ {
		t := tweetsList[i]

		C.pango_layout_set_width(t.Layout, maxTweetWidth)
		C.pango_layout_get_extents(t.Layout, nil, &Rect)

		// Get tweet text size
		_, ry, _, rh := PangoRectToPixels(&Rect)

		// Position and add padding
		ry += yPos
		if rh < UserImageSize+2*UIPadding-UIPadding {
			rh = UserImageSize + 2*UIPadding
		} else {
			rh += UIPadding
		}

		// Draw rectangle around tweet
		C.cairo_set_source_rgb(W.Cairo, 0.2, 0.2, 0.2)
		C.cairo_rectangle(W.Cairo, UIPadding, C.double(ry), C.double(WindowWidth-2*UIPadding), C.double(rh))
		C.cairo_fill(W.Cairo)
		if mouseClick[0] >= UIPadding && float64(mouseClick[1]) >= ry && float64(mouseClick[1]) <= ry+rh {
			fmt.Println("Clicked tweet", t.Text)
		}

		// Draw user image
		userImage := GetCachedImage(W.UserImages, t.UserImage)
		if userImage == nil || C.cairo_surface_status(userImage) != C.CAIRO_STATUS_SUCCESS {
			userImage = placeholderImage
		}
		C.cairo_set_source_surface(W.Cairo, userImage, 2*UIPadding, C.double(yPos+UIPadding))
		C.cairo_paint(W.Cairo)

		// Draw tweet text
		C.cairo_move_to(W.Cairo, 63, C.double(yPos+SmallPadding))
		C.cairo_set_source_rgb(W.Cairo, 0.95, 0.95, 0.95)
		C.pango_cairo_show_layout(W.Cairo, t.Layout)
		yPos += 5 + rh
	}
}
Esempio n. 2
0
func ShowLayout(cr0 *cairo.Context, layout0 pango.LayoutLike) {
	var cr1 *C.cairoContext
	var layout1 *C.PangoLayout
	if cr0 != nil {
		cr1 = (*C.cairoContext)(cr0.C)
	}
	if layout0 != nil {
		layout1 = layout0.InheritedFromPangoLayout()
	}
	C.pango_cairo_show_layout(cr1, layout1)
}
Esempio n. 3
0
//void pango_cairo_show_layout       (cairo_t          *cr,
//				    PangoLayout      *layout);
func CairoShowLayout(cr *cairo.Context, layout *Layout) {
	C.pango_cairo_show_layout(cairo_context(cr), layout.native())
}