From: Richard K. <ric...@us...> - 2005-05-17 02:37:43
|
Update of /cvsroot/actionstep/actionstep/src/org/actionstep In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12406 Added Files: ASAnimatedTabView.as Log Message: added sliding animated tab view --- NEW FILE: ASAnimatedTabView.as --- /* * Copyright (c) 2005, InfoEther, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1) Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2) Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3) The name InfoEther, Inc. may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import org.actionstep.NSTabView; import org.actionstep.NSView; import org.actionstep.NSRect; import org.actionstep.NSTimer; import org.actionstep.NSTabViewItem; import org.actionstep.constants.NSTabState; class org.actionstep.ASAnimatedTabView extends NSTabView { public function selectTabViewItem(item:NSTabViewItem) { if (m_delegate != null) { if(typeof(m_delegate["tabViewShouldSelectTabViewItem"]) == "function") { if (!m_delegate["tabViewShouldSelectTabViewItem"].call(m_delegate, this, item)) { return; } } } _removeOldItem(item); } private function _removeOldItem(item:NSTabViewItem) { if (m_selected != null) { m_selected.setTabState(NSTabState.NSBackgroundTab); setNeedsDisplay(true); NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats( .1, this, "_animateOldItem", { item:item, point:m_selected.view().frame().origin.clone(), width:m_selected.view().frame().size.width, speed:50, }, true); } else { _addNewItem(item); } } private function _animateOldItem(timer:NSTimer) { var context = timer.userInfo(); context.point.x -= context.speed; context.speed+=20; if ((-context.point.x) > context.width) { m_selected.view().removeFromSuperview(); timer.invalidate(); _addNewItem(timer.userInfo().item); } else { m_selected.view().setFrameOrigin(context.point); updateAfterEvent(); } } private function _addNewItem(item:NSTabViewItem) { m_selected = item; if (m_selected != null) { m_selectedItem = m_items.indexOfObject(m_selected); m_selected.setTabState(NSTabState.NSSelectedTab); if(typeof(m_delegate["tabViewWillSelectTabViewItem"]) == "function") { m_delegate["tabViewWillSelectTabViewItem"].call(m_delegate, this, m_selected); } var selectedView:NSView = m_selected.view(); if (selectedView != null) { addSubview(selectedView); m_window.makeFirstResponder(m_selected.initialFirstResponder()); var rect:NSRect = contentRect(); rect.origin.x -= rect.size.width; selectedView.setFrame(rect); setNeedsDisplay(true); selectedView.window().displayIfNeeded(); NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats( .1, this, "_animateNewItem", { point:rect.origin, targetX:(rect.origin.x+rect.size.width), speed:140, }, true); } else { _finish(); } } else { m_selectedItem = -1; _finish(); } } private function _animateNewItem(timer:NSTimer) { var context = timer.userInfo(); context.point.x += context.speed; context.speed-=20; if (context.point.x > context.targetX) { context.point.x = context.targetX; m_selected.view().setFrameOrigin(context.point); timer.invalidate(); _finish(); } else { m_selected.view().setFrameOrigin(context.point); updateAfterEvent(); } } private function _finish() { setNeedsDisplay(true); if(typeof(m_delegate["tabViewDidSelectTabViewItem"]) == "function") { m_delegate["tabViewDidSelectTabViewItem"].call(m_delegate, this, m_selected); } } } |