Skip to content

Commit

Permalink
add zoom functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kutu committed Jul 20, 2013
1 parent 69857ea commit e8a4efe
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ru/kutu/grindplayer/events/PlayerVideoZoomEvent.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.kutu.grindplayer.events {

import flash.events.Event;

public class PlayerVideoZoomEvent extends Event {

public static const ZOOM_IN:String = "playerVideoZoom.in";
public static const ZOOM_OUT:String = "playerVideoZoom.out";
public static const ZOOM_RESET:String = "playerVideoZoom.reset";

public function PlayerVideoZoomEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
}

override public function clone():Event {
return new PlayerVideoZoomEvent(type, bubbles, cancelable);
}

override public function toString():String {
return formatToString("PlayerVideoZoomEvent", "type", "bubbles", "cancelable", "eventPhase");
}

}

}
44 changes: 44 additions & 0 deletions src/ru/kutu/grindplayer/views/mediators/PlayerViewMediator.as
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package ru.kutu.grindplayer.views.mediators {

import ru.kutu.grind.views.mediators.PlayerViewBaseMediator;
import ru.kutu.grindplayer.config.GrindPlayerConfiguration;
import ru.kutu.grindplayer.events.PlayerVideoZoomEvent;
import ru.kutu.osmf.advertisement.AdvertisementPluginInfo;
import ru.kutu.osmf.subtitles.SubtitlesPluginInfo;

Expand All @@ -23,6 +24,8 @@ package ru.kutu.grindplayer.views.mediators {

public class PlayerViewMediator extends PlayerViewBaseMediator {

private var _zoom:int;

override protected function processConfiguration(flashvars:Object):void {
CONFIG::DEV {
flashvars.src = "";
Expand Down Expand Up @@ -70,6 +73,47 @@ package ru.kutu.grindplayer.views.mediators {
}
}

override protected function initializeView():void {
super.initializeView();

addContextListener(PlayerVideoZoomEvent.ZOOM_IN, onZoom, PlayerVideoZoomEvent);
addContextListener(PlayerVideoZoomEvent.ZOOM_OUT, onZoom, PlayerVideoZoomEvent);
addContextListener(PlayerVideoZoomEvent.ZOOM_RESET, onZoom, PlayerVideoZoomEvent);
}

override protected function onViewResize(event:Event = null):void {
if (mediaContainer) {
const w:Number = view.mediaPlayerContainer.width;
const h:Number = view.mediaPlayerContainer.height;
videoContainer.width = w * (100 + _zoom) / 100;
videoContainer.height = h * (100 + _zoom) / 100;
videoContainer.validateNow();
videoContainer.x = (w - videoContainer.width) / 2;
videoContainer.y = (h - videoContainer.height) / 2;
mediaContainer.width = w;
mediaContainer.height = h;
hitArea.graphics.clear();
hitArea.graphics.beginFill(0);
hitArea.graphics.drawRect(0, 0, w, h);
}
}

private function get zoom():int { return _zoom }
private function set zoom(value:int):void {
if (value < -90) value = -90;
if (value == _zoom) return;
_zoom = value;
onViewResize();
}

private function onZoom(event:PlayerVideoZoomEvent):void {
switch (event.type) {
case PlayerVideoZoomEvent.ZOOM_IN: zoom++; break;
case PlayerVideoZoomEvent.ZOOM_OUT: zoom--; break;
case PlayerVideoZoomEvent.ZOOM_RESET: zoom = 0; break;
}
}

private function onFullScreen(event:FullScreenEvent = null):void {
view.controlBarAutoHide = contextView.view.stage.displayState == StageDisplayState.NORMAL
? configuration.controlBarAutoHide
Expand Down
25 changes: 25 additions & 0 deletions src/ru/kutu/grindplayer/views/mediators/ShortcutsMediator.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ package ru.kutu.grindplayer.views.mediators {

import ru.kutu.grind.events.StatInfoEvent;
import ru.kutu.grind.views.mediators.ShortcutsBaseMediator;
import ru.kutu.grindplayer.events.PlayerVideoZoomEvent;

public class ShortcutsMediator extends ShortcutsBaseMediator {

override protected function onKeyDown(event:KeyboardEvent):void {
super.onKeyDown(event);

switch (event.keyCode) {
// zoom in
case Keyboard.EQUAL:
case Keyboard.NUMPAD_ADD:
dispatch(new PlayerVideoZoomEvent(PlayerVideoZoomEvent.ZOOM_IN));
break;

// zoom out
case Keyboard.MINUS:
case Keyboard.NUMPAD_SUBTRACT:
dispatch(new PlayerVideoZoomEvent(PlayerVideoZoomEvent.ZOOM_OUT));
break;
}
}

override protected function onKeyUp(event:KeyboardEvent):void {
super.onKeyUp(event);

Expand All @@ -27,6 +46,12 @@ package ru.kutu.grindplayer.views.mediators {
case Keyboard.T:
dispatch(new StatInfoEvent(StatInfoEvent.TOGGLE));
break;

// zoom reset
case Keyboard.NUMBER_0:
case Keyboard.NUMPAD_0:
dispatch(new PlayerVideoZoomEvent(PlayerVideoZoomEvent.ZOOM_RESET));
break;
}
}

Expand Down

0 comments on commit e8a4efe

Please sign in to comment.