flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/2] git commit: [flex-asjs] [refs/heads/develop] - Button w/o text that uses CSS
Date Thu, 08 Aug 2013 17:31:55 GMT
Updated Branches:
  refs/heads/develop 69ecc0777 -> 55cd7ee06


Button w/o text that uses CSS


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/44b65a10
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/44b65a10
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/44b65a10

Branch: refs/heads/develop
Commit: 44b65a1034f0d2358647e313430f6e9fd22a26b1
Parents: 69ecc07
Author: Alex Harui <aharui@apache.org>
Authored: Thu Aug 8 10:31:17 2013 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Aug 8 10:31:43 2013 -0700

----------------------------------------------------------------------
 .../html/staticControls/beads/CSSButtonView.as  | 128 +++++++++++++++++++
 1 file changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/44b65a10/frameworks/as/src/org/apache/flex/html/staticControls/beads/CSSButtonView.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/CSSButtonView.as
b/frameworks/as/src/org/apache/flex/html/staticControls/beads/CSSButtonView.as
new file mode 100644
index 0000000..f7dc60a
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/CSSButtonView.as
@@ -0,0 +1,128 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.html.staticControls.beads
+{
+	import flash.display.Loader;
+	import flash.display.Shape;
+	import flash.display.SimpleButton;
+	import flash.display.Sprite;
+	import flash.events.Event;
+	import flash.net.URLRequest;
+	
+	import org.apache.flex.core.IBeadView;
+    import org.apache.flex.core.CSSTextField;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.ITextModel;
+	import org.apache.flex.core.ValuesManager;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.utils.SolidBorderUtil;
+
+	public class CSSButtonView implements IBeadView
+	{
+		public function CSSButtonView()
+		{
+			upSprite = new Sprite();
+			downSprite = new Sprite();
+			overSprite = new Sprite();
+		}
+		
+		private var textModel:ITextModel;
+		
+		private var _strand:IStrand;
+		
+		private var shape:Shape;
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			shape = new Shape();
+			shape.graphics.beginFill(0xCCCCCC);
+			shape.graphics.drawRect(0, 0, 10, 10);
+			shape.graphics.endFill();
+			SimpleButton(value).upState = upSprite;
+			SimpleButton(value).downState = downSprite;
+			SimpleButton(value).overState = overSprite;
+			SimpleButton(value).hitTestState = shape;
+
+            setupBackground(overSprite, "hover");
+            setupBackground(downSprite, "active");
+            setupBackground(upSprite);
+		}
+	
+		private function setupSkin(sprite:Sprite, state:String = null):void
+		{
+			var borderColor:uint;
+			var borderThickness:uint;
+			var borderStyle:String;
+			var borderStyles:Object = ValuesManager.valuesImpl.getValue(_strand, "border", state);
+			if (borderStyles is Array)
+			{
+				borderColor = borderStyles[2];
+				borderStyle = borderStyles[1];
+				borderThickness = borderStyles[0];
+			}
+			var value:Object = ValuesManager.valuesImpl.getValue(_strand, "border-style", state);
+			if (value != null)
+				borderStyle = value as String;
+			value = ValuesManager.valuesImpl.getValue(_strand, "border-color", state);
+			if (value != null)
+				borderColor = value as uint;
+			value = ValuesManager.valuesImpl.getValue(_strand, "border-thickness", state);
+			if (value != null)
+				borderThickness = value as uint;
+			var padding:Object = ValuesManager.valuesImpl.getValue(_strand, "padding", state);
+			var backgroundColor:Object = ValuesManager.valuesImpl.getValue(_strand, "background-color",
state);
+			if (borderStyle == "solid")
+			{
+				SolidBorderUtil.drawBorder(sprite.graphics, 
+					0, 0, sprite.width + Number(padding) * 2, sprite.height + Number(padding) * 2,
+					borderColor, backgroundColor, borderThickness);
+			}			
+		}
+		
+        private function setupBackground(sprite:Sprite, state:String = null):void
+        {
+            var backgroundImage:Object = ValuesManager.valuesImpl.getValue(_strand, "background-image",
state);
+            if (backgroundImage)
+            {
+                var loader:Loader = new Loader();
+                sprite.addChildAt(loader, 0);
+                var url:String = backgroundImage as String;
+                loader.load(new URLRequest(url));
+                loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function
(e:flash.events.Event):void { 
+                    setupSkin(sprite, state);
+                    updateHitArea();
+                });
+            }
+        }
+        
+		private var upSprite:Sprite;
+		private var downSprite:Sprite;
+		private var overSprite:Sprite;
+				
+		private function updateHitArea():void
+		{
+			shape.graphics.clear();
+			shape.graphics.beginFill(0xCCCCCC);
+			shape.graphics.drawRect(0, 0, upSprite.width, upSprite.height);
+			shape.graphics.endFill();
+			
+		}
+	}
+}
\ No newline at end of file


Mime
View raw message