Пример #1
0
static MRESULT APIENTRY Paint ( HWND Window, MESG, MPARAM1, MPARAM2 ) {

  /**************************************************************************
   * Find the instance data.                                                *
   **************************************************************************/

   PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ;

  /**************************************************************************
   * Compute the current zoom factor.                                       *
   **************************************************************************/

   double Zoom = (double) FIXEDINT ( Data->fxZoom ) ;
   Zoom += (double) FIXEDFRAC ( Data->fxZoom ) / 0x10000L ;

  /**************************************************************************
   * Get presentation space and prepare it for use.                         *
   **************************************************************************/

   RECTL ClippingRectangle ;
   WorkSpace PS ( "HRuler::Paint", 0, Window, Data->pDevice, int(Data->Metric), ClippingRectangle ) ;
   PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ;
   PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, ClippingRectangle ) ;

  /**************************************************************************
   * Clear the window and draw a border.                                    *
   **************************************************************************/

   RECTL WindowRectangle ;
   WinQueryWindowRect ( Window, &WindowRectangle ) ;

   WindowRectangle.xRight -- ;
   WindowRectangle.yTop -- ;

   PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, WindowRectangle ) ;

   PS.SetColor ( Data->IniData->fRulerColors[0] ? Data->IniData->RulerColors[0] : RGB_WHITE ) ;
   PS.FillBox ( WindowRectangle ) ;

   PS.SetColor ( RGB_BLACK ) ;
   PS.DrawBox ( WindowRectangle ) ;

  /**************************************************************************
   * Draw the left margin.                                                  *
   **************************************************************************/

   if ( ClippingRectangle.xLeft <= Data->LeftMargin ) {

      PS.SetColor ( Data->IniData->fRulerColors[1] ? Data->IniData->RulerColors[1] : RGB_BLUE ) ;
      PS.SetFillType ( PATSYM_HALFTONE ) ;
      RECTL Box = { ClippingRectangle.xLeft, ClippingRectangle.yBottom,
         Data->LeftMargin, ClippingRectangle.yTop } ;
      PS.FillBox ( Box ) ;
      PS.SetFillType ( PATSYM_DEFAULT ) ;

      PS.SetColor ( RGB_BLACK ) ;
      PS.SetLineType ( LINETYPE_ALTERNATE ) ;
      POINTL Point = { Data->LeftMargin, ClippingRectangle.yTop } ;
      PS.Move ( Point ) ;
      Point.y = ClippingRectangle.yTop ;
      PS.DrawLine ( Point ) ;
      PS.SetLineType ( LINETYPE_SOLID ) ;

   } /* endif */

   POINTL Point = { Data->LeftMargin, WindowRectangle.yTop } ;
   PS.Transform ( CVTC_DEFAULTPAGE, CVTC_DEVICE, 1, &Point ) ;
   Point.y -= 8 ;
   PS.DrawPointer ( Data->MarginPtr, Point, DP_NORMAL ) ;

  /**************************************************************************
   * Draw the right margin.                                                 *
   **************************************************************************/

   if ( ClippingRectangle.xRight >= Data->RightMargin ) {

      PS.SetColor ( Data->IniData->fRulerColors[1] ? Data->IniData->RulerColors[1] : RGB_BLUE ) ;
      PS.SetFillType ( PATSYM_HALFTONE ) ;
      RECTL Box = { Data->RightMargin, ClippingRectangle.yBottom,
         ClippingRectangle.xRight, ClippingRectangle.yTop } ;
      PS.FillBox ( Box ) ;
      PS.SetFillType ( PATSYM_DEFAULT ) ;

      PS.SetColor ( RGB_BLACK ) ;
      PS.SetLineType ( LINETYPE_ALTERNATE ) ;
      Point.x = Data->RightMargin ;
      Point.y = ClippingRectangle.yBottom ;
      PS.Move ( Point ) ;
      Point.y = ClippingRectangle.yTop ;
      PS.DrawLine ( Point ) ;
      PS.SetLineType ( LINETYPE_SOLID ) ;

   } /* endif */

   Point.x = Data->RightMargin ;
   Point.y = WindowRectangle.yTop ;
   PS.Transform ( CVTC_DEFAULTPAGE, CVTC_DEVICE, 1, &Point ) ;
   Point.x -= 8 ;
   Point.y -= 8 ;
   PS.DrawPointer ( Data->MarginPtr, Point, DP_NORMAL ) ;

  /**************************************************************************
   * Draw the tab-stops.                                                    *
   **************************************************************************/

   for ( int i=0; i<Data->TabCount; i++ ) {
      Point.x = Data->Tabs[i] ;
      Point.y = WindowRectangle.yTop ;
      PS.Transform ( CVTC_DEFAULTPAGE, CVTC_DEVICE, 1, &Point ) ;
      Point.y -= 8 ;
      PS.DrawPointer ( Data->TabstopPtr, Point, DP_NORMAL ) ;
   } /* endfor */

  /**************************************************************************
   * Draw the ruler.                                                        *
   **************************************************************************/

   for ( long x=WindowRectangle.xLeft; x<WindowRectangle.xRight; x++ ) {
      if ( x % ( Data->Metric ? 200 : 250 ) == 0 ) {
         PS.SetColor ( RGB_BLACK ) ;
         Point.x = x ;
         Point.y = 0 ;
         PS.Move ( Point ) ;
         if ( x % 1000 == 0 ) {
            Point.y = LONG ( 200.0 / Zoom ) ;
            PS.DrawLine ( Point ) ;
            Point.x += LONG ( 50.0 / Zoom ) ;
            Point.y = LONG ( 50.0 / Zoom ) ;
            char Text [10] ;
            sprintf ( Text, "%i", int(x/1000) ) ;
            PS.SetColor ( Data->IniData->fRulerColors[1] ? Data->IniData->RulerColors[1] : RGB_BLUE ) ;
            PS.Move ( Point ) ;
            PS.DrawText ( Text ) ;
         } else if ( x % 500 == 0 ) {
            Point.y = LONG ( 150.0 / Zoom ) ;
            PS.DrawLine ( Point ) ;
         } else {
            Point.y = LONG ( 100.0 / Zoom ) ;
            PS.DrawLine ( Point ) ;
         } /* endif */
      } /* endif */
   } /* endfor */

  /**************************************************************************
   * We're done.                                                            *
   **************************************************************************/

   return ( MRFROMSHORT ( 0 ) ) ;
}