2008-12-15

Convert your buttons to BMPs keeping transparency with GdiPlusX -REVISITED

this is just an update for an old post with the same title. erik gomez and russel campbell had some problems on the conversions of some specific png images, so i recoded this function, this time using a safer code.

new update:

thanks to bernard bout and craig boyd, i've updated the code below. in fact it contained a small bug, that was not adjusting the white colors. now it seems to be working nice. thanks !

this runs a little bit slower than the other aproach, but in my tests, the success was 100%.

the function below converts any button image to a bmp to be used in vfp forms.

there are lots of cool and free icons available on the web, but the vast majority are in .ico, gif or png image formats, that are not very familiar and reliable to be used in vfp. for us, the best image format, for a lot of reasons, is the bmp format.

some transformations are needed to make this bmp to show exactly how we desire, specially when converting source images in a png, gif or ico formats.

vfp shows the pure white - rgb(255,255,255) as transparent in our buttons and image objects. the code below first converts the original whites to rgb(254,254,254) that is visually the same, but does not become transparent, and eliminates the need to create a mask image (.msk) and next, converts the background color of the original bitmap to pure white, that will show transparent in vfp forms.


Important Requires VFP9 and GdiplusX to run.  

Save the program below as button2bmp.prg, and call it this way:

button2bmp(getpict(), "c:\newicon.bmp")

when you compile this program in your executable, please don't forget to remove the locfile() command, and just use a do system.app instead


lparameters tcsourcefile, tcdestfile

* tcsourcefile = getpict()
* tcdestfile = forceext(tcsourcefile, "bmp")

do locfile("system.app")

local lobmp as xfcbitmap
local logfx as xfcgraphics
local loborderclr as xfccolor
local lorect as xfcrectangle
local loattr as xfcimageattributes
local locolormap as xfccolormap
local lodestbmp as xfcbitmap

with _screen.system.drawing
 locolormap = .imaging.colormap.new()
 loattr = .imaging.imageattributes.new()
 lobmp = .bitmap.fromfile(tcsourcefile)
 logfx = .graphics.fromimage(lobmp)

 lodestbmp = .bitmap.new(lobmp.width, lobmp.height, .imaging.pixelformat.format24bpprgb)
 lodestgfx = .graphics.fromimage(lodestbmp)

 * clear the new bitmap
 lodestgfx.clear(.color.white)

 * by craig boyd - for enhancing the smoothless and quality
 lodestgfx.smoothingmode     = .drawing2d.smoothingmode.highquality
 lodestgfx.interpolationmode = .drawing2d.interpolationmode.highqualitybicubic
 lodestgfx.pixeloffsetmode   = .drawing2d.pixeloffsetmode.highquality

 lorect = lobmp.getbounds()

 * get the top left pixel color, presuming this color is the background color to become transparent
 * for our bmp case, this will become pure white - rgb(255,255,255)
 * that becomes transparent when used in vfp objects
 loborderclr = lobmp.getpixel(0,0)

 * convert original whites rgb(255,255,255) to off white - rgb(254,254,254)
 * this way, the whites will remain without the need of a mask
 locolormap.oldcolor = .color.white
 locolormap.newcolor = .color.fromargb(255,254,254,254)

 loattr.setremaptable(locolormap)
 lodestgfx.drawimage(lobmp, lorect, lorect, .graphicsunit.pixel, loattr)

 * next step, convert the borders to pure white, rgb(255,255,255) that will become transparent in buttons
 locolormap.oldcolor = loborderclr
 locolormap.newcolor = .color.white
 loattr.setremaptable(locolormap)

 lodestgfx.drawimage(lodestbmp, lorect, lorect, .graphicsunit.pixel, loattr)

 lodestbmp.save(tcdestfile, .imaging.imageformat.bmp)
endwith




2008-05-26

GdiPlusX undocumented functions

The GdiPlusX library is intended to be compatible with the .net framework’s system.drawing namespace. that means that you can use the msdn online documentation for the “system.drawing” in order to obtain accurate information about the gdiplusx classes. objects and functions. more than that, you can also convert the huge amount of samples published in various forums, blogs, articles and e-magazines to be used in VFP. It really does not matter if the sample was published in VB, C or ASP. the conversion to VFP is really intuitive.
When GdiplusX was coded, we used a .net conversion tool, called reflector, which showed us all the source codes involved in each function, bringing us the possibility to code calling the same api functions, working with the same parameters.
But, during the coding phase, we had some great discussions about things that could be enhanced in order to ease user’s lives. We had a premise not changing the behavior of any function, even if we disagreed with some things there, in order to keep the full compatibility. On the other hand, we have decided that we could add new functions
Below is a short list of some functions that have been added to gdiplusx, that are not present in the .NET original classes. most of them have already been used in some samples posted in this blog, but till now, no documentation was published. so, here are some of those new functions, that came to my mind. probably bo or craig will remember to add something here. i hope to be updating this post with some other improvements that only VFP users have available.
Of course, we know that GdiPlusX still needs some documentation, and we’re working on it. But for now, we hope that the list below will bring you some help.


XfcGraphics class
DrawStringJustified Draws the specified text string at the specified location with the specified brush and font objects in a full justified format.
             Parameters: tcstring, ;                         tofont as xfcfont, ;                         tobrush as xfcbrush, ;                         torectangle as xfcrectangle
             Where:                         tcstring: text to be drawn                         tofont: gdi+x font object                         tobrush: gdi+x brush object                         torectangle: gdi+x rectangle object with position and dimensions to draw
             Returns: nothing
             See also:               Full-justified text with gdiplus-x 
             Full justified texts in your reports with gdiplus x
             Samples: fulljustified.scx  /  fulljustify.prg
             Code sample:
local lctext

text to
lctext noshow
this library
was intended to provide visual foxpro 9.0 developers with an object based library to wrap the 600+ functions included with the gdi+ api. the intent is to mimic the system.drawing namespace in the .net framework. all classes in the library are based on the classes included in the system.drawing namespace and other classes that are dependencies for classes in the system.drawing namespace. some additional additional functionality has been added to take advantage of features built in to vfp 9.0 endtext
do locfile("system.app")
with _screen.system.drawing

   local
logfx as xfcgraphics
   logfx = .graphics.fromhwnd(
_screen.hwnd)
   logfx.drawstringjustified(lctext, .
font.new(“tahoma”,12);
      , .brushes.red, .rectangle.new(0,0,250,400))

endwith


XfcBitmap class
ToClipboard Sends the current bitmap to the clipboard
            Parameters: none
            Returns: nothing
            See also:              Send images to the clipboard with gdiplus-x revisited
            Code sample:
do locfile("system.app")

with _screen
.system.drawing
   local
lobmp as xfcbitmap
   lobmp = .
bitmap.fromfile(getpict())
   lobmp.toclipboard()
endwith

FromClipboard Creates a gdi+ bitmap object from the clipboard data
            Parameters: none
            Returns: gdi+ bitmap object
            Code sample:
do locfile("system.app")
with _screen.system.drawing

   local
lobmp as xfcbitmap
  
lobmp = .bitmap.fromclipboard()
   lobmp.
save
("c:\fromclip.png", .imaging.imageformat.png)
endwith


FromVarbinary Creates an image object from the specified varbinary string. useful to start manipulating an image directly without having to convert the binaries from the image to a file.
            Parameters: tcbinary
            Returns: gdiplusx bitmap object

            Code sample:


do locfile("system.app")
with _screen.system.drawing

   local
lcbinary
  lcbinary =
filetostr(getpict())
   local
lobmp as xfcbitmap
   lobmp = .
bitmap.fromvarbinary(lcbinary)
   lobmp.
save
("c:\fromvarbinary.png", .imaging.imageformat.png) endwith



FromScreen
            Captures the specified window or object image to a new gdi+ bitmap object

            Parameters:
                thwnd, tix, tiy, tiwidth, tiheight, tlensurevisible                 toform [, tix, tiy, tiwidth, tiheight [, tlensurevisible]]                 tocontrol [, tlensurevisible]
            Returns: gdi+ bitmap object
            See also: capture screens with gdiplus-x
            Code sample:

 
do locfile
("system.app")
with _screen
.system.drawing
   local
lobmp as xfcbitmap
   lobmp = .
bitmap.fromscreen()
   lobmp.
save("c:\fromscreen.png", .imaging.imageformat.png)
endwith




GetMonoChrome Returns a monochrome gdi+ bitmap (1bpp) of this image object.
            The image must be saved in the bmp image format in order to keep the 1bpp format. because the resulting bitmap is in an indexed pixel format, gdi+ cannot create a xfcgraphics object in order to draw on it. this function is recommended to be used immediately before saving to a file, in order to obtain the minimum file size. for some specific tiff compression types, a monochrome image of 1bpp is required too, see more details in these articles:
            Parameters: none
            Returns: gdi+ bitmap object
            See also: convert images to monochrome with gdiplus x
                         using tiffs with the new gdi+ classes – update
                         tiffs and the latest release of gdiplusx
            Code sample:

do locfile("system.app")
with _screen
.system.drawing
   local
lobmp as xfcbitmap
   lobmp = .
bitmap.fromfile(getpict())
   local
lomonoch as xfcbitmap
   lomonoch = lobmp.getmonochrome() 
 
 lomonoch.save("c:\monoch.bmp", .imaging.imageformat.bmp) endwith

GetPictureVal Returns a string containing the pictureval of this image object, according to the imageformat passed. you can retrieve the binaries of the image with no disk access, in any image format supported by gdi+
            Parameters: imageformat object
                             encoderparameter object (optional)
            Returns: string
            See also: manipulate images with no disk access with gdiplusx
            Code sample:

do locfile("system.app") local lobmp as xfcbitmap * obtaining the pictureval directly
with _screen
.system.drawing    lobmp = .bitmap.fromfile(getpict())    thisform.image1.pictureval = lobmp.getpictureval (.imaging.imageformat.bmp) endwith

GetPicturevalFromHBitmap Returns a string containing the pictureval of this image object using the hbitmap gdi technique. the binaries retrieved are always in bmp format, what makes it a big string in most times. but, in most cases, this technique runs about 40% faster than using getpictureval() function shown above. the imagecanvas objects uses this function to obtain the binaries from the images drawn.
            Parameters: none
            Returns: string
            See also: manipulate images with no disk access with gdiplusx
do locfile("system.app") local lobmp as xfcbitmap * obtaining the pictureval directly
with _screen
.system.drawing
   lobmp = .
bitmap.fromfile(getpict())    thisform.image1.pictureval = lobmp.getpicturevalfromhbitmap() endwith

ApplyColorMatrix Applies the received color matrix to the current bitmap object.  This is very useful, and provides an easy and quick way to apply image transformations in just one step, without having to use the imageattributes class.
             Parameters:                         tocolormatrix

             Returns: null
             See also: special effects on images with gdiplusx- part1
                           special effects on images with gdiplusx – part2
                           draw logos in your images with gdiplusx - part 2
             Code sample:
do locfile("system.app") with _screen.system.drawing    local lobmp as xfcbitmap
   lobmp = .bitmap.fromfile(getpict())
    local loclrmatrix as xfccolormatrix
   loclrmatrix = .imaging.colormatrix.new(;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0, 0, 0, 1, 0, ;
      0, 0, 0, 0, 1)
   lobmp.applycolormatrix(loclrmatrix)
   lobmp.save("c:\clrmatrix.png", .imaging.imageformat.png)
endwith

GetMask Returns a bitmap object with the mask from the current bitmap.  In fact this function returns a bitmap with all the transparent parts of the image. useful when you need to convert a png image that contains transparencies to be used in the bmp image format.
             Parameters: none
             Returns: gdi+ bitmap object

ToPrinter Sends the image object to the printer
             Parameters: tnstretch, tcprintername, tnorientation, tnalignment
                        tnstretch                         *   specifies how an image is sized to fit inside a control.                         *   0 - clip. the image is clipped to fit the page. (default)                         *   1 - isometric. the image resizes to fit the page while maintaining its original proportions.                         *   2 - stretch. the image resizes to fit the page, but does not maintain its original proportions.
                        tcprintername                         *   specifies the name of the printer, the same of getprinter()
                        tnorientation:                         *   0 - portrait                         *   1 - landscape
                        tnalignment                         *   specifies a numerical value representing the alignment of the image in the page.                         *   0 - vertically centered left.                         *   1 - vertically centered right.                         *   2 - centered. centers image vertically and horizontally.                         *   4 - top left. aligns image in top left corner of the page.                         *   5 - top right. aligns image in top right corner of the page.                         *   6 - top center. aligns image at the top and horizontally centered on the page.                         *   7 - bottom left. aligns image in the bottom left corner of the page.                         *   8 - bottom right. aligns image in bottom right corner of the page.                         *   9 - bottom center. aligns image at the bottom and vertically centered on the page.
            Returns: nothing
            Code sample:
do locfile("system.app") with _screen.system.drawing
   local
lobmp as xfcbitmap
   lobmp = .
bitmap.fromfile(getpict())
   lobmp.toprinter()
endwith


FloodFill 
Fills an area of the current bitmap surface with the passed color. It is used to fill an area with a single specific color, starting from the determined coordinates.
            Parameters: tnX, tnY, toxfcColor
            Returns: nothing
do locfile("System.app") local lobmp as xfcbitmap * obtaining the pictureval directly
with _screen
.system.drawing 
   loBmp = .
bitmap.fromfile(GETPICT())    loBmp.FloodFill(10,100, .Color.Red)   
endwith





XfcColorMatrix class
MatrixMultiply Returns a new color matrix object resulting of the multiplication of two color matrices. this is very useful when more than one color matrix is needed to be applied to an image. multiplying the color matrices before they are applied to the image will bring a huge gain of performance.
            Parameters: tocolormatrixone, ;                         tocolormatrixtwo
            Returns: a new color matrix containing the resultant matrix
            Code sample:
do locfile
("system.app") with _screen.system.drawing    local lobmp as xfcbitmap
   lobmp = .
bitmap.fromfile(getpict())    local loclrmatrix1 as xfccolormatrix && greyscale matrix
   loclrmatrix1 = .imaging.colormatrix.new(;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0, 0, 0, 1, 0, ;
      0, 0, 0, 0, 1)
  local loclrmatrix2 as xfccolormatrix && half brightness matrix
  loclrmatrix2 = .imaging.colormatrix.new(;
      0.5, 0, 0, 0, 0, ;
      0, 0.5, 0, 0, 0, ;
      0, 0, 0.5, 0, 0, ;
      0, 0, 0, 1, 0, ;
      0, 0, 0, 0, 1)

   local lonewclrmatrix as xfccolormatrix
   lonewclrmatrix = loclrmatrix1.multiply(loclrmatrix1, loclrmatrix2)
   lobmp.applycolormatrix(lonewclrmatrix)
   lobmp.save("c:\multclrmatrix.png", .imaging.imageformat.png)
endwith


XfcSize class
toRectangle Returns a xfcrectangle object from the current xfcsizef object


XfcSizeF class
toRectangleF Returns a xfcrectanglef object from the current xfcsizef object

2008-05-21

FoxCharts 0.20 Alpha

here's a new release of foxcharts


https://www.codeplex.com/release/projectreleases.aspx?projectname=vfpx&releaseid=13477


 


prerequisites:
visual foxpro 9 and the gdiplusx library from vfpx 











 


as you can see, 2 new charts are now available:


- stacked area


- cylinder


 



  • the stackedarea chart can be defined using the "charttype" property, that must be set to the numeric 10

  • the cylinder chart is derived from the original bars chart. to have it, select charttype for the bar option, and then set the bartype property to numeric 1 (0 = bar default; 1 = cylinder)

 


apart from this, many other important modifications were applied:


the main difference is that now foxcharts' base class is a container, that contains the gdiplusx imagecanvas, and the legend objects, responsible for drawing all the text needed.

now we can customize any of those labels in lots of ways. every piece of text, legend in the chart now has the following properties:




alignment - 0 left; 1 right; 2 center
backcolor
backcoloralpha - this is cool, (0-255) determines the transparency of the background of the label
caption
fontbold
fontitalic
fontname
fontsize
fontstrikethru
fontunderline
forecolor
forecoloralpha - determines the transparency of the label



the legends are represented by the following objects:



title
subtitle
xaxis
xaxislegend2
yaxis
shapelegend
scalelegend
sidelegend


this way, every piece of text in the chart can be fully customized, not only the font, but the backcolor and the alpha (transparency). now you can also change the alignment of the text, for example, to set the title to right alignment, all you have to do is to:


thisform.foxcharts1.title.alignment = 1 && right


 


i still need to remind you that this is still a preview version, destined for people that are interested in helping testing this tool.



please continue sending your suggestions and feedback!
it is really very appreciated


https://www.codeplex.com/release/projectreleases.aspx?projectname=vfpx&releaseid=13477




contains the alpha version of the foxcharts project.

unzip the file and run the form chartssample to see how it works.

this version also distributes the two main files from gdiplusx - system.app and gdiplusx.vcx.
if you are already a gdiplusx user, you can use your own gdiplusx version.
just make sure to be using the latest gdiplusx version.

gdiplusx is also a vfpx project. for more information, please visit the gdiplusx page at vfpx.


more information and pictures about this project can be obtained at the vfpimaging weblog:

http://weblogs.foxite.com/vfpimaging/archive/2008/04/04/5919.aspx

http://weblogs.foxite.com/vfpimaging/archive/2008/04/24/6040.aspx


this new release contains lots of enhancements:

chart types
- bar charts
- multiple bars
- stacked bars

- pie
- doughnut

- lines
- area
- stacked area
- points and shapes


color variations:
- basic colors
- custom colors
- gradient colors
- random colors
- monochrome
- gradient or solid colors


legends in many places: axys, shapes, side legends

scales

customize:
- titles
- subtitles
- backgrounds (solid or gradient)
- fonts
- colors

2008-05-11

Crop Images with GdiPlusX

Cropping an image is super simple using GdiplusX

Prerequisites
Visual FoxPro 9 and the GdiplusX library from VFPX at GitHub 


Please make sure that you have the latest version!

The cropping is done by the fuction "Clone()" from the xfcBitmap class. All we need is to pass a xfcRectangle object containing the X, Y, Width and Height of the desired image to be cropped.

Original image



Top Left


Center


Bottom Right


Run the code below, selecting any image, and you will see the image cropped in three ways: the top-left part of the image, the bottom-right part, and the center.


LOCAL lcsource, lnwidth, lnheight
m.lcsource = GETPICT()
IF EMPTY(m.lcsource)
 RETURN
ENDIF

DO LOCFILE("system.app")

WITH _SCREEN.SYSTEM.drawing

 * load image to gdiplusx
 LOCAL lobmp AS xfcbitmap
 m.lobmp    = .BITMAP.fromfile(m.lcsource)
 m.lnwidth  = m.lobmp.WIDTH
 m.lnheight = m.lobmp.HEIGHT

 * crop image
 LOCAL locropped AS xfcbitmap

 * crop top-left
 LOCAL lorect AS xfcrectangle
 m.lorect = .rectangle.new(0, 0, m.lnwidth / 2, m.lnheight / 2)
 m.locropped = m.lobmp.CLONE(m.lorect)
 m.locropped.SAVE("d:\Tools\crop-topleft.png", .imaging.imageformat.png)
 RUN /N explorer.EXE d:\Tools\crop-topleft.png

 * crop bottom-right
 * now, the rectangle region will be created inside the clone function
 m.locropped = m.lobmp.CLONE(.rectangle.new(m.lnwidth / 2, m.lnheight / 2, m.lnwidth / 2, m.lnheight / 2))
 m.locropped.SAVE("d:\Tools\crop-bottomright.png", .imaging.imageformat.png)
 RUN /N explorer.EXE d:\Tools\crop-bottomright.png

 * crop center
 m.locropped = m.lobmp.CLONE(.rectangle.new(m.lnwidth / 4, m.lnheight / 4, m.lnwidth / 2, m.lnheight / 2))
 m.locropped.SAVE("d:\Tools\crop-center.png", .imaging.imageformat.png)
 RUN /N explorer.EXE d:\Tools\crop-CENTER.png

ENDWITH
RETURN

2008-04-24

FoxCharts 0.14 ALPHA released !

i'm happy to announce that foxcharts has recently been accepted as a vfpx project.


today i've just uploaded to vfpx at codeplex a new version of foxcharts. this is version 0.14 - still alpha - not for production !


prerequisites:
visual foxpro 9 and the gdiplusx library from vfpx 


first of all i have to thank you all for your kind comments and feedback you provided in my last post. i had never expected to receive so many comments, in this blog, at the other vfp forums and by email. i really apreciated that. be sure that your feedback resulted in a superpowered motivation to improve it.


it is also important to tell everybody of the importance that both bo durban and craig boyd have in this project. they are the menthors and fathers of gdiplusx. without gdiplusx this project would become almost impossible. if i had to use any other of the gdi+ classes available for vfp, for sure it would have taken much more time - believe-me, i've tried them all.


using gdiplusx i can be indeed much more productive. once you understand how it works, things become really easy and simple.


at first sight, when i saw one of the first versions that bo and craig designed for gdiplusx i was really amazed, and i said to myself - i have to go deeper into this.


bo durban has also provided important help, providing important suggestions, support and testing. thanks also to emersonreed, luis maria guayan and leandro walfrans for your tips and support.


this version also distributes the two main files from gdiplusx - system.app and gdiplusx.vcx.
if you are already a gdiplusx user, you can use your own gdiplusx version.
just make sure to be using the latest version.


this new release contains lots of enhancements:

chart types
- bar charts
- multiple bars
- stacked bars

- pie
- doughnut

- lines
- area
- points and shapes


color variations:
- basic colors
- custom colors
- gradient colors
- random colors
- monochrome
- gradient or solid colors


legends in many places: axys, shapes, side legends

scales - automatic or customized

customize:
- titles
- subtitles
- backgrounds (solid or gradient)
- fonts
- colors


the sample form shows most of the features that are available. run the form "chartssample.scx" and play changing the various properties, generating some cool charts like the ones below.



all the relevant codes are in the init() event of the sample form. with very few lines of code you can create super cool and beautiful charts.


this sample also includes a report sample. check the codes in the command button that generates a report to see one of the various ways we have to print our charts.



 


important to remember that this is still an alpha version, and is not recommended to be used in production although it works nice.


some important improvements still need to be applied, specially in the class initialization. the codes also need to be optimized. my priority was in obtaining the results, and in many places the performance can be improved.


if you have any tips, or can provide suggestions, or fixes, you are most welcome !


enjoy !


download the latest version directly from the foxcharts page on vfpx:


http://www.codeplex.com/vfpx/wiki/view.aspx?title=foxcharts&referringtitle=home


the page for the latest release 0.14 alpha:


http://www.codeplex.com/vfpx/release/projectreleases.aspx?releaseid=12847


 



















 




 




 



 


 
  

 
 




 


here are the properties that are currently provided in foxcharts, that you can use to improve your charts:






























































































































































































sourcealiascharacter, the name of the alias that contains the needed fields that will create the chart
fieldvalue1character, the field name of the cursor that contains the numeric values that contain the values that will create the chart.
fieldcolorcharacter, the field name of the cursor that contains the rgb values of the custom colors for the chart
fielddetachslicecharacter, the field name of the cursor that contains the logical values that tell if the slice of the pie or donut chart will be detached or not
fieldhideslicecharacter, the field name of the cursor that contains the logical values that tell if the slice of the pie or donut chart will be hidden or not
fieldlegendcharacter, the field name of the cursor that contains the character values that contain the main legends of the pie or donut charts
fieldlegend2character, the field name of the cursor that contains the character values that contain the secondary legends of the chart that will be drawn inside the slice, or point or bar.
fieldxaxyscharacter, the name of the field that contains the text to be drawn in the x axys
color1numeric, the rgb value of the color from the first chart
legend1character, the legend text for the first sequence of values
charttypenumeric, type of chart: 1 = pie ; 2 = donut ; 3 = unspecified ; 4 = point ; 5 = line ;  6 = area ; 7 = simple bar ; 8 = multiple bars ; 9 = stacked bars
chartscountnumeric, the number of value sources
fontnamecharacter, the name of the font to be used to display text
titlefontsizenumeric, the font size for the main title
titlecaptioncharacter, the title caption
titleforecolornumeric, the title and subtitle forecolor rgb value
subtitlecaptioncharacter, the subtitle caption
subtitlefontsizenumeric, the subtitle font size
showlegendlogical, shows the side legends
legendfontsizenumeric, the fontsize for the side legends
legendforecolornumeric, the legend fore color rgb value
showvaluesonshapeslogical, determines if the values will be drawn inside the shapes of the chart
legendonshapecolornumeric, the rgb value for the shape color
legendonshapefontsizenumeric, the font size for legends on shape
showaxyslogical, for line, area or point charts - determines if the x and y axys will be drawn
axysxcaptioncharacter, the main text for the x axys
axysycaptioncharacter, the main text for the y axys
axyscolornumeric, the rgb value for the axys main color
backcolornumeric, rgb value of the main backcolor
backcolor2numeric, rgb value of the secondary (destination) backcolor. this is used to create gradients, together with "backcolor"
backgradientmodenumeric, if gradient background (having backcolor2 specified) - 0 - horizontal; 1 - vertical; 2 - diagonal1 ; 3 - diagonal 2
showscalelogical, determines if the scale in the y axys will be shown
scalenumeric, the scale value for the y axys; 0 = automatic scale
scalebacktypenumeric, the background scale type; 0 = none; 1 = lines; 2 = rectangle
colortypenumeric, the type of colors of the chart: 0 = basic colors   1 = custom (default)   2 = random   3 = scale of gradients
brushtypenumeric, type of brush used to fill the chart: 1 - solid colors; 2 - gradient colors; 3 - monochrome hatch brush
gradientlevelnumeric, for gradient brush mode (-10 = destination black; 0 = solid color; +10 destination white)
alphachannelnumeric, 0-255 determines the level of the transparency level; 255 = opaque; 0 = transparent
_3dnumeric, the quantity of pixels that create the 3d effect (0 = plain)
marginnumeric, specifies the margin width created in the text portion of the control.
donutrationumeric, for donut chart - the width of the donut related to its size ( 0.01 = full slice ; 0.99 = thin)
linecapslogical, for the case of plain line chart, shows rounded caps in each point.
lineshape
pointsshapenumeric, the shape to be used in a points chart: 0 = round; 1 = square; 2 = triangle; 3 = cross; 4 = star; 5 = man; 98 = gdi+x path object; 99 = custom image
pointsshapewidthnumeric, for point chart, determines the width of the pen that will draw the shapes
piedetachpixelsnumeric, for pie and donut charts, the quantity of pixels to detach from center
barsspacebetweennumeric, for bars chart - the distance in pixels between bars
area3dtoplogical, when true, a line will be drawn on the top of the 3d area chat
multichartlogical, determines if more than one kind of chart will run at the same time


 


 

2008-04-11

How to disable print button in report preview

till now i had seen many samples showing how we can make the print button invisible from the report preview toolbar, but i had never seen the possibility to show it disabled.
here's a sample, totally based in emerson reed's, from an old post in his great blog: a sample on how to add features to report listener - http://weblogs.foxite.com/emersonreed/archive/2006/09/13/a_sample_on_how_to_add_features_to_report_listener.aspx


it brings the possibility to hide completely the print button or to disable it - just set the properties "printbuttonvisible" and "printbuttonenabled". apart from this, it also allows to change the tooltips from the buttons. for my case this is really helpful, in order to have the translated tooltips to my native language.


i've only added 7 or 8 lines of code all the sample comes from emerson.
it was tricky to set the "enabled" property of the print button, because there's no property that allows us to set this, differently from the "visible", that was allowed, using the property "allowprintfrompreview".
even setting the property "enabled" directly in the extensionhandler class below, the button still appeared enabled.


.cmdprint.enabled = .f. && did not work


my solution was to use bindevent, in order to control the behavior whenever the report previewer tried to change the "enabled" property:


bindevent(this.previewform.toolbar.cmdprint,"enabled",this,"disabled",1)
 
then, i added a custom function "disabled", that forces the print button to appear disabled:
 
procedure disabled
   this
.previewform.toolbar.cmdprint.enabled = .f.
endproc

 

 
* see "leveraging the default preview container" topic in help for more info
* report listener based on emerson reed's sample from
*
http://weblogs.foxite.com/emersonreed/archive/2006/09/13/a_sample_on_how_to_add_features_to_report_listener.aspx


* create a report listener object
local loreportlistener
loreportlistener =
newobject("myreportlistener")
with loreportlistener
   .
listenertype = 1 && preview
   .printbuttonvisible = .t.
   .printbuttonenabled = .f.
endwith
 
* run a report from the samples of vfp using the new report engine (object-assisted output)
report form ;
   home() + 'samples\solution\reports\colors.frx' ;
   object loreportlistener
return
 
 
 
* custom report listener that adds some features
define class myreportlistener as fxlistener of addbs(home()) + "ffc\_reportlistener.vcx"


* public properties
printbuttonvisible = .t.
printbuttonenabled = .t.
*
procedure loadreport
   dodefault
()
   with this
      if
.listenertype==1 and not vartype(.previewcontainer)=="o"
         .extendpreviewcontainer()
      endif
   endwith
endproc
*
function extendpreviewcontainer
   local lopreviewcontainer
   lopreviewcontainer =
null
   do
(_reportpreview) with lopreviewcontainer
   lopreviewcontainer.allowprintfrompreview =
this.printbuttonvisible

   local loexthandler
   loexthandler =
createobject("myextensionhandler")
   loexthandler.disableprintbutton = not
this.printbuttonenabled

   lopreviewcontainer.setextensionhandler(loexthandler)
   this.previewcontainer = lopreviewcontainer
endfunc
enddefine



* create a class that will extend report preview
define class myextensionhandler as custom
   disableprintbutton = .f.


procedure show(istyle)
with this.previewform
   with .toolbar
   * translate toolbar buttons tooltips to brazilian portuguese language
   .cbozoom.tooltiptext = "zoom"
   .cmdclose.
tooltiptext = "fechar a visualização"
   .cmdgotopage.
tooltiptext = "ir para a página"
   .cmdprint.
tooltiptext = "imprimir"
 
   if this.disableprintbutton
      * bindevent(this.previewform.toolbar.cmdprint, "visible", this, "invisible", 1)


      * here we control the enabled property
      bindevent(this.previewform.toolbar.cmdprint, "enabled", this, "disabled", 1)
   endif

   with
.cntnext
      .cmdbottom.
tooltiptext = "última página"
      .cmdforward.
tooltiptext = "próxima página"
   endwith


   with .cntprev
      .cmdback.
tooltiptext = "página anterior"
      .cmdtop.
tooltiptext = "primeira página"
   endwith


   with .opgpagecount
      .opt1.
tooltiptext = "uma página"
      .opt2.
tooltiptext = "duas páginas"
      .opt3.
tooltiptext = "quatro páginas"
   endwith
*
   endwith
   .windowstate = 2 && maximize report preview
   endwith
   dodefault
(istyle)

endproc


* here is the relevant code to disable the button
procedure disabled
   this
.previewform.toolbar.cmdprint.enabled = .f.
endproc
*
enddefine

2008-04-04

FoxCharts !!!

wanna create some cool charts in vfp ?



with no activex controls, dlls, or 3rd party products ?



what do you think of these ?





 



 



 


recently, i’ve seen many discussions about people asking for charts components.
since gdiplusx brings us all these possibilities, i thought it would  be worth to start a project regarding this.



 


foxcharts is a subclass of the imagecanvas class from gdiplusx, that allows us to direct draw in an image object, among many other cool and useful features, that are not in the scope of this post.



goals of foxcharts:
- create good looking and modern charts in pure vfp
- no activex components
- easy to setup
- easy to customize.
- easy to save to disk or print
- open source
- benefit from all the gdiplusx drawing capabilities, allowing users to modify the charts the way they like.
- save as emf, resulting in perfect charts when printed in vfp reports



prerequisites:
visual foxpro 9 and the gdiplusx library from vfpx 



in the source code you'll find a sample form, “newchart.scx” that allows to create different kinds of charts using this class.


please note that as it is still in alpha version, the codes that create the charts are still in the sample form. gpcharts.vcx is (at this moment) just a holder that contains the pems needed to draw. in development mode, double click the imagecanvas object to see the source code that generates these charts.


the codes that will instantiate gpcharts reside in the init() event of the sample form, only there.


 


currently available:
bars, lines, area, pie and donut charts, in various color variations, using gradients, custom colors, basic and random colors.
titles, subtitles and legends


 


to do:
enhance the data filling, create a builder, allow different kinds of charts to appear together (eg. lines and bars). legends in the y and x axys.


and obviously:
fix some bugs !



if you are interested in developing and enhancing foxcharts, feel free to post a comment here.
your suggestions, tips, critics, testing and bugs hunting will be most appreciated !


 


download directly from the foxcharts page in vfpx


http://www.codeplex.com/vfpx/wiki/view.aspx?title=foxcharts&referringtitle=home