// $Revision: 1.9 $ // TitleDrawer.C // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_TITLEDRAWER #include "TitleDrawer.h" #endif #ifndef TaligentSamples_STANDARDGRAPH #include "StandardGraph.h" #endif #ifndef Taligent_GRAFPORT #include #endif #ifndef Taligent_ASSERTIONS #include #endif //============================================================================== // TTitleDrawer TTitleDrawer::TTitleDrawer( ETitleType xOrYAxis, const GCoordinate& distanceFromAxis, const TStandardText& title, const TFontPointSizeStyle& fontSize, const TFontFamilyStyle& font) : TGraphDrawer(), fTitle(title, font, fontSize), fDistance(distanceFromAxis), fType(xOrYAxis) { } TTitleDrawer::TTitleDrawer(const TTitleDrawer& source) : TGraphDrawer(source), fTitle(source.fTitle), fDistance(source.fDistance), fType(source.fType) { } TTitleDrawer::~TTitleDrawer() { } TTitleDrawer& TTitleDrawer::operator=(const TTitleDrawer& source) { if (&source != this) { TGraphDrawer::operator=(source); fTitle = source.fTitle; fDistance = source.fDistance; fType = source.fType; } return *this; } TStream& TTitleDrawer::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); TGraphDrawer::operator>>=(toStream); fTitle >>= toStream; fDistance >>= toStream; (short)fType >>= toStream; return toStream; } TStream& TTitleDrawer::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); TGraphDrawer::operator<<=(fromStream); fTitle <<= fromStream; fDistance <<= fromStream; short type; type <<= fromStream; fType = (ETitleType)type; return fromStream; } void TTitleDrawer::DrawIntoGraph(TGrafPort& port) const { ::Assertion(fType != kInvalidType, "Title type must be set to kXAxisTitle or kYAxisTitle."); if (fType == kXAxisTitle) { fTitle.Draw(port); } else if (fType == kYAxisTitle) { TGPoint titleOrigin; fTitle.GetOrigin(titleOrigin); TLinkedModelMatrixPort rotatedPort(&port, TGrafMatrix(-90.0, titleOrigin)); fTitle.Draw(rotatedPort); } } TGRect TTitleDrawer::GetBounds() const { TGRect bounds(fTitle.GetTextBounds()); if (fType == kYAxisTitle) { TGPoint titleOrigin; fTitle.GetOrigin(titleOrigin); bounds = TGrafMatrix(-90.0, titleOrigin).TransformBounds(bounds); } return bounds; } void TTitleDrawer::Prepare(const TStandardGraph& graph) { TGPoint titleOrigin = graph.MapValuesToPoint(graph.GetXRange().GetMin(), graph.GetYRange().GetMin()); if (fType == kXAxisTitle) { titleOrigin.fY += fDistance + fTitle.GetTextBounds().GetHeight(); } else if (fType == kYAxisTitle) { titleOrigin.fX -= fDistance; } fTitle.SetOrigin(titleOrigin); } TTitleDrawer::TTitleDrawer() : TGraphDrawer(), fTitle(), fDistance(0.0), fType(kInvalidType) { }