Hi Rooters, here follows a little explenation on using custom graphics contexts in the TG widgets. A graphics context (GContext_t) defines attributes with which primitives are drawn. All widget classes define some static protected GC's that are used when creating a corresponding widget object. Most widgets share the same GC as to get a coherent looking interface while defining only a few GC's (all default GC's are defined in the TGClient class). To create a widget with, for example, a non default color one has to define a new GC and pass that in the widget ctor. In the example below we create a TGLabel with a red foreground color (plug this piece of code in the $ROOTSYS/guitest.cxx just above "fLtitle = "). To see the red label click on "Click here". // Create new graphics context for drawing of TGlabel with text in red. // Use default font as specified in .rootrc FontStruct_t labelfont; labelfont = gClient->GetFontByName(gEnv->GetValue("Gui.NormalFont", "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1")); // Define new graphics context. Only the fields specified in // fMask will be used (for default TGLabel context see // http://root.cern.ch/root/html/src/TGClient.cxx.html). GCValues_t gval; gval.fMask = kGCForeground | kGCFont; gval.fFont = gGXW->GetFontHandle(labelfont); gClient->GetColorByName("red", gval.fForeground); GContext_t redlabelgc = gGXW->CreateGC(gClient->GetRoot()->GetId(), &gval); fLtitle = new TGLabel(f4, new TGString("Title:"), redlabelgc); Once you have a custom GC you can copy or change it using gGXW->CopyGC() and gGXW->ChangeGC(). Once all widgets using the custom GC's are deleted you should also delete the GC using: gGXW->DeleteGC(redlabelgc); Cheers, Fons. Wei Xie wrote: > > Dear Rooters, > > One more question about TGLabel, please. > > A TGLabel has the following ctor: > > TGLabel(const TGWindow *p, TGString *text, > GContext_t norm = fgDefaultGC, > FontStruct_t font = fgDefaultFontStruct, > UInt_t options = kChildFrame, > ULong_t back = fgDefaultFrameBackground); > > Could you tell me how to get value of > "fgDefaultGC" and "kChildFrame" ? > > Sincerely > > Xie > > W__W W__W > / \ PHONE : 972 8 9343372 (o) 9471872 (h) / \ > ( 0 _ 0) Fax : 972-8-946-6253 (0 _ 0 ) > \_ V_/ E-mail: xiewei@ceres.weizmann.ac.il \_^ _/ > / \ / \ > =OOOo=======oOOO====================================OOOo=======oOOO====== -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland Phone: +41 22 7679248 E-Mail: Fons.Rademakers@cern.ch Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET