GContext_t FontStruct_t etc.. with (for example) TGlabel

From: Rutger van der Eijk (r36@nikhef.nl)
Date: Mon Aug 03 1998 - 13:48:05 MEST


Hi Rooters/Fons,

First: the example with the possibility to embed a TCanvas in a TGFrame
looks promising. I was waiting for this, and will try it myself later this
week.

Concerning the GContext_t etc...:

I have some problems using GContext_t etc.. to make a red TGLabel of a
certain font. I see that a font is part of a GContext_t, so I define a
GContext_t in a similair way as in the guitest.cxx example. 

i.e. in my case:
-----------
  // create new graphics context
  FontStruct_t labelfont;
  labelfont = gClient->GetFontByName(
              "-adobe-helvetica-medium-r-*-*-18-*-*-*-*-*-iso8859-1");
  GCValues_t   gval;
  gval.fMask = kGCForeground | kGCFont;
  gval.fFont = gGXW->GetFontHandle(labelfont);
  gClient->GetColorByName("red", gval.fForeground);
  
  fTextGC = gGXW->CreateGC(gClient->GetRoot()->GetId(), &gval);
---------

Now when I use this gcontext for a TGLabel:
--------
  fTextLabelLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX,
				       10, 10, 10, 10);
  fTextLabel1 = new TGLabel(this, "Outer Tracker", fTextGC);
  AddFrame(fTextLabel1, fTextLabelLayout);	
  Resize(fTextLabel1->GetWidth(), fTextLabel1->GetHeight());
------ (in reality more complicated) ------

my frame is resized to a size as if i had a font of size '12', instead of
the 18 as in 'labelfont' up here. It might be that I'm doing
something wrong here. It's not completely clear to me when I should use
Resize(XXX), and what a later Resize(XXX) of a motherframe does with the
previous one. But when I look at the constructor of TGLabel i see that the
datamembers fTWidth and fTHeight are set according to the FontStruct_t
passed as argument to the constructor, i.e,
------
   TGLabel(const TGWindow *p, TGString *text,
           GContext_t norm = fgDefaultGC,
           FontStruct_t font = fgDefaultFontStruct,
           UInt_t options = kChildFrame,
           ULong_t back = fgDefaultFrameBackground);
------
the problems is that because I don't specify this FontStruct_t I get the
default font struct. This then overrides the one in my specified
GContext_t. It seems strange to me that if I specify a GContext_t, which
already contains something for the font, I should still specify a
FontStruct. Maybe some check in the constructor is appropriate
here (for example on the fMask member).

Thanks,

Rutger



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET