HomeController.js 5.64 KB
'use strict';

AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout",
    function ($rootScope, Modules, $log, $location, $timeout) {

        //$scope.pageToOpen = {
        //    name: 'MainMenu'
        //};
        $rootScope.pageToOpen = 'app/widget/MainMenu.html';
        $rootScope.currentBodyViewId;
        $rootScope.currentActiveModuleTitle = 'Welcome to A.D.A.M. Interactive Anatomy';//Modules[0].Name;
        $rootScope.currentActiveViewTitle;
        $rootScope.cuurentActiveModuleId;
        $rootScope.openModules = [];
        $rootScope.openViews = [];
        $rootScope.currentSlug;
        $rootScope.jsPanelTitle;
        $rootScope.ViewTitle;
        $rootScope.isLoading = false;
        $rootScope.isAnnotationWindowOpen = false;
        $rootScope.isDrawingToolSelected = false;
        $rootScope.isIdetifyClicked = true;
        $rootScope.paint = false;
        $rootScope.clickX = new Array();
        $rootScope.clickY = new Array();
        $rootScope.clickDrag = new Array();
        $rootScope.isLineDrawSelecyed = false;
        $rootScope.isAnnotationWindowClose = false;
        $rootScope.lastX;
        $rootScope.lastY;



        $rootScope.ClearIframe = function () {
            if ($('#daImagePanel') != null)
                $('#daImagePanel').remove();

            $rootScope.hideScrollbar();
        }

        $rootScope.hideScrollbar = function () {
            $(".sidebar").mCustomScrollbar({
                autoHideScrollbar: true,
                //theme:"rounded"
            });
        }

        //annotation tool custom events
        $rootScope.ShowAnnotationWindow = function () {
           $rootScope.isAnnotationWindowOpen = true;
           $(".annotationTollbar").css("display", "block");
           $rootScope.$broadcast('annotationToolEvent',true);

        }

        $rootScope.CloseAnnotationTool = function () {
            console.log('close')
            $(".annotationTollbar").css("visibility", "hidden");
            $rootScope.isAnnotationWindowClose = true;
        }

        $rootScope.OnIdentifyClick = function () {
            $rootScope.isIdetifyClicked = true;
            $rootScope.isDrawingToolSelected = false;
        }

        //draw line on canvas
        $rootScope.DrawLine = function () {
            $rootScope.isIdetifyClicked = false;
            $rootScope.isDrawingToolSelected = true;
            $rootScope.isLineDrawSelecyed = true;

        }

       

        $rootScope.AddClick=function (x, y, dragging) {
            $rootScope.clickX.push(x);
            $rootScope.clickY.push(y);
            $rootScope.clickDrag.push(dragging);
        }

        $rootScope.Redraw = function () {
            var context = document.getElementById('paintCanvas').getContext('2d');

            context.clearRect(0, 0, context.canvas.width, context.canvas.height); // Clears the canvas

            context.strokeStyle = "#FFFFFF";
            context.lineJoin = "round";
            context.lineWidth = 5;

          
            for (var i = 0; i < $rootScope.clickX.length; i++) {
                context.beginPath();
                if ($rootScope.clickDrag[i] && i) {
                    context.moveTo($rootScope.clickX[i - 1], $rootScope.clickY[i - 1]);
                } else {
                    context.moveTo($rootScope.clickX[i] - 1, $rootScope.clickY[i]);
                }
                context.lineTo($rootScope.clickX[i], $rootScope.clickY[i]);
                context.closePath();
                context.stroke();
            }
        }

        $rootScope.PaintCanvasMousedownListener = function (canvasContext,x,y) {
            if ($rootScope.isLineDrawSelecyed == true) {

                canvasContext.lineWidth = 0.1;
                //$scope.paintCanvasContext.lineJoin = 'round';
                //$scope.paintCanvasContext.lineCap = 'round';
                canvasContext.strokeStyle = 'red';


                canvasContext.beginPath();

                //var canvasOffset = $("#myCanvas").offset();
                //var offsetX = canvasOffset.left;
                //var offsetY = canvasOffset.top;
                canvasContext.moveTo(x, y);
            }

        }
        
        $rootScope.PaintCanvasMouseupListener = function (canvasContext) {
            if ($scope.isLineDrawSelecyed == true) {

            }
        }

        $rootScope.PaintCanvasMousemoveListener = function (canvasContext,x,y) {
            if ($rootScope.isLineDrawSelecyed == true) {
                console.log('hm moving')
                canvasContext.lineTo(x, y);
                canvasContext.stroke();
            }
        }

        $rootScope.Draw = function (x, y, isDown,context) {
            if (isDown) {
                context.beginPath();
                context.strokeStyle = '#000000';
                context.lineWidth = 1//$('#selWidth').val();
                context.lineJoin = "round";
                context.moveTo($rootScope.lastX, $rootScope.lastY);
                context.lineTo(x, y);
                context.closePath();
                context.stroke();
            }
            $rootScope.lastX = x; $rootScope.lastY = y;
        }

        $rootScope.EraseDrawing = function () {
          document.getElementById('paintCanvas').getContext('2d').setTransform(1, 0, 0, 1, 0, 0);
          document.getElementById('paintCanvas').getContext('2d').clearRect(0, 0, document.getElementById('paintCanvas').getContext('2d').canvas.width, document.getElementById('paintCanvas').getContext('2d').canvas.height);

        }


    }]
);