the zoombar class
from the first time i saw this class here
i liked it a lot. only problem was it was in .net and not vfp and i did not want all that overhead.
emerson reed did a good class here http://weblogs.foxite.com/emersonreed but it only had 2 states so was more of a popup button class rather than a zoom class.
so i decided to develop this from the ground up to suit my needs and with an actual zooming effect. the class i came up with was easier to program than i first thought.
the class library consists of 2 classes:
1. a zooming button class that can be used by itself and
2. a container class that holds a series of buttons that would zoom when the mouse was moved over them.
the buttons had to be able to be zoomed from the bottom up (bottom fixed) as well as to zoom from a central point. also the container had to be able to move the remaining buttons around the zoomed button.
another need was that the buttons were centrally arranged in the container whether odd or even numbers of buttons were used.
the class was to be self contained as well as have a handler for the click. of what use is a button that does nothing when you click it?
the zoom button class - zoomimage
the whole animation of zooming takes place in the mousemove of the button. this is a vfp image class.
so if the mouse is moving over the button from left to right, the button should zoom till the central point is reached and then as the mouse moves away from the centre, the button un zooms and vice versa for the opposite diretion. so find this central point, zoom till reached and then unzoom. there is also the fact that the direction the mouse is moving in, should also be stored and known else if you moved the mouse from right to left, the button would first shrink till the central point and that was undesirable.
all the original positions of the button are stored for later use here:
with this as image
.oldwidth = .width
.oldheight = .height
.oldleft = .left
.oldtop = .top
.vcenter = .oldleft+int(.oldwidth/2)
.oldbottom = .top+.height
also the button acts differently when placed on a form or in a container. so this code was put in the zoomimage.mousemove:
lparameters nbutton, nshift, nxcoord, nycoord
*is this in a container or form
if this.parent.baseclass = "form"
bb = this.zoomimage(nxcoord - this.parent.left)
all the zooming happens here in this method. the position of the mouse cursor is passed into this depending on if it is a form or container that is the parent
if cstr = "left"
inc = int(((nxcoord-.oldleft)*10)/(.oldwidth/2))+1
inc = int(((.oldleft +.oldwidth - nxcoord )*10)/(.oldwidth/2))+1
the 10 here means that the zooming is done in 10 steps depending on the original size of the button.
.zoomfactor is the amount of zoom we want. a larger number means a greater zoom.
the next bit of code zooms the button as needed depending on whether it is a “bubble” zoom of centre zoom:
if not .centerzoom
.height = .oldheight + inc
.top = .oldbottom - (.height)
.height = .oldheight + inc
.top = .hcenter - (.height/2)
finally i store the mouse position so that we can check next time to find the direction of movement: this.oldnx = nxcoord
and that is all that is needed. the class can be used on its own as below:
the zoomcontainer class
this is used as a button bar and is responsible for creating the buttons, repositioning them and maintaining that position and has the button click handler.
i have added some sample code to show how the buttons are added. important is the dodefault() since this is what initially positions the buttons and sets up the anchor of the container depending on its centerzoom property.
a user may opt for odd or even buttons so the buttons must all be centrally located. here again i get the central point of the container and the buttons are arranged around this. this method is also called in the zoomcontainer.resize so that the central location of the buttons is always maintained even if the form is resized.
above you would have seen this line
the zoomcontainer.reposition method is the one that maintains all the buttons in position.
here i get the central point of the container and the sum of widths of the buttons. one pixel is added for each button to stop overlapping them:
ntotalwidth = obutton.width*this.buttoncount + this.buttoncount
ncenter = this.width/2
nbcenter = ntotalwidth/2
nleft = ncenter - nbcenter
next the top of the button is calculated depending on the centrezoom property:
ntop = this.height/2 - obutton.height/2
ntop = this.height - (obutton.height+1)
finally i iterate through all the buttons setting theme up in position:
for n = 1 to .buttoncount
obutton = evaluate(".zoomimage"+transform(n))
with obutton as zoomimage
.left = nleft
.top = ntop
nleft = nleft+obutton.width+1
.visible = .t.
this method handles the repositioning of the other buttons around the zoomed one by getting a left and right value and setting each button so that the left position of a button is one pixel to the right of the previous button. this all works very sweetly.
for aesthetics i placed a label and image in the container which is hidden at runtime.
also i added a 3d bar to give an added perspective effect. this is just another image and is anchored to the sides of the container.
finally the handler for the buttons. you can add any code here. the name you passed is stored in the tag property of the button, and can be used to identify which button was clicked but really ny property can be used since i pass the button object to the method.
i looked at many icon sets but i really liked emerson's icons so used them in the class. however you are free to use any icons you wish. i found that simple png's like these are the best. the more complex png's suffer from the vfp flashing bug and are not recommended. bitmaps can be used instead but png's give a better effect when zoomed. just change your code to point to the icons of your choice:
.addbuttons("name of your button","your icon file here","any tooltip text")
here 3 buttons are added
with this as zoomcontainer
.addbuttons("firstbutton","explorer96.png","this is the first button")
.addbuttons("secondbutton","folder96.png", "click here for a file")
.addbuttons("thirdbutton","monitor96.png", "monitor events")
the effect is as in the naimations below depending on the centerzoom property:
the final result is as per the sample form attached in the download:
the class including source code and images can be downloaded from here.
the green vista bar (shown below) in the sample form above - you can select this image and “saveas” . it should be a bmp with a white background since png’s on png’s will cause too much flashing. it is not included in the download.
i hope you find good use for this class. if you do please drop me a line.
21/12/2007 - updated bbzoombar class is now available for download from the attachment below. note that this is only the class update. the main file is still available at foxite at the link above..
this fixes a bug where only 9 buttons could be added. now 99 buttons can be added. thanks to guille (paraguay!!!) who reported this