Exemplo n.º 1
0
        private static void checkChange()
        {
            Windows.Foundation.Rect frame = BarcodeHelper.MWBgetScanningRect(0);
            int orientation = BarcodeLib.Scanner.MWBgetDirection();

            if (orientation != lastOrientation || frame.Left != lastLeft || frame.Top != lastTop || frame.Width != lastWidth || frame.Height != lastHeight)
            {
                updateOverlay();
            }

            if (lastBLinkingSpeed != blinkingSpeed)
            {
                removeAnimation();
                addAnimation();
            }

            if (isBlinkingLineVisible != (lineLayer.Visibility == System.Windows.Visibility.Visible))
            {
                updateOverlay();
            }

            if (isViewportVisible != (viewportLayer.Visibility == System.Windows.Visibility.Visible))
            {
                updateOverlay();
            }

            lastOrientation   = orientation;
            lastLeft          = (float)frame.Left;
            lastTop           = (float)frame.Top;
            lastWidth         = (float)frame.Width;
            lastHeight        = (float)frame.Height;
            lastBLinkingSpeed = blinkingSpeed;
        }
Exemplo n.º 2
0
        private static void updateOverlay()
        {
            Windows.Foundation.Rect unionRect = BarcodeHelper.MWBgetScanningRect(0);
            int orientation = BarcodeLib.Scanner.MWBgetDirection();

            int width  = (int)currentCanvas.ActualWidth;
            int height = (int)currentCanvas.ActualHeight;

            if (width <= 0 || height == 0)
            {
                DispatcherTimer updateDelayed = new DispatcherTimer();
                updateDelayed.Interval = TimeSpan.FromSeconds(0.2);
                updateDelayed.Tick    += delegate
                {
                    updateOverlay();
                    updateDelayed.Stop();
                };
                updateDelayed.Start();
                return;
            }



            int rectLeft   = (int)((float)unionRect.Left * width / 100.0);
            int rectTop    = (int)((float)unionRect.Top * height / 100.0);
            int rectWidth  = (int)((float)unionRect.Width * width / 100.0);
            int rectHeight = (int)((float)unionRect.Height * height / 100.0);
            int rectRight  = (int)((float)unionRect.Right * width / 100.0);
            int rectBottom = (int)((float)unionRect.Bottom * height / 100.0);

            if (isViewportVisible)
            {
                viewportLayer.Visibility = System.Windows.Visibility.Visible;

                var bitmapviewport = new WriteableBitmap(width, height);
                bitmapviewport.FillRectangle(0, 0, width, height, colorFromAlphaAndInt(viewportAlpha, 0));

                int lineWidth2 = (int)(viewportLineWidth / 2.0);

                bitmapviewport.FillRectangle(rectLeft - lineWidth2, rectTop - lineWidth2, rectRight + lineWidth2, rectBottom + lineWidth2, colorFromAlphaAndInt(viewportLineAlpha, viewportLineColor));

                bitmapviewport.FillRectangle(rectLeft, rectTop, rectRight, rectBottom, System.Windows.Media.Color.FromArgb(0, 0, 0, 0));



                viewportLayer.Source = bitmapviewport;
            }
            else
            {
                viewportLayer.Visibility = System.Windows.Visibility.Collapsed;
            }


            if (isBlinkingLineVisible)
            {
                lineLayer.Visibility = System.Windows.Visibility.Visible;

                addAnimation();

                if (width < height)
                {
                    double pos1f = Math.Log(BarcodeLib.Scanner.MWB_SCANDIRECTION_HORIZONTAL) / Math.Log(2);
                    double pos2f = Math.Log(BarcodeLib.Scanner.MWB_SCANDIRECTION_VERTICAL) / Math.Log(2);

                    int pos1 = (int)(pos1f + 0.01);
                    int pos2 = (int)(pos2f + 0.01);

                    int bit1 = (orientation >> pos1) & 1; // bit at pos1
                    int bit2 = (orientation >> pos2) & 1; // bit at pos2
                    int mask = (bit2 << pos1) | (bit1 << pos2);
                    orientation = orientation & 0xc;
                    orientation = orientation | mask;
                }



                var bitmapLine = new WriteableBitmap(width, height);
                int lineWidth2 = (int)(blinkingLineWidth / 2.0);

                if (((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_HORIZONTAL) > 0) || ((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_OMNI) > 0))
                {
                    bitmapLine.FillRectangle(rectLeft, rectTop + rectHeight / 2 - lineWidth2, rectRight, rectTop + rectHeight / 2 + lineWidth2, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                }

                if (((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_VERTICAL) > 0) || ((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_OMNI) > 0))
                {
                    bitmapLine.FillRectangle(rectLeft + rectWidth / 2 - lineWidth2, rectTop, rectLeft + rectWidth / 2 + lineWidth2, rectBottom, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                }

                if ((orientation & BarcodeLib.Scanner.MWB_SCANDIRECTION_OMNI) > 0)
                {
                    bitmapLine.DrawLine(rectLeft, rectTop, rectRight, rectBottom, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                    bitmapLine.DrawLine(rectLeft, rectBottom, rectRight, rectTop, colorFromAlphaAndInt(blinkingLineAlpha, blinkingLineColor));
                }

                lineLayer.Source = bitmapLine;
            }
            else
            {
                lineLayer.Visibility = System.Windows.Visibility.Collapsed;
                removeAnimation();
            }
        }