TVirtualPad::PaintLine and line width

Hi,

I’m trying to use this method to draw lines of different widths in the same pad. First, is this possible ? And then how ? I’m using gPad->SetLineWidth(), but of course it seems this change globally the width of all the lines…

Thanks,

Hi,

You can use the user interface to set different line widths in a canvas window. After drawing the lines just activate the graphics editor selecting View menu / Editor (it will show up on the left of the canvas window as shown on the attached picture). After that click with the left mouse button on the line which width you want to change and use the combo box to set its width. You have a choice between 1 and 15 pixels. Then click the next line and set the same way line width for it.

Cheers, Ilka

Hi,

Thanks. But I’d like to achieve the same result programmatically (basically I have an object that must be drawable, and its representation calls for different line thicknesses)

Regards,

TLine inherits fom TAttline and therefore you can set the line width of a TLine using SetLineWith().

Hi,

Well, I’m not using a TLine. This is maybe what I misunderstand. I’m in my Class::Paint() method, and I thought I can only use PaintXXX methods from there. Am I correct ?
If I am, then I use PaintLine, and for this one I don’t seem to be able to be able to set the line width for only one line (and not the others in the same gPad).
Not sure I explain myself clearly…
In the attached picture, what I’d like is the borderline of each colored zone to be thicker than the internal lines.


When you the the gPad->PaintLine method you are at a very low level (there is no object “Line” involved). It will simply paint a line with the current line attributes on the screen and in a PS file if needed.

So, what do I need to do then ?
Use several PaintLine “stacked” onto each other to get a thicker one ?

thanks,

It works like a state machine …

  • you set the line width …
  • paint line 1
  • paint line 2
  • paint line 3
  • you set an other line width
  • paint line 4
  • paint line 5

line 1 2 3 have the same line width and lines 4 and 5 have an other line width.
As I said this graphics layer is the very basic one.

ok, so to recap, if I do :

gPad->SetLineWidth(1)
gPad->PaintLine(…) (a)
gPad->PaintLine(…) (b)

gPad->SetLineWidth(3)
gPad->PaintLine(…) ©

gPad->SetLineWidth(1)
gPad->PaintLine() (d)

I’ll then get 3 lines of thickness 1 (a,b,d) and 1 of thickness 3 ©, is that right ?

Yep.

Hi,

Ok. It works as advertized :wink:
Now a related question. When a line has a width=w>1, and I do a e.g. a PaintLine(x,x+dx,y,y), will the left part of my line begin at x-AbsPixeltoX(w/2) or at x ? (this is to avoid mismatch of lines, as seen in the attached picture)

Thanks,

You get this effect because you paint single lines, between two points. When you paint polylines this effect is not visible as shown in the attached gif file.


Hum, yes, but the algorithm I have to draw my lines would be a tad more difficult with polylines… No way to do it with single lines ?

The line position is independant of the line width … of course … it would be really bad to see lines becoming longer when the line width changes ! Only when a polyline is drawn it can be decided to finish each piece of line in a way it connects to the next one “in a nice way” because we know the whole line. Note that the first and last points of the polyline are also fixed.

[quote=“aphecetche”]Hum, yes, but the algorithm I have to draw my lines would be a tad more difficult with polylines… No way to do it with single lines ?[/quote]With ROOT Qt-layer “on” you can use Qt QPainter class to complement the TPad drawing and apply
doc.trolltech.com/3.3/qt.html#PenCapStyle-enum
See, for example root.bnl.gov/QtRoot/root/qtExamp … Pixmap.cxx ) example to show how to use the very PenStyle if needed

[quote=“couet”]The line position is independant of the line width … of course … it would be really bad to see lines becoming longer when the line width changes !..[/quote]Hi Olivier, What about to complement TVirtualX /TAttLine class with TAttLine::SetLineCapStyle method? This should be useful for many users and simple to implement for any platfrom.

What is done here is independant line segments. The linecap will not help. To be efficient the linecap must be applied on a polyline. Seems to me we had that discussion in the past already … don’t we ?
We have it for PostScript already:
root.cern.ch/root/htmldoc/TPostS … ostScript:SetLineJoin

[quote=“couet”]What is done here is independant line segments. The linecap will not help. To be efficient the linecap must be applied on a polyline. Seems to me we had that discussion in the past already … don’t we ?
We have it for PostScript already:
root.cern.ch/root/htmldoc/TPostS … ostScript:SetLineJoin[/quote]Yes I agree, read carefully the link I mentioned:
doc.trolltech.com/3.3/qt.html#PenCapStyle-enum
to see it did discuss the “join style” too
doc.trolltech.com/3.3/qt.html#PenJoinStyle-enum
Both features are available for the Qt/Root users ( from ROOT prompt too via root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html ). May be you find these features are common / useful enough to promote them to the TVirtualX level.

Now in TGX11 we have:

static int gCapStyle = CapButt;
static int gJoinStyle = JoinMiter;

that’s is fixed, I agree. Do we really something else … ?

[quote=“couet”]Now in TGX11 we have:

static int gCapStyle = CapButt;
static int gJoinStyle = JoinMiter;

that’s is fixed, I agree. Do we really something else … ?[/quote]Uhh !! I am lost! Where is the abstract interface ? Why this is for X11 ONLY ??? What was the technical reason for such constrain? Can you provide an example of the end-user code to manage the features you mentioned ? Why it is X11 specific?