Re: Gtkmm draw line with mouse events
- From: Gurjot Singh <bhattigurjot gmail com>
- To: Chris Vine <chris cvine freeserve co uk>
- Cc: gtkmm-list gnome org
- Subject: Re: Gtkmm draw line with mouse events
- Date: Tue, 15 Jul 2014 00:30:25 +0530
On 14 July 2014 23:19, Chris Vine <chris cvine freeserve co uk> wrote:
Suppose I have two functions that are called to draw point and line,
something like this:
http://pastebin.com/Ancx87EF
This example looks fine.
But if this is it, it'd re-draws the whole drawing area, so I'd be
unable to retain any previously drawn entity.
I don't understand what you mean here.
I meant that, taking an example that I showed earlier, when I call the
on_point_cb() it draws the point like defined and when I call the next
function on_line_cb(), the line is drawn but the previously drawn
point is wiped clean.
IDK maybe this is because I am using queue_draw() which re-draws the
entire widget. But if I understand it correctly, like you suggested
that cairo context is already equipped with clip region and I don't
have to explicitly define this clip_rectangle.
<snip>
And that is why I was asking if it could be done something like,
void DrawingArea :: on_line_cb()
{
cr->set_source_rgb(0.0, 0.26, 0.26);
cr->save();
cr->move_to(0,0);
cr->line_to(100,100);
cr->restore();
cr->stroke();
queue_draw();
std::cout<<"Line created"<<std::endl;
}
But this doesn't work because it says that 'cr' is not declared in the
scope or something related to this.
As a matter of cairo implementation you need a cairo context to work
with. That is provided by the on_draw() method (pre-clipped, as I
said). As a matter of basic C++, the cairo context object needs to be
visible to the code addressing it, which means it must be in scope.
I've declared the cairo context in the DrawingArea.h file as:
Cairo::RefPtr<Cairo::Context> cr;
And the 'scope error' is resolved but I get the segmentation error.
And on running backtrace I get the following:
(gdb) backtrace
#0 0x00007ffff6e24c84 in Cairo::Context::set_source_rgb(double,
double, double) () from /usr/lib/x86_64-linux-gnu/libcairomm-1.0.so.1
#1 0x000000000040d4ca DrawingArea::on_point_cb (this=0x7cce00)
at /home/src/DrawingArea.cpp:78
What I think is that it is not able to identify the context correctly.
Even though I've declared the 'cr' in .h file, the context cr in
on_draw(const Cairo::RefPtr<Cairo::Context>& cr) might be different.
Confused here. :/
--
Gurjot Singh
Blog: http://bhattigurjot.wordpress.com
"It takes a person who is wide awake to make his dream come true." ~
Roger Babson
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]