help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: units updater for figures is broken when using fltk


From: Ben Abbott
Subject: Re: units updater for figures is broken when using fltk
Date: Sun, 05 Feb 2012 12:00:48 -0500

On Feb 5, 2012, at 7:14 AM, Michael Goffioul wrote:

> On Sun, Feb 5, 2012 at 12:35 AM, Ben Abbott <address@hidden> wrote:
> 
>> This diff below worked for me, but I liked your suggestion of using the 
>> get_boundingbox better.
>> 
>> ----------------------
>> diff --git a/src/DLD-FUNCTIONS/__init_fltk__.cc 
>> b/src/DLD-FUNCTIONS/__init_fltk__.cc
>> --- a/src/DLD-FUNCTIONS/__init_fltk__.cc
>> +++ b/src/DLD-FUNCTIONS/__init_fltk__.cc
>> @@ -1173,7 +1173,10 @@
>> 
>>   void draw (void)
>>   {
>> +    octave_value funits = fp.get_units ();
>> +    fp.set_units (octave_value ("pixels"));
>>     Matrix pos = fp.get_position ().matrix_value ();
>> +    fp.set_units (funits);
>>     Fl_Window::resize (pos(0), pos(1), pos(2), pos(3) + status_h + menu_h);
>> 
>>     return Fl_Window::draw ();
>> ----------------------
> 
> It might solve your problem, but this is not a good solution imo. What
> if the user attached a listener to the units property?

Good point. You've clued me in to a larger problem. See the end of my reply.

>> Unfortunately, it looks to me as if get_boundingbox returns the wrong 
>> result.  I tried the change below ...
>> 
>> ----------------------
>> --- a/src/DLD-FUNCTIONS/__init_fltk__.cc
>> +++ b/src/DLD-FUNCTIONS/__init_fltk__.cc
>> @@ -1173,7 +1173,7 @@
>> 
>>   void draw (void)
>>   {
>> -    Matrix pos = fp.get_position ().matrix_value ();
>> +    Matrix pos = fp.get_boundingbox (true);
>>     Fl_Window::resize (pos(0), pos(1), pos(2), pos(3) + status_h + menu_h);
>> 
>>     return Fl_Window::draw ();
>> ----------------------
>> 
>> The result was what appeared to be an infinite loop, that produced a very 
>> large figure that rendered mostly to the right of my screen.
>> 
>> Am I missing something, or is the get_boundingbox result due to your comment 
>> regarding Matlab world above [1].
> 
> I think the problem is not in get_boundingbox, but in the incorrect
> interpretation of the position property in the FLTK code. Moreover,
> the code is probably not robust against feedback loops when changing
> properties, like:
> 1) the user change figure position
> 2) the backend is notified and move/resize the figure window
> 3) as in any toolkit, moving/resizing the window triggers corresponding events
> 4) the backend receives events and propagates the changes back to the
> figure position (this is needed as the move/resize could be the result
> of a user action with the mouse)
> 5) if the newly computed position does not match the previous one, goto 1)
> 
> Step 4) above should not happen when the position change is coming
> from octave, but I suspect it does, which can explain the infinite
> loop you're seeing.
> 
> Michael.

The loop may have been due to my not understanding what I was doing. I used ...

        Matrix pos = fp.get_boundingbox (true);

But I don't understand what the boolean arg is intended for. In graphics.cc 
(figure::properties::get_boundingbox) the boolean is named "internal" and is 
references in the snippet below.

        Matrix pos = (internal ?
                      get_position ().matrix_value () :
                      get_outerposition ().matrix_value ());

I choose get_boundingbox (true) because I don't know the purpose of the 
outerposition property for figures (there's none in Matlab). I notice you added 
it  below.

        
http://hg.savannah.gnu.org/hgweb/octave/annotate/d99aa455296e/src/graphics.cc

What is the figure's outerposition property for ?

Back to the need to obtain the figure position property in pixels, I attempted 
the change below, but ran into scoping problems.

  void draw (void)
  {
    Matrix screen_size = screen_size_pixels ();
    Matrix pos = fp.get_position ().matrix_value ();
    pos = convert_position (pos, get_units (), "pixels", screen_size);
    Fl_Window::resize (pos(0), pos(1), pos(2), pos(3) + status_h + menu_h);

    return Fl_Window::draw ();
  }

DLD-FUNCTIONS/__init_fltk__.cc: In member function 'virtual void 
plot_window::draw()':
DLD-FUNCTIONS/__init_fltk__.cc:1180:46: error: 'screen_size_pixels' was not 
declared in this scope
DLD-FUNCTIONS/__init_fltk__.cc:1182:72: error: 'convert_position' was not 
declared in this scope

I can resolved the scoping problem with convert_position by calling 
get_boundingbox and then modifying the result, but I still need to obtain the 
screensize in pixels, which I haven't figured out how to do. I may be in over 
my head, so if you're inclined ... feel free take this on.

On a related note, many properties are changed during the print() process. 
These changes would trigger listeners set up by the user (figure position, and 
fontname, fontsize properties can be modified). Would it make sense be able to 
"disable" and "enable" user specified listeners to avoid any unexpected 
craziness? If so, that feature would be useful here as well.

Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]