/// <summary> /// Sync specified index slice to stage center. /// </summary> /// <param name="pIndex">Index of the slice which will be place to the stage center.</param> private void SyncSortIndex(int pIndex) { // Verify pIndex if(pIndex < 0) pIndex = 0; if(pIndex >= _dataSource.Children.Count) pIndex = _dataSource.Children.Count - 1; // Sync Page's sort arrow if (pIndex == 0) { (_target.FindName("parentCanvas") as Page).ShowBothArrow(); (_target.FindName("parentCanvas") as Page).HideLeftArrow(); } else if (pIndex == _dataSource.Children.Count - 1) { (_target.FindName("parentCanvas") as Page).ShowBothArrow(); (_target.FindName("parentCanvas") as Page).HideRightArrow(); } else { (_target.FindName("parentCanvas") as Page).ShowBothArrow(); } PhotoSlice syncSlice = _targetShadow.Children[pIndex] as PhotoSlice; ////// for (int i = 0; i < _targetShadow.Children.Count; i++) { if (pIndex == i) { (_targetShadow.Children[i] as PhotoSlice).ShowHighRes(); (_targetShadow.Children[i] as PhotoSlice).FadeIn(); } else if (Math.Abs(pIndex - i) <= CommonValues.SortBufferCount) { (_targetShadow.Children[i] as PhotoSlice).ShowHighRes(); (_targetShadow.Children[i] as PhotoSlice).FadeOut(); } else { (_targetShadow.Children[i] as PhotoSlice).ShowLowRes(); (_targetShadow.Children[i] as PhotoSlice).FadeOut(); } } Point desPoint = GetAnimationDestination(syncSlice); _isSliceRequest = true; AnimateToPosition(desPoint.X, 0); // Move navi's highlight _sortNavi.MoveHighlightFrameTo(_sortNavi.ThumHolder.Children[pIndex] as ThumSlice); _currentSortSliceIndex = pIndex; _currentSlice = _targetShadow.Children[pIndex] as PhotoSlice; }
void thumRec_OnSliceClicked(object sender, ThumClickEventArgs e) { // move highlight ThumSlice senderSlice = sender as ThumSlice; _sortNavi.MoveHighlightFrameTo(senderSlice); SyncSortIndex(e.SliceID); _currentSlice = _targetShadow.Children[e.SliceID] as PhotoSlice; }
void mySlice_MouseLeftButtonUp(object sender, MouseEventArgs e) { if (_zoomStatus == ZoomStatus.In) { if (_currentSlice == (sender as PhotoSlice)) _genuineSlice.ShowImage(_dataSource.Children[(sender as PhotoSlice).ID].Image); else _currentSlice = sender as PhotoSlice; } _isSliceRequest = true; PhotoSlice senderSlice = sender as PhotoSlice; _currentRandomSlice = senderSlice; _currentSlice = senderSlice; // Sync resolution status. _currentRandomSlice.ShowHighRes(); // Swap z-index //_target.Children.Remove(senderSlice); //_target.Children.Add(senderSlice); // Calculate des position. Point desPoint = GetAnimationDestination(senderSlice); // Active animation. (_target.FindName("parentCanvas") as Page).HideLeftArrow(); (_target.FindName("parentCanvas") as Page).HideRightArrow(); ZoomIn(); RotateToAngle(-1 * senderSlice.Rotation.Angle); AnimateToPosition(desPoint.X, desPoint.Y); }
void sortSlice_MouseLeftButtonUp(object sender, MouseEventArgs e) { if (_currentSlice == sender as PhotoSlice) { _genuineSlice.ShowImage(_dataSource.Children[(sender as PhotoSlice).ID].Image); } else { _currentSlice = sender as PhotoSlice; SyncSortIndex((sender as PhotoSlice).ID); } }
private void LayoutToRandom() { GenerateRandomPosition(); // Update slice counter _randomSliceCount = _dataSource.Children.Count; _targetShadow.Children.Clear(); _renderedSliceCount = 0; _currentScreen = 0; // Show slices. for (int i = 0; i < _dataSource.Children.Count; i++) { PhotoSlice mySlice = new PhotoSlice(this, i, _dataSource.Children[i]); mySlice.OnSliceLoaded += new EventHandler<SliceLoadedEventArgs>(mySlice_OnSliceLoaded); _targetShadow.Children.Add(mySlice); mySlice.SetValue<double>(Canvas.LeftProperty, -1000); mySlice.SetValue<double>(Canvas.TopProperty, -1000); } }
private void LayoutToSorted() { // Clear Holder _targetShadow.Children.Clear(); _renderedSliceCount = 0; // Reset _target RotateToAngle(0); AnimateToPosition(0, 0); _currentScreen = 0; MoveScreen(0); ZoomIn(); // Reset slice pointer _currentSortSliceIndex = 0; // Add all slices. for (int i = 0; i < _dataSource.Children.Count; i++) { PhotoSlice sortSlice = new PhotoSlice(this, i, _dataSource.Children[i]); sortSlice.OnSliceLoaded += new EventHandler<SliceLoadedEventArgs>(sortSlice_OnSliceLoaded); sortSlice.MouseLeftButtonUp += new MouseEventHandler(sortSlice_MouseLeftButtonUp); sortSlice.MouseEnter += new MouseEventHandler(sortSlice_MouseEnter); sortSlice.MouseLeave += new EventHandler(sortSlice_MouseLeave); _targetShadow.Children.Add(sortSlice); Point desPoint = GetSortSlicePosition(i); sortSlice.SetValue<double>(Canvas.LeftProperty, Math.Round(desPoint.X)); sortSlice.SetValue<double>(Canvas.TopProperty, Math.Round(desPoint.Y)); } _sortNavi.MoveHighlightFrameTo(_sortNavi.ThumHolder.Children[0] as ThumSlice); _currentSlice = _targetShadow.Children[0] as PhotoSlice; (_target.FindName("parentCanvas") as Page).ShowBothArrow(); (_target.FindName("parentCanvas") as Page).HideLeftArrow(); if(_dataSource.Children.Count<2) { (_target.FindName("parentCanvas") as Page).HideRightArrow(); } }
private double GetSliceOriginPosY(PhotoSlice pSlice) { return (double)(pSlice.GetValue(Canvas.TopProperty)) + pSlice.Height / 2 - _target.Height / 2 + (double)_targetShadow.GetValue(Canvas.TopProperty); ; }
private double GetSliceOriginPosX(PhotoSlice pSlice) { return (double)(pSlice.GetValue(Canvas.LeftProperty)) + pSlice.Width / 2 - _target.Width / 2 + (double)_targetShadow.GetValue(Canvas.LeftProperty); }
private Point GetAnimationDestination(PhotoSlice pSlice) { // length angle double length = Math.Sqrt(Math.Pow(GetSliceOriginPosX(pSlice), 2) + Math.Pow(GetSliceOriginPosY(pSlice), 2)); double lengthAngle = Math.Atan2(GetSliceOriginPosY(pSlice), GetSliceOriginPosX(pSlice)) * 180 / Math.PI; double totalAngle = pSlice.Rotation.Angle - lengthAngle; //double desX = -1 * GetSliceOriginPosX(senderSlice); //double desY = -1 * GetSliceOriginPosY(senderSlice); double desX = -1 * length * Math.Cos(totalAngle * Math.PI / 180); double desY = length * Math.Sin(totalAngle * Math.PI / 180); return new Point(Math.Round(desX), Math.Round(desY)); }
/* GenerateRandomPosition_bak() private void GenerateRandomPosition_bak() { double sliceWidth; double sliceHeight; double stageWidth = _target.Width; double stageHeight = _target.Height - _btnRandom.Height; PhotoSlice measureSlice = new PhotoSlice(this, -1, new PhotoItem()); sliceWidth = measureSlice.Width; sliceHeight = measureSlice.Height; // Generate position grid. _randomPositionSet = new Collection<Point>(); // Get grid matirix. int itemCount = _dataSource.Children.Count; // each grid's size should be... double gridWidth = BrowserHost.ActualWidth / _cols; double gridHeight = (BrowserHost.ActualHeight - _btnRandom.Height - 30) / _rows; // Calculate zoomout scale. double scaleX = gridWidth / sliceWidth * CommonValues.FreespaceRatio; double scaleY = gridHeight / sliceHeight * CommonValues.FreespaceRatio; _zoomoutScale = Math.Min(scaleX, scaleY); if (_zoomoutScale > CommonValues.ZoomOutScale) _zoomoutScale = CommonValues.ZoomOutScale; for (int i = 0; i < itemCount; i++) { double xpos = (gridWidth / 2 + gridWidth * _axisSet[i].X) / _zoomoutScale - (BrowserHost.ActualWidth) / _zoomoutScale / 2 + sliceWidth / 2; double ypos = (gridHeight / 2 + gridHeight * _axisSet[i].Y) / _zoomoutScale - (BrowserHost.ActualHeight - _btnRandom.Height - 30) / _zoomoutScale / 2; _randomPositionSet.Add(new Point(xpos, ypos)); } } */ private void GenerateRandomPosition() { double sliceWidth; double sliceHeight; double stageWidth = BrowserHost.ActualWidth; ; double stageHeight = BrowserHost.ActualHeight - _btnRandom.Height; _targetShadow.Width = _target.Width; _targetShadow.Height = _target.Height; PhotoSlice measureSlice = new PhotoSlice(this, -1, new PhotoItem()); sliceWidth = measureSlice.Width; sliceHeight = measureSlice.Height; // Generate position grid. _randomPositionSet.Clear(); // each grid's size should be... double gridWidth = stageWidth / _cols; double gridHeight = stageHeight / _rows; // Calculate zoomout scale. double scaleX = gridWidth / sliceWidth * CommonValues.FreespaceRatio; double scaleY = gridHeight / sliceHeight * CommonValues.FreespaceRatio; _zoomoutScale = Math.Min(scaleX, scaleY); if (_zoomoutScale > CommonValues.ZoomOutScale) _zoomoutScale = CommonValues.ZoomOutScale; #region generate random positions. _totalScreens = _dataSource.Children.Count / (CommonValues.FixCols * CommonValues.FixRows); if ((_dataSource.Children.Count % (CommonValues.FixCols * CommonValues.FixRows)) > 0) _totalScreens += 1; for (int itemFlag = 0; itemFlag < _dataSource.Children.Count; itemFlag++) { int screenCount = itemFlag / (CommonValues.FixCols * CommonValues.FixRows); int screenIndex = itemFlag % (CommonValues.FixCols * CommonValues.FixRows); int rowFlag = screenIndex / CommonValues.FixCols; int colFlag = screenIndex % CommonValues.FixCols; Debug.WriteLine("slice - " + itemFlag); Debug.WriteLine("screen #" + screenCount + " / " + rowFlag + " / " + colFlag); double xpos = (gridWidth / 2 + gridWidth * colFlag) / _zoomoutScale - stageWidth / _zoomoutScale / 2 + sliceWidth / 2 + screenCount * stageWidth / _zoomoutScale; double ypos = (gridHeight / 2 + gridHeight * rowFlag) / _zoomoutScale - stageHeight / _zoomoutScale / 2; Debug.WriteLine(xpos + " / " + ypos); _randomPositionSet.Add(new Point(xpos, ypos)); } #endregion }
/// <summary> /// Generate random & sort layout positions and param(zoomscale, etc.). /// </summary> private void GenerateLayoutPostion() { double sliceWidth; double sliceHeight; double stageWidth = _target.Width; _targetShadow.Width = _target.Width; _targetShadow.Height = _target.Height; double stageHeight = _target.Height - _btnRandom.Height; PhotoSlice measureSlice = new PhotoSlice(this, -1, new PhotoItem()); sliceWidth = _sliceWidth = measureSlice.Width; sliceHeight = measureSlice.Height; // Generate position grid. _randomPositionSet = new Collection<Point>(); // Get grid matirix. _rows = CommonValues.FixRows; _cols = CommonValues.FixCols; // each grid's size should be... double gridWidth = stageWidth / _cols; double gridHeight = stageHeight / _rows; // Calculate zoomout scale. double scaleX = gridWidth / sliceWidth * CommonValues.FreespaceRatio; double scaleY = gridHeight / sliceHeight * CommonValues.FreespaceRatio; _zoomoutScale = Math.Min(scaleX, scaleY); if (_zoomoutScale > CommonValues.ZoomOutScale) _zoomoutScale = CommonValues.ZoomOutScale; #region generate random positions. _totalScreens = _dataSource.Children.Count / (CommonValues.FixCols * CommonValues.FixRows); if ((_dataSource.Children.Count % (CommonValues.FixCols * CommonValues.FixRows)) > 0) _totalScreens += 1; for (int itemFlag = 0; itemFlag < _dataSource.Children.Count; itemFlag++) { int screenCount = itemFlag / (CommonValues.FixCols * CommonValues.FixRows); int screenIndex = itemFlag % (CommonValues.FixCols * CommonValues.FixRows); int rowFlag = screenIndex / CommonValues.FixCols; int colFlag = screenIndex % CommonValues.FixCols; Debug.WriteLine("slice - " + itemFlag); Debug.WriteLine("screen #" + screenCount + " / " + rowFlag + " / " + colFlag ); double xpos = (gridWidth / 2 + gridWidth * colFlag) / _zoomoutScale - stageWidth / _zoomoutScale / 2 + sliceWidth / 2 + screenCount * stageWidth; double ypos = (gridHeight / 2 + gridHeight * rowFlag) / _zoomoutScale - stageHeight / _zoomoutScale / 2; _randomPositionSet.Add(new Point(xpos, ypos)); } #endregion #region calculate sort params. // reset stage's size. stageWidth = _target.Width; stageHeight = _target.Height - _btnRandom.Height; _sortCenterPosition = new Point((stageWidth - sliceWidth) / 2, (stageHeight - sliceHeight) / 2 + 50); _sortBufferCount = 0; while ((sliceWidth * _sortBufferCount + CommonValues.SortedMargin * (_sortBufferCount - 1)) < stageWidth) { _sortBufferCount++; } if (_sortBufferCount < 5) _sortBufferCount = 5; // at least 3 buffers. _currentSortSliceIndex = 0; // initialize this value. #endregion }