Created
August 12, 2023 12:42
-
-
Save nanjizal/fecce517a2cdaad3806e768ac09fb87b to your computer and use it in GitHub Desktop.
old bigben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package samples.examples.big_ben.views; | |
import divtastic.js.DisplayDiv; | |
import divtastic.js.Divtastic; | |
import divtastic.js.Drawing; | |
import divtastic.js.application.views.WindowView; | |
using divtastic.js.Drawing; | |
using samples.examples.big_ben.views.BigBenView; | |
class BigBenView | |
{ | |
private var _holder: DisplayDiv; | |
private var _win: WindowView; | |
//These need to be Divtastic's to allow rotation | |
private var _hourHand: Divtastic; | |
private var _minHand: Divtastic; | |
private var _secHand: Divtastic; | |
//private var _sec: Int; | |
private var _min: Int; | |
private var _hour: Int; | |
private var origTitle: String; | |
public function new( holder_: DisplayDiv, win_: WindowView ) | |
{ | |
_holder = holder_; | |
_win = win_; | |
var dGap = 10; | |
var hGap = Std.int( WindowView.headerHeight + dGap ); | |
var w = Std.int( _holder.width - dGap*2 ); | |
var h = Std.int( _holder.height - hGap - dGap ); | |
/* | |
_holder.drawGradElipse ( Std.int( dGap ) | |
, hGap | |
, w | |
, h | |
, 0xebe9eb | |
, 0xf7e9f2 | |
, 1 | |
, 'vertical' | |
); | |
*/ | |
var clockFace = new DisplayDiv( 'assets/bigben.png' ); | |
clockFace.x = dGap; | |
clockFace.y = hGap; | |
clockFace.width = 517; | |
clockFace.height = 517; | |
_holder.addChild( clockFace ); | |
var cx = dGap + w/2; | |
var cy = hGap + h/2; | |
origTitle = _win.title; | |
_hourHand = new Divtastic(); | |
_hourHand.x = cx - 38/2; | |
_hourHand.y = cy - 92/2; | |
_hourHand.drawHand( 38, 164, 92, 'assets/shortHand.png' ); | |
_holder.addChild( _hourHand ); | |
_minHand = new Divtastic(); | |
_minHand.x = cx - 35/2; | |
_minHand.y = cy - 98/2; | |
_minHand.drawHand( 35, 296, 98, 'assets/bigHand.png' ); | |
_holder.addChild( _minHand ); | |
var timer = new haxe.Timer(1000); | |
timer.run = updateRotation; | |
updateRotation(); | |
} | |
public function updateRotation() | |
{ | |
var currTime = Date.now(); | |
var min = currTime.getMinutes(); | |
var hour = currTime.getHours(); | |
//_sec = currTime.getSeconds(); | |
if( hour != _hour ) | |
{ | |
_hourHand.rotation = (360/12)*hour%12 ; | |
} | |
if( min != _min ) | |
{ | |
_minHand.rotation = (360/60)*min ; | |
} | |
//testHand.rotation = 2*(360/60)*_sec ; | |
_min = min; | |
_hour = hour; | |
_win.title = origTitle + ' - ' + _hour + ':' + _min ; | |
} | |
//use | |
private static function drawHand( scope: Divtastic, width: Int, length: Int, dy: Int, img: String ) | |
{ | |
var inside = new DisplayDiv( img ); | |
inside.x = 0; | |
inside.y = -length + dy; | |
inside.width = width; | |
inside.height = length; | |
scope.addChild( inside ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment