On 18-May-2000 Angus Leeming wrote:
[snip]
> 
> I looked in insettext.[Ch]. SCARY!
> 

#:O)

>>From what I can see, the methods of importance here are
>       int ascent(Painter &, LyXFont const &) const;
>       int descent(Painter &, LyXFont const &) const;
>       int width(Painter &, LyXFont const &) const;
>       void draw(Painter &, LyXFont const &, int baseline, float & x) const;
> 
> which exist in both InsetText and in the parent class to InsetCitation,
> InsetCommand.
> 
> In InsetCommand, the inset is a button.
> width() returns the width of the button.
> draw() draws the button and updates the current position, "x".
>>From what I can make out, ascent() and descent() return now much above and
> below some datum the button (or is it the font?) reaches.
> 
> So far so good?
> 
> So, if I want to draw an inset over more than one line, I need to draw multiple
> buttons?

Or draw 1 multirow button, but this is not supported now in the Painter, so
you would have to do it by hand! Something as:

vector<string> s; // here are the row-strings I want to paint as button

//
// first calculate with and height
//
int height = 0;
int maxwidth = 0;
for (string::const_iterator sit = s.begin(); sit != s.end(); ++sit) {
    height += lyxfont::maxAscent(font) + lyxfont::maxDescent(font) + 2;
    maxwidth = max(width, lyxfont::width(sit, font);
}

// now draw

int asc = ascent(pain, font) + 3;

pain.button(x, baseline - asc, maxwidth + 8, height+6);

int cx = int(x) + 4;
int cy = baseline;

for (string::const_iterator sit = s.begin(); sit != s.end(); ++sit) {
    text(cx, cy, sit, font);
    cy += lyxfont::maxAscent(font) + lyxfont::maxDescent(font) + 2;
}

> 
> How do I proceed?
> I guess the first thing I have to do in InsetCommand::draw() is split
>       string s = getScreenLabel();
> up into its constituent parts (individual keys).
> 
> (A secondary point: getScreenLabel returns a comma separated list of keys.
> Would it be better to return a vector<string> of keys and then insert the
> commas when drawing the label? I think it would. Comments?)
> 
> and then rebuild them so that the button will fit on the line with as many keys
> as possible. 
> This is a loop I guess: (psuedo code!)
> 
> while( keys ) {
>       build button;
>       draw button;
>       keys++
> }
> 

Well I would say first you have to make the width(), ascent() and descent()
functions. You have to think about how you want the inset displayed-vertically
and then divide the height of the inset between ascent and descent. The inset
should be relatively small and so you can recalculate all each time.

Look above then how to draw it (obviously you should then use the width()
ascent(), descent() functions to get the values for the drawing, without
duplicationg code ;)

> Searching further, I see that in InsetText::computeTextRows(), the max width
> available is determined with maxWidth = getMaxTextWidth(pain, this);
> 

Ok this fuction just splits the whole text up in rows depending on how much
space I have. You'll see that there is also the posibility that the inset
is not allowed to split up and so all is displayed on one row (autoBreakRows).
For getting the maximum allowed with you can draw in call getMaxWidth() as
that is an inset-function and returns you the maximum width you can use
(max is the page-width of the painter but you could be inside another inset
wich already sets its max width and so the width will be less).

> So, I can use this in InsetCommand::draw() to help me decide whether I need 
> more than one button:
>       maxWidth = getMaxTextWidth(pain, this);
>       if( x+width() > maxWidth )
>               draw multiple buttons;
>       else
>               draw one button;

Yes something like that only use getMaxWidth(pain, this)!

> 
> I know this isn't rigorous, but am I on the right track?

You are!

Hope this helps!

      Jürgen

-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._

Dr. Jürgen Vigna                      E-Mail: [EMAIL PROTECTED]
Italienallee 13/N                     Tel:    +39-0471-450260
I-39100 Bozen                         Fax:    +39-0471-450296
ITALY                                 Web:    http://www.sad.it/~jug

Who dat who say "who dat" when I say "who dat"?
                -- Hattie McDaniel

-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._

Reply via email to