Prod.: Engine, ver.: 6, ID: 60000976, HowTo : Example of drawings primitives on over all drawing

HowTo : Example of drawings primitives on over all drawing

Article60000976
TypeHowTo
ProductEngine
Version6
Date Added10/13/2009
Submitted byWayne Romer
Keywords

Subject

Example of drawings primitives on over all drawing

Summary

I would like to implement some functionality which renders an overlay over the top of all entities on the screen. Ideally, at the start, I would just like to be able to draw a date string at the bottom left of the current vdraw view. This text would be view independent, so that it would always be drawn facing the user no matter what 3D view they have selected. I would also like that around the text is a little shaded so that it is easy to see.

What do you think is the best approach to doing this. Any sample code would be greatly appreciated.

Solution

Example in C# Windows Application using vdFramed Control :


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using VectorDraw.Professional.vdObjects;
using VectorDraw.Professional.vdFigures;
using VectorDraw.Professional.vdPrimaries;
using VectorDraw.Generics;
using VectorDraw.Geometry;
using VectorDraw.Professional.vdCollections;
using VectorDraw.Actions;


namespace WindowsApplication2
{


   public partial class Form2 : Form
   {

      public Form2()
      {
         InitializeComponent();
      }


      private vdDocument doc { get { return vdFramedControl1.BaseControl.ActiveDocument; } }


      VectorDraw.Render.grTextStyle textstyle = null;


      protected override void OnLoad(EventArgs e)
      {
         base.OnLoad(e);
         doc.OnDrawAfter += new vdDocument.DrawAfterEventHandler(doc_OnDrawAfter);
         doc.OnDrawOverAll += new vdDocument.DrawOverAllEventHandler(doc_OnDrawOverAll);
         //create a global TextStyle used to draw the overall text
         textstyle = new VectorDraw.Render.grTextStyle("Arial");
      }

    void drawoverall(VectorDraw.Render.vdRender render)
    {
   
    double DPIScale=1.0d; //ratio render DPI/ScreenDPI
       
if (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW)
        {
            DPIScale = (
double)render.Height / (double)(doc.ActiveLayOut.Printer.LandScape ? doc.ActiveLayOut.Printer.paperSize.Width : doc.ActiveLayOut.Printer.paperSize.Height);
        }

       
//make the active render unlock so it will always draw using GDIPlus API
       
bool islock = render.IsLock;
       
if (islock) render.UnLock();
       
//Get the display string
       
string str = System.DateTime.Now.ToShortDateString();
       
//Calculate the text box with the selecting text style Size.
       
Box textbox = textstyle.GetBaseTextBox(str, null);
       
//create a box that will be drawn in the text background and will be 25% biger tham the text box.
       
Box box = new Box(textbox);
        box.AddWidth(textbox.Height * 0.25);
       
//calculate a Matrix that will scale and offset the drawing primitives.
       
Matrix m = new Matrix();
       
double OneMM_DUSize = render.PixelSize * DPIScale * render.DpiY * 1.0d / 25.4;
       
//select the text height to be 10 mm of height.
       
double scale = OneMM_DUSize * 10.0d / textbox.Height;
       
Box rendersize = render.ClipBounds.ToBox();

        //select the left offset of the box to be 15 mm of width, and the the bottom offset of the box to be 15 mm.
       
gPoint offset = new gPoint((render.ClipBounds.Xmin + OneMM_DUSize * 15.0d), (render.ClipBounds.Ymin + box.Height * scale + OneMM_DUSize * 15.0d));
   
    if (render.IsPrinting) //taking into consideration the printer hardware margins
        {
            offset.x += (OneMM_DUSize *
Globals.INCH_MM * doc.ActiveLayOut.Printer.Hardmargins.Left / 100);
            offset.y += (OneMM_DUSize *
Globals.INCH_MM * doc.ActiveLayOut.Printer.Hardmargins.Bottom / 100);
        }

        m.ScaleMatrix(scale, scale, scale);
        m.TranslateMatrix(offset);

        //select the matrix and draw the primitives
       
render.PushToViewMatrix();
        render.PushMatrix(m);
        render.PushPenstyle(
new VectorDraw.Render.vdGdiPenStyle(Color.Brown, 150));
        render.DrawSolidBoundBox(
this, box);
        render.PopPenstyle();
        render.PushPenstyle(
new VectorDraw.Render.vdGdiPenStyle(Color.Blue, 255));
        render.DrawString(
this, textstyle, null, str, textbox);
        render.PopPenstyle();
        render.PopMatrix();
        render.PopMatrix();
   
    if (islock) render.Lock();
    }


//we use the OnDrawAfter event only when priniting because the OnDrawOverAll is not fired when printing
      void doc_OnDrawAfter(object sender, VectorDraw.Render.vdRender render)
      {
         if (render.IsPrinting && (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PRINTER_PAPER)) drawoverall(render);
      }


      void doc_OnDrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel)
      {
         drawoverall(render);
      }


   }
}