鱼眼菜单功能
鱼眼菜单功能:
void FishEyeMenu_MouseMove(object sender, MouseEventArgs e)
{
for(int i = 0 ; i < _images.Count; i++){
Image image = _images[i];
// compute the scale of each image according to the mouse position
double imageScale = MAX_SCALE - Math.Min(MAX_SCALE - 1, Math.Abs(e.GetPosition(this).X - ((double) image.GetValue(Canvas.LeftProperty) + image.Width / 2)) / MULTIPLIER);
// resize the image
resizeImage(image, IMAGE_WIDTH * imageScale, IMAGE_HEIGHT * imageScale, i, IMAGES.Length);
// sort the children according to the scale
image.SetValue(Canvas.ZIndexProperty, (int) Math.Round(IMAGE_WIDTH * imageScale));
}
}
for(int i = 0 ; i < _images.Count; i++){
Image image = _images[i];
// compute the scale of each image according to the mouse position
double imageScale = MAX_SCALE - Math.Min(MAX_SCALE - 1, Math.Abs(e.GetPosition(this).X - ((double) image.GetValue(Canvas.LeftProperty) + image.Width / 2)) / MULTIPLIER);
// resize the image
resizeImage(image, IMAGE_WIDTH * imageScale, IMAGE_HEIGHT * imageScale, i, IMAGES.Length);
// sort the children according to the scale
image.SetValue(Canvas.ZIndexProperty, (int) Math.Round(IMAGE_WIDTH * imageScale));
}
}
代码
// resize the image
private void resizeImage(Image image, double imageWidth, double imageHeight, int index, int total){
image.Width = imageWidth;
image.Height = imageHeight;
image.SetValue(Canvas.TopProperty, Height / 2 - image.Height / 2);
double width = Width / 2 + (index - (total - 1) / 2) * (MARGIN + IMAGE_WIDTH) - image.Width / 2 +100;
image.SetValue(Canvas.LeftProperty, width);
}
private void resizeImage(Image image, double imageWidth, double imageHeight, int index, int total){
image.Width = imageWidth;
image.Height = imageHeight;
image.SetValue(Canvas.TopProperty, Height / 2 - image.Height / 2);
double width = Width / 2 + (index - (total - 1) / 2) * (MARGIN + IMAGE_WIDTH) - image.Width / 2 +100;
image.SetValue(Canvas.LeftProperty, width);
}