home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 6.8 KB | 256 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRuler.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef FWRULER_H
- #include "FWRuler.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h" // FW_CRectShape
- #endif
-
- #ifndef FWTXTSHP_H
- #include <FWTxtShp.h> // FW_CTextShape
- #endif
-
- #ifndef FWLINSHP_H
- #include <FWLinShp.h> // FW_CLineShape
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CRuler, FW_CView)
-
- //========================================================================================
- // CLASS FW_CRuler
- //========================================================================================
-
- const FW_CFixed kRulerExtent = FW_IntToFixed(1000);
-
- //----------------------------------------------------------------------------------------
- // FW_CRuler::FW_CRuler
- //----------------------------------------------------------------------------------------
-
- FW_CRuler::FW_CRuler(Environment* ev,
- FW_CView* container,
- const FW_CRect& bounds,
- int contentSpace) :
- FW_CView(ev, container, bounds,
- (contentSpace & FW_CView::kXaxis) ? FW_CPoint(kRulerExtent, bounds.bottom - bounds.top) :
- FW_CPoint(bounds.right - bounds.left, kRulerExtent),
- NULL,
- contentSpace)
- {
- FW_ASSERT(contentSpace != 0);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRuler::~FW_CRuler
- //----------------------------------------------------------------------------------------
-
- FW_CRuler::~FW_CRuler()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRuler::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CRuler::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- FW_CRect bounds;
- invalidShape->GetBoundingBox(ev, (ODRect*)&bounds);
-
- FW_CRectShape::RenderRect(vc, bounds, FW_kFill, FW_kWhiteEraseInk);
-
- if (UseContentSpaceInX(ev))
- RenderHorizontalRuler(vc, bounds);
- else
- RenderVerticalRuler(vc, bounds);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRuler::RenderGradation
- //----------------------------------------------------------------------------------------
-
- void FW_CRuler::RenderGradation(FW_CViewContext& vc,
- short gradation,
- const FW_PFont& font,
- const FW_CPoint& pos)
- {
- FW_CString32 string;
-
- #ifdef FW_BUILD_MAC
- Str255 pString;
- NumToString(gradation, pString);
- string.ReplaceAll(pString);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not Yet Implemented!");
- #endif
-
- FW_CTextShape::RenderText(vc, string,
- FW_CPoint(pos.x - FW_kFixedPos1, pos.y - FW_kFixedPos1),
- font,
- FW_kTextAlignRight | FW_kTextAlignBottom);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRuler::RenderHorizontalRuler
- //----------------------------------------------------------------------------------------
-
- void FW_CRuler::RenderHorizontalRuler(FW_CViewContext& vc, const FW_CRect& visibleRect)
- {
- FW_PStyle lineStyle(FW_kFixed0);
- FW_PFont theFont(FW_kTimes, FW_kPlain, FW_IntToFixed(10));
-
- FW_CLineShape::RenderLine(vc,
- FW_CPoint(visibleRect.left, visibleRect.bottom - FW_kFixedPos1),
- FW_CPoint(visibleRect.right, visibleRect.bottom - FW_kFixedPos1),
- FW_kNormalInk, lineStyle);
-
- short h = visibleRect.Height().AsInt();
- FW_CFixed full = FW_IntToFixed(2 * (h / 3));
- FW_CFixed half = FW_IntToFixed(h / 2);
- FW_CFixed third = FW_IntToFixed(h / 3);
-
- short gradation = visibleRect.left.AsInt() / 72;
- FW_CFixed minX = FW_IntToFixed(72 * gradation);
- FW_CFixed maxX = FW_IntToFixed(72 * ((visibleRect.right + FW_kFixed72).AsInt() / 72));
-
- FW_CFixed fixed18 = FW_IntToFixed(18);
-
- short n = 0;
- FW_CFixed height = full;
- if (minX == FW_kFixed0)
- {
- minX = fixed18;
- n = 1;
- height = third;
- }
-
- FW_CPoint start(minX, visibleRect.bottom);
- FW_CPoint end(minX, visibleRect.bottom - height);
- for (FW_CFixed x = minX; x <= maxX; x += fixed18)
- {
- FW_CLineShape::RenderLine(vc, start, end, FW_kNormalInk, lineStyle);
- if (n == 0)
- RenderGradation(vc, gradation, theFont, start);
-
- n++;
- if (n == 4)
- {
- n = 0;
- gradation++;
- height = full;
- }
- else if (n == 2)
- height = half;
- else if (n == 1 || n == 3)
- height = third;
-
- start.x += fixed18;
- end.x += fixed18;
- end.y = visibleRect.bottom - height;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRuler::RenderVerticalRuler
- //----------------------------------------------------------------------------------------
-
- void FW_CRuler::RenderVerticalRuler(FW_CViewContext& vc, const FW_CRect& visibleRect)
- {
- FW_PStyle lineStyle(FW_kFixed0);
- FW_PFont theFont(FW_kTimes, FW_kPlain, FW_IntToFixed(10));
-
- FW_CLineShape::RenderLine(vc,
- FW_CPoint(visibleRect.right - FW_kFixedPos1, visibleRect.top),
- FW_CPoint(visibleRect.right - FW_kFixedPos1, visibleRect.bottom),
- FW_kNormalInk, lineStyle);
-
- short h = visibleRect.Width().AsInt();
- FW_CFixed full = FW_IntToFixed(2 * (h / 3));
- FW_CFixed half = FW_IntToFixed(h / 2);
- FW_CFixed third = FW_IntToFixed(h / 3);
-
- short gradation = visibleRect.top.AsInt() / 72;
- FW_CFixed minY = FW_IntToFixed(72 * (visibleRect.top.AsInt() / 72));
- FW_CFixed maxY = FW_IntToFixed(72 * ((visibleRect.bottom + FW_kFixed72).AsInt() / 72));
-
- FW_CFixed fixed18 = FW_IntToFixed(18);
-
- short n = 0;
- FW_CFixed width = full;
- if (minY == FW_kFixed0)
- {
- minY = fixed18;
- n = 1;
- width = third;
- }
-
- FW_CPoint start(visibleRect.right, minY);
- FW_CPoint end(visibleRect.right - width, minY);
- for (FW_CFixed y = minY; y <= maxY; y += fixed18)
- {
- FW_CLineShape::RenderLine(vc, start, end, FW_kNormalInk, lineStyle);
- if (n == 0)
- RenderGradation(vc, gradation, theFont, start);
-
- n++;
- if (n == 4)
- {
- n = 0;
- gradation++;
- width = full;
- }
- else if (n == 2)
- width = half;
- else if (n == 1 || n == 3)
- width = third;
-
- start.y += fixed18;
- end.y += fixed18;
- end.x = visibleRect.right - width;
- }
- }
-