Fix width/height when context is out of the Chart.

This commit is contained in:
Kolan Sh 2017-10-06 22:46:28 +03:00
parent 7d9ce0e2b4
commit 42b846fa75
2 changed files with 6 additions and 13 deletions

View File

@ -1,8 +1,8 @@
namespace Gtk.CairoChart { namespace Gtk.CairoChart {
public class Chart { public class Chart {
protected double width = 0; public double width = 0;
protected double height = 0; public double height = 0;
public Cairo.Context context = null; public Cairo.Context context = null;
@ -35,9 +35,9 @@ namespace Gtk.CairoChart {
} }
protected double cur_x_min = 0.0; protected double cur_x_min = 0.0;
protected double cur_x_max = 0.0; protected double cur_x_max = 1.0;
protected double cur_y_min = 0.0; protected double cur_y_min = 0.0;
protected double cur_y_max = 0.0; protected double cur_y_max = 1.0;
public virtual void check_cur_values () { public virtual void check_cur_values () {
if (cur_x_min > cur_x_max) if (cur_x_min > cur_x_max)
@ -48,8 +48,6 @@ namespace Gtk.CairoChart {
public virtual bool draw () { public virtual bool draw () {
update_size ();
draw_background (); draw_background ();
cur_x_min = cur_y_min = 0.0; cur_x_min = cur_y_min = 0.0;
@ -84,13 +82,6 @@ namespace Gtk.CairoChart {
return true; return true;
} }
protected virtual void update_size () {
if (context != null) {
width = context.copy_clip_rectangle_list().rectangles[0].width;
height = context.copy_clip_rectangle_list().rectangles[0].height;
}
}
protected virtual void set_source_rgba (Color color) { protected virtual void set_source_rgba (Color color) {
context.set_source_rgba (color.red, color.green, color.blue, color.alpha); context.set_source_rgba (color.red, color.green, color.blue, color.alpha);
} }

View File

@ -341,6 +341,8 @@ int main (string[] args) {
// user's pre draw operations here... // user's pre draw operations here...
chart.context = context; chart.context = context;
chart.width = da.get_allocated_width();
chart.height = da.get_allocated_height();
/*var ret = */chart.draw(); /*var ret = */chart.draw();
// user's post draw operations here... // user's post draw operations here...