[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

IVBDrawing-Interface and Implementation-Demos

Schmidt

6/25/2012 5:11:00 PM

Hi *.*

Have finally found the time, to come up with the
proposed TypeLib, which contains nearly all the
known VB-Drawing-Methods and -Properties (up to
the ScaleMode-Handling and the Printer-stuff
like NewPage, EndDoc etc.).

To test it properly, I was starting with a simple
implementation of the (at this time sparse) interface
.... in two Classes first ... a simpler one, which was
only mapping the Interface-Methods to an internally hosted
PictureBox nearly 1:1 ... and to be able to compare it
against the Screen-Drawing of a different Render-Backend,
I've also implemented a class, which internally hosts cairo
(an image-surface - and the cairo-context for this surface).

So that was the starting-point, ending up with the pretty easy:
cDrwPictureBox
accompanied by the antialiasing-capable:
cDrwCairoImg

Both implementations were working encouragingly well,
especially for the "weird Param-Syntax" which methods
I had defined in the Typelib first, to not run into
surprises.
So, after that "Go", I've defined and implemented "all
the rest" of the methods and properties too, to have
at lest the interface "out of the way" and be able to
forget all about the TypeLib-Editing.

Then, after I had two well working "Screen-Classes" - it was
more or less a copy and paste-operation for the one which
needed to interact directly with VBs Printer-Object.
So, cDrwPictureBox and cDrwPrinter share a lot of code.
The last one of them was cDrwCairoPDF - which also took
a lot of code over (from cDrwCairoImg) accordingly.

Last task then, because everything still went quite smoothly -
was the enhancement of cDrwCairoImg (one of the "Screen-
Classes"), to also act directly as a Zoomable ScreenPreview,
in case one was setting two *optional* Parameters in the
Bind-Call (PageWidthTwips and PageHeightTwips)...
In this case an automatic "extra-scaling" takes place,
with the correct Aspect-Ratio and Size, the defined
PageSize-in-Twips is demanding.

So, the amount of code which is needed, to achieve a zoomable,
antialiased PrintPreview, is now pretty low - and along the
way I tried to fix some "quirks" (in my opinion) of the VB-Printer-
Object too ... so that e.g. the LineWidth-Output is now ending up
roughly the same, as the (always Pixelbased) LineWidth which is
shown on a "PictureBox-based Screen-Class".

The following Demo needs vbRichClient4 installed - but
then is starting up two simple TestForms, which can
be seen here in this ScreenShot, in case you want only
to take a look:
www.datenhaus.de/Downloads/IVBDrawing.png

The left Form there contains only 25 lines of code and
shows the Render-Output of the two "Screen-Classes".

The right Form is a bit "heavier" (about 40 lines of code),
and shows the Screen-Output of cDrwCairoImg in PrintPreview-
Mode (sized along with the Window-Container-Size).

The two buttons then trigger the other two remaining,
printing-oriented Classes (cDrwPrinter and cDrwCairoPDF).

I've set my System-Printer to the Cute-PDF-Driver, to
be able to compare the both differently generated PDF-
File-Contents for correctness among each other - and
also for similarity with the PrintPreview-ScreenOutput.

Here's the VB-Code for the Test-Project:
www.datenhaus.de/Downloads/IVBDrawing.zip

@Eduardo and Mike Williams...
I was not very convinced at first, whether mimicking
this old VB-Drawing-Stuff was really worth it, because
it really lacks "in power" (no alpha, no rounded rects,
no proper Transforms, no clipping/masking etc) ... but
now, after it's done, I think a little bit more backward-
compatiblity with regards to the planned compiler and
the new cairo-based Rendering is not that bad either.
That's the reason I've driven the implementation to
near completion already (about 95% I guess) - but in
case you want to take it over into your maintenance
from now on, Eduardo - I'd have at least this stuff
"off my back" now - I'm sure there's still a few bugs
in it - it will need some more tests, that's for sure...

In case you find - and fix (or simply enhance) something,
just mail me your changes, so that I can include it into
the RC4-libs later on "officially".

Just for completeness, in case one doesn't want to do
the download - this is the kind of VB-Drawing-Code
all the 4 different IVBDrawing-Implementing Classes
now understand in the same way:


Please throw your own larger VB-Drawing-Routines at it,
as said, the whole thing is in need of some more heavy tests


'**** Here's what the Demo currently has in modDrawing.bas:

Option Explicit

Public Const PI# = 3.14159265358979

'this routine can be shared by the two Implementations, which
'understand and implement the few additional "VB-Printing-Methods"
'(cDrwPrinter and cDrwCairoPDF)

Public Sub PrintingTest(ByVal Drw As IVBDrawing)
'draw the first page in Portraitmode
Drw.Orientation = vbPRORPortrait
DrawingTest Drw

'second Page in Landscape-Mode, using the same drawing-routine
Drw.NewPage True
DrawingTest Drw

Drw.EndDoc
End Sub

'And this routine is shared by all of the 4 different Implementations
Public Sub DrawingTest(ByVal Drw As IVBDrawing)
Dim S As String
Const strHello As String = "Hello World"
Drw.Cls
Drw.ForeColor = vbBlack

'***Printing-related Implementations have a Device-independent Default-
'***Scalemode initialized to vbPoints (1/72 inch)
'***whereas Screen-related Implementations start with a Default-
'***Scalemode of vbPixels after their BindTo-Call was done
'***
'***but in the next, outcommented block, one can override to a few
'***differently enforced VB-ScaleModes, to compare and test for similar
'***behaviour also with one of these other Coord-Mappings below...
'
' Drw.ScaleMode = vbTwips
' Drw.ScaleMode = vbPoints
' Drw.ScaleMode = vbPixels
' Drw.Scale (22, 297)-(210, 33)
' Debug.Print Drw.ScaleLeft, Drw.ScaleTop, Drw.ScaleWidth,
Drw.ScaleHeight
'
'***though the coords we use in the following Drawing-calls work best,
'***when the Scalemodes are left at their defaults (Pixels or Points)


'we start with a left- and a right-aligned text at the top,
'with info about the current Drw-Implementation
Drw.FontName = "Arial"
Drw.FontSize = 9
Drw.FontItalic = False
Drw.FontBold = False
Drw.FontUnderline = False
S = "left-aligned, UTF16-WChar: " & ChrW(&H6CD5)
Drw.PrintText S, True '< suppress the linefeed after Print

S = "right-aligned (Impl.: " & TypeName(Drw) & ")"
Drw.CurrentX = Drw.ScaleWidth - Drw.TextWidth(S)
Drw.PrintText S

'a larger, solidly filled 3/4 ellipse with a missing pie
Drw.FillStyle = vbFSSolid
Drw.FillColor = vbYellow
Drw.DrawWidth = 2
Drw.Circle (120, 90), 100, vbBlue, 0, 270 / 180 * PI, 0.5

'relative to the center-point of the last drawn ellipse,
'a larger Text
Drw.FontName = "Times New Roman"
Drw.FontSize = 20
Drw.FontBold = True
Drw.FontItalic = True
Drw.PrintText strHello, True '<- True is similar like having a ';'
' at the end of a VB.Print

'now relative to the just printed larger Text, a smaller circle
'with only a Border and no FillColor
Drw.FillStyle = vbFSTransparent
Drw.ForeColor = vbMagenta 'this is used for the BorderColor,
'when we leave out the Color-Param
Drw.DrawWidth = 6
Drw.Circle Step(0, Drw.TextHeight(strHello) + 40), 40

'centered TextOutPut within the small Circle we've just drawn
Drw.ForeColor = vbRed
Drw.FontSize = 8
Drw.CurrentX = Drw.CurrentX - Drw.TextWidth(strHello) / 2
Drw.CurrentY = Drw.CurrentY - Drw.TextHeight(strHello) / 2
Drw.FontUnderline = True
Drw.PrintText strHello

'here come a few line-tests
Drw.Line Step(40, 20)-Step(80, 290), vbGreen
Drw.Line -Step(170, 0)
'last line in "rectangle Box-mode"
Drw.FillStyle = vbFSSolid
Drw.FillColor = vbCyan
Drw.Line -(Drw.ScaleWidth, Drw.ScaleHeight), vbBlue, B

'a scaled Image per PaintPicture (with a small Offset,
'relative to the center-point)
Drw.PaintPicture LoadPicture(App.Path & "\img.jpg"), _
Drw.ScaleWidth /2+10, Drw.ScaleHeight / 2 + 10, _
Drw.ScaleWidth / 3, Drw.ScaleWidth / 5

'and finally the PSet-Test, drawing a larger Point
'at the center of the canvas (or Page)
Drw.DrawWidth = 10
Drw.PSet (Drw.ScaleWidth / 2, Drw.ScaleHeight / 2), vbBlack
'Ok, just two diagonal lines more, crossing that point and we're done
Drw.DrawWidth = 1
Drw.Line Step(-10, -10)-Step(20, 20), vbBlack
Drw.Line Step(-20, 0)-Step(20, -20), vbBlack
Drw.Refresh
End Sub


1 Answer

mm

6/25/2012 11:14:00 PM

0


"Schmidt" <sss@online.de> escribió en el mensaje
news:jsa640$ibp$1@dont-email.me...

Hi Olaf,

I see that I need to understand all this this in deep. I'll have to do it
with time.
So far I have run your demo project and I saw what it does.

I think that to have backward compatibility, as much as possible, is
something desirable that can lead to the early adoption of the new
environment by more VB6 programmers.
Remember that one of the problems with .Net was that the old code didn't
work with it and there was a need to rewrite everything. (it was just one of
the issues).

I' not saying that the features cannot be expanded, but it would be nice to
be done trying to keep it compatible with early versions.
For example using other methods for more powerful features not available in
VB6 or adding extra optional parameters to the existing methods.
I also realize that to work like that means more work.