PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/HelloRubberBandCtrl/src/com/google/maps/extras/rubberbandctrl/CrosshairCursor.as

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 108 lines | 57 code | 18 blank | 33 comment | 1 complexity | 5923263ac99559cddd3f76abd06c1eac MD5 | raw file
  1package com.google.maps.extras.rubberbandctrl
  2{
  3
  4import flash.display.DisplayObjectContainer;
  5import flash.events.MouseEvent;
  6import flash.geom.Point;
  7import flash.ui.Mouse;
  8import flash.display.Shape;
  9
 10/**
 11 * A cursor that shows a "crosshair" pattern. Used by RubberBandCtrl.
 12 * <p>
 13 * <strong>Notes:</strong>&#xA0;
 14 * <ul>
 15 * <li>This class is not required for Flash 10, which includes support for alternate cursors.</li>
 16 * </ul>
 17 * </p>
 18 * <p>
 19 * <strong>Contacts:</strong>
 20 * <ul>
 21 * <li>To contact the author of CrosshairCursor, email kevin.macdonald AT thinkwrap DOT com</li>
 22 * <li>Visit <code>http://www.spatialdatabox.com</code> for other Google Flash Map demos and related information.</li>
 23 * <li>For updates to CrosshairCursor, please visit <code>http://code.google.com/p/gmaps-utility-library-flash</code></li>
 24 * </ul>
 25 * </p>
 26 *
 27 * <p>
 28 * <strong>Copyright Notice:</strong><br>
 29 * <br>
 30 * Copyright 2009 Kevin Macdonald<br>
 31 * <br>
 32 * Licensed 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<br>
 33 * <br>
 34 *     http://www.apache.org/licenses/LICENSE-2.0<br>
 35 * <br>
 36 * 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.<br>
 37 * </p>
 38 */
 39internal class CrosshairCursor
 40{
 41
 42function CrosshairCursor (displayObject:DisplayObjectContainer)
 43{
 44	displayObject.addChild (cursor);
 45	hide ();
 46}
 47
 48internal function show (p:Point):void
 49{
 50	if (! cursor.visible) {
 51		Mouse.hide ();
 52		cursor.visible = true;
 53	}
 54	cursor.x = p.x + X_OFFSET_PX - 1;
 55	cursor.y = p.y + Y_OFFSET_PX - 1;
 56}
 57
 58
 59internal function hide ():void
 60{
 61	cursor.visible = false;
 62	Mouse.show ();
 63}
 64
 65internal function isVisible ():Boolean
 66{
 67	return cursor.visible;
 68}
 69
 70private static function drawCrosshairs ():Shape
 71{
 72	const s:Shape = new Shape ();
 73
 74	//	Draw a thick white crosshair
 75	s.graphics.lineStyle (BACKGROUND_THICKNESS_PX, BACKGROUND_COLOR);
 76	s.graphics.moveTo (SIZE_PX / 2, 0);
 77	s.graphics.lineTo (SIZE_PX / 2, SIZE_PX);
 78	s.graphics.moveTo (0, SIZE_PX / 2);
 79	s.graphics.lineTo (SIZE_PX, SIZE_PX / 2);
 80
 81	//	Draw a thin black crosshair in the middle of the thick white crosshair.
 82	s.graphics.lineStyle (FOREGROUND_THICKNESS_PX, FOREGROUND_COLOR);
 83	s.graphics.moveTo (SIZE_PX / 2, 0);
 84	s.graphics.lineTo (SIZE_PX / 2, SIZE_PX);
 85	s.graphics.moveTo (0, SIZE_PX / 2);
 86	s.graphics.lineTo (SIZE_PX, SIZE_PX / 2);
 87
 88	return s;
 89}
 90
 91private static const BACKGROUND_COLOR:uint = 0xffffff;
 92private static const BACKGROUND_THICKNESS_PX:uint = 3;
 93
 94private static const FOREGROUND_COLOR:uint = 0x000000;
 95private static const FOREGROUND_THICKNESS_PX:uint = 1;
 96
 97//	Width & height of crosshair cursor. Must be an odd number.
 98private static const SIZE_PX:int = 15;
 99
100//	Offset of cursor origin (ie. upper-left-edge) from its center.
101private static const X_OFFSET_PX:int = -SIZE_PX / 2;
102private static const Y_OFFSET_PX:int = -SIZE_PX / 2;
103
104private static const cursor:Shape = drawCrosshairs ();
105
106}
107
108}