Can I draw a rectangle in GtkWindow directly without GtkDrawingArea? - gtk

1、I have looked up many references about drawing a rectangle in GtkWindow in Gtk,but lots of them are used GtkDrawingArea . I want to know that can I draw a rectangle in GtkWindow directly without GtkDrawingArea?And if i can do this ,how should i do? Is there any examples or references?
2、Actually, I need to draw a rectangle in a gtkwindow ,and then add two buttons in the rectangle and specify coordinates of the point set to the fixed color value in a small field in the rectangle.
I have tried the way of drawing rectangle by GtkDrawingArea,but GtkDrawingArea isn't a GTK_CONTAINER ,so I can't add anything in GtkDrawingArea;I also tried to use some Layout managers such as gtk_vbox ,but it seems failed. I can't place a button in the area of the rectangle.
Now I am confused how to do next.If someone can give me some guide or reference ,Thank you for much!

Yes, you can. You may need to set the "app-paintable" flag on the GtkWindow, but you can connect to its draw signal, and draw on the background with Cairo. Then return FALSE from the draw signal handler to signify that other handlers should still be invoked for the drawing; then the buttons can still be drawn on top. I don't know of any online examples for drawing directly on the window, though.

Related

Can I begin_move_drag only on opaque part when using cairo in Gtk?

Gtk-3.0 here.
I draw some thing directly on window using cairo. Some part of window is transparent, other is opaque(or partly transparent).
I want begin drag (begin_move_drag function) the window only when the mouse point is on the non-transparent part. So how can I judge the current point is transparent statu? Get the screen pixmap and check the alpha value? Or maybe some cairo tricks can help me?

Leaflet showing radius as drawing circle

I was asked to see if I could using leaflet draw a circle and as I'm drawing it show what the current expanding radius is. Either as a tooltip or write it to a page label. I noticed the circle option has a showRadius option but can you capture this value as your drawing the circle?
Kind of like the measure tool that uses the drawing plugin can show your distance as you move the mouse.
This way the user can see how big their circle is as they are drawing it.
Any ideas, examples, hints?
Leaflet.draw plugin does that.
Check out this demo
However, it shows radius only when you create a circle. Unfortunately, not when you edit it.

How to change the shape of a UIButton in Swift?

I am trying to make an arrow shape. I understand that it will be done with CGRect method but can you give a complete example of how it will be done in SWIFT?
This can be done programmatically by first subclassing UIButton and overriding drawRect within it to form the shape of an arrow via bezier paths. Then simply set the title of the button to be whatever you want your text to be and position it accordingly within the shape you have drawn.
The benefit of doing it this way is that you can easily change the color of, scale and dimensions of the arrow since you control how the object is actually being drawn.
A good tool for drawing complex bezier paths is paintCode. I'm using the trial version and can pretty easily make shapes like this now.

How to draw custom line on MKMapview?

I've been searching for a way to draw a custom line, but the only help I can find is how to draw lines with an UIColor.
I want to draw a straight line but not just with a color. I want the appearance of the line to be customizable.
(So right now I can draw lines between 2 points, but not the line I want)
The line I want got straight 45 degree lines on it, and it's grey and black.
Anybody can help?
The line looks like this, I'm also thinking that I could stretch this image, but if I stretch it, it will look kinda weird.
Why don't you add image then? I'm new developer so I don't know other way to do it. Only OpenGL with texturing, but there is no need to use openGL. So my suggestion is to add image.
Sound like what your looking for is the MKPolylineView Class. You assign it a polyline which contains the points in your line. Since the polyline view is an MKOverlayPathView you can set the stroke and fill colors.
Since it's also a UIView subclass you can manipulate the appearance even further by grabing the views layer property and adding gradients, shadows, masks, etc.
Is there a specific effect that you're trying to achieve?

Add shading to clipped UIView

I'm creating an iphone application. I have this UIView whose content is clipped with a path. I want to add shading and/or shadow to it. What's the best way to do this? For shadow, I tried CGContextSetShadow() but it doesn't seem to have an effect (perhaps it's drawing outside the shown region?) . How about shading? I want it to appear along the path. What's the best way to go about it? Is it to create another narrow clip strip along the original clipping path (if it's possible to have two clip path... ) Or does this need to be done in another CALayer? I am not even sure what that is yet.
You can't add shadows to layers which are clipped or masked. The way I would do this is use two CALayers, one for the clipped content and place this inside another for the shadow which isn't clipped.