/// <summary>
        /// Initializes a new instance of the <see cref="Paint.ToolBox"/> class.
        /// </summary>
        /// <param name='toolboxLayoutDefinition' The layout of the toolbox />
        /// <param name='graphicsDisplay' The graphics texture map - contains images for buttons and controls />
        /// <param name='scale' iPad size scale - i.e.2 for retina and 1 for normal - allows us to multiply up the layout />
        public ToolBox(ToolboxLayoutDefinition toolboxLayoutDefinition, IGraphicsDisplay graphicsDisplay, int scale)
        {
            this.BackgroundColor = this.TranslateToolboxLayoutColor(toolboxLayoutDefinition.BackgroundColor);
            this.BorderColor = this.TranslateToolboxLayoutColor(toolboxLayoutDefinition.Border.Color);
            this.GraphicsDisplay = graphicsDisplay;
            this.Scale = scale;
            this.toolboxWidth = toolboxLayoutDefinition.Width * scale;
            this.ToolboxMinimizedHeight = toolboxLayoutDefinition.MinimizedHeight * scale;
            this.toolboxMaximisedHeight = toolboxLayoutDefinition.MaximizedHeight * scale;

            int toolboxBorderWidth = toolboxLayoutDefinition.Border.Width * scale;

            // we start maximised and docked at the bottom
            this.ToolboxHeight = toolboxLayoutDefinition.MaximizedHeight * scale;
            this.DockPosition = DockPosition.Bottom;

            this.toolboxBounds = new Rectangle(0, 0, this.toolboxWidth, this.ToolboxHeight);

            this.toolbarInnerBounds = new Rectangle(
                toolboxBorderWidth,
                toolboxBorderWidth,
                this.toolboxWidth - (2 * toolboxBorderWidth),
                this.ToolboxMinimizedHeight - (2 * toolboxBorderWidth));

            this.interactiveTools = new List<IToolBoxToolTouch>();
            this.nonInteractiveTools = new List<IToolBoxTool>();

            // Add all the buttons
            this.AddStandardTools(toolboxLayoutDefinition.StandardTools);
        }
Пример #2
0
        private async Task StartDisplayAsync()
        {
            // Create the display
            var disp = new ST7735()
            {
                ChipSelectLine = 0,
                ClockFrequency = 40000000, // Attempt to run at 40 MHz
                ControllerName = "SPI0",
                DataCommandPin = gpioController.OpenPin(12),
                DisplayType    = ST7735DisplayType.RRed,
                ResetPin       = gpioController.OpenPin(16),

                Orientation = DisplayOrientations.Landscape,
                Width       = 160,
                Height      = 128,
            };

            // Initialize the display
            await disp.InitializeAsync();

            // Store for future using generic interface
            display = disp;

            // Add to device list
            devices.Add(display);

            // Update the display faster than the default of 1 second
            GraphicsPanel.UpdateInterval = 500;

            // Associate with display panel
            GraphicsPanel.Display = display;

            // Start updates
            GraphicsPanel.AutoUpdate = true;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Paint.Gauge"/> class.
 /// </summary>
 /// <param name='backgroundColor' The background color of the gauge />
 /// <param name='graphicsDisplay' Contains all the graphics for rendering the tools />
 /// <param name='bounds' The bounds of this control/tool />
 /// <param name='markerWidth' The size of the marked (the bit the user drags) />
 /// <param name='gaugeColor' The color of the gauge />
 /// <param name='startMarker' The starting position/value of the marker />
 public Gauge(Color backgroundColor, IGraphicsDisplay graphicsDisplay, Rectangle bounds, int markerWidth, Color gaugeColor, float startMarker)
     : base(backgroundColor, graphicsDisplay, bounds)
 {
     this.CurrentMarker = this.PreviousMarker = startMarker;
     this.GaugeColor = gaugeColor;
     this.MarkerWidth = markerWidth;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Paint.BrushSizeSelector"/> class.
        /// </summary>
        /// <param name='graphicsDisplay'>
        /// Graphics display.
        /// </param>
        /// <param name='brushSizeDefinition'>
        /// Brush size definition - layout of the control.
        /// </param>
        public BrushSizeSelector(IGraphicsDisplay graphicsDisplay, BrushSizeSelectorDefinition brushSizeDefinition)
            : base(brushSizeDefinition.BackgroundColor,
				brushSizeDefinition.BorderColor,
				brushSizeDefinition.BorderWidth,
				graphicsDisplay,
				brushSizeDefinition.Bounds)
        {
            this.brushSizeDefinition = brushSizeDefinition;

            this.color = brushSizeDefinition.StartColor;
            this.BrushSize = brushSizeDefinition.BrushSizeInitial;
            this.gaugeYPosition = Bounds.Y + brushSizeDefinition.GaugeVerticalMargin + this.brushSizeDefinition.BrushSizeMaximum;

            Rectangle gaugeBounds = new Rectangle(
                this.Bounds.X + ((this.Bounds.Width - this.brushSizeDefinition.GaugeWidth) / 2),
                this.gaugeYPosition,
                this.brushSizeDefinition.GaugeWidth,
                this.Bounds.Height - (this.brushSizeDefinition.BrushSizeMaximum + (this.brushSizeDefinition.GaugeVerticalMargin * 2)));

            float startMarkerValue =
                (float)(this.brushSizeDefinition.BrushSizeInitial - this.brushSizeDefinition.BrushSizeMinimum) /
                (float)(this.brushSizeDefinition.BrushSizeMaximum - this.brushSizeDefinition.BrushSizeMinimum);

            this.brushSizeGauge =
                new VerticalGauge(
                    this.BackgroundColor,
                    graphicsDisplay,
                    gaugeBounds,
                    this.brushSizeDefinition.GaugeMarkerWidth,
                    this.brushSizeDefinition.BorderColor,
                    startMarkerValue);

            this.brushSizeGauge.MarkerChanged += brushSizeGauge_MarkerChanged;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Paint.ColorPicker"/> class.
        /// </summary>
        /// <param name='graphicsDisplay' Contains all the graphics for rendering the tools />
        /// <param name='colorPickerDefinition' The layout definition of this control/tool />
        public ColorPicker(IGraphicsDisplay graphicsDisplay, ColorPickerDefinition colorPickerDefinition)
            : base(colorPickerDefinition.BackgroundColor, 
		       colorPickerDefinition.BorderColor, 
		       colorPickerDefinition.BorderWidth, 
		       graphicsDisplay, 
		       colorPickerDefinition.Bounds)
        {
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Paint.CanvasToolTouchBase"/> class.
 /// </summary>
 /// <param name='backgroundColor' The background color of this tool />
 /// <param name='borderColor' The border color of this tool />
 /// <param name='borderWidth' The border width of this tool />
 /// <param name='graphicsDisplay' Contains all the images for the application />
 /// <param name='bounds' The bounds of this control/tool />
 public ToolBoxToolTouchBase(Color backgroundColor, Color borderColor, int borderWidth, IGraphicsDisplay graphicsDisplay, Rectangle bounds)
 {
     this.Bounds = bounds;
     this.graphicsDisplay = graphicsDisplay;
     this.BackgroundColor = backgroundColor;
     this.BorderColor = borderColor;
     this.BorderWidth = borderWidth;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Paint.SpeedGauge"/> class.
        /// </summary>
        /// <param name='graphicsDisplay'>raphics display.</param>
        /// <param name='speedGaugeDefinition'>Speed gauge definition.</param>
        public SpeedGauge(IGraphicsDisplay graphicsDisplay, SpeedGaugeDefinition speedGaugeDefinition)
            : base(speedGaugeDefinition.BackgroundColor, 
				speedGaugeDefinition.BorderColor, 
				speedGaugeDefinition.BorderWidth, 
				graphicsDisplay, 
				speedGaugeDefinition.Bounds)
        {
            this.speedGaugeDefinition = speedGaugeDefinition;

            this.CreateGauge(graphicsDisplay);
            this.CreateGraphicsRectangles(graphicsDisplay);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Paint.ColorSelector"/> class.
        /// </summary>
        /// <param name='graphicsDisplay'>
        /// Graphics display.
        /// </param>
        /// <param name='colorSelectorDefinition'>
        /// Color selector definition - layout of the color selector
        /// </param>
        public ColorSelector(IGraphicsDisplay graphicsDisplay, ColorSelectorDefinition colorSelectorDefinition)
            : base(colorSelectorDefinition.BackgroundColor, 
				colorSelectorDefinition.BorderColor, 
				colorSelectorDefinition.BorderWidth, 
				graphicsDisplay, 
				colorSelectorDefinition.Bounds)
        {
            this.colorSelectorDefinition = colorSelectorDefinition;

            // Create all our gauge sub-controls
            List<Gauge> gauges = new List<Gauge>();

            Color[] colorList = new Color[] { Color.Red, Color.Lime, Color.Blue, Color.DarkBlue };

            byte[] markerValueList = new byte[]
            {
                this.colorSelectorDefinition.StartColor.R,
                this.colorSelectorDefinition.StartColor.G,
                this.colorSelectorDefinition.StartColor.B,
                this.colorSelectorDefinition.StartColor.A
            };

            for (int i = 0; i < colorList.Length; i++)
            {
                Rectangle gaugeRectangle = new Rectangle(
                    this.Bounds.X + this.colorSelectorDefinition.GaugeHorizontalMargin,
                    this.Bounds.Y + this.Bounds.Height - ((GaugeCount - i) * (this.colorSelectorDefinition.GaugeWidth + this.colorSelectorDefinition.GaugeVerticalMargin)),
                    this.Bounds.Width - this.colorSelectorDefinition.GaugeHorizontalMargin * 2,
                    this.colorSelectorDefinition.GaugeWidth);

                gauges.Add(
                    new HorizontalGauge(
                        this.colorSelectorDefinition.BackgroundColor,
                        graphicsDisplay,
                        gaugeRectangle,
                        this.colorSelectorDefinition.GaugeMarkerWidth,
                        colorList[i],
                        markerValueList[i] / 255.0f));
            }

            this.gaugeList = gauges.ToArray();
            this.color = this.colorSelectorDefinition.StartColor;
            this.HookGaugeEvents();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Paint.PlaybackProgressBar"/> class.
        /// </summary>
        /// <param name='graphicsDisplay' Contains all the graphics for rendering the tools />
        /// <param name='colorSetterDefinition' The layout of the progress bar />
        public PlaybackProgressBar(IGraphicsDisplay graphicsDisplay, PlaybackProgressBarDefinition playbackProgressBarDefinition)
        {
            this.graphicsDisplay = graphicsDisplay;
            this.playbackProgressBarDefinition = playbackProgressBarDefinition;
            this.Bounds = this.playbackProgressBarDefinition.Bounds;

            var graphicsRectangleProgressBarLeft = this.graphicsDisplay.SourceRectangleFromImageType(ImageType.ProgressBarLeft);
            var graphicsRectangleProgressBarRight = this.graphicsDisplay.SourceRectangleFromImageType(ImageType.ProgressBarRight);

            var yDiff = this.playbackProgressBarDefinition.Bounds.Height - graphicsRectangleProgressBarLeft.Height;

            this.boundsLeftImage = new Rectangle(
                this.playbackProgressBarDefinition.Bounds.X,
                this.playbackProgressBarDefinition.Bounds.Y + yDiff / 2,
                graphicsRectangleProgressBarLeft.Width,
                this.playbackProgressBarDefinition.Bounds.Height - yDiff);

            this.boundsRightImage = new Rectangle(
                this.playbackProgressBarDefinition.Bounds.X + (this.playbackProgressBarDefinition.Bounds.Width - graphicsRectangleProgressBarRight.Width),
                this.playbackProgressBarDefinition.Bounds.Y + yDiff / 2,
                graphicsRectangleProgressBarRight.Width,
                this.playbackProgressBarDefinition.Bounds.Height - yDiff);

            this.boundsMiddleImage = new Rectangle(
                this.playbackProgressBarDefinition.Bounds.X + this.boundsLeftImage.Width,
                this.playbackProgressBarDefinition.Bounds.Y + yDiff / 2,
                this.playbackProgressBarDefinition.Bounds.Width - (graphicsRectangleProgressBarRight.Width + graphicsRectangleProgressBarLeft.Width),
                this.playbackProgressBarDefinition.Bounds.Height - yDiff);

            var indicatorXOffset = (this.playbackProgressBarDefinition.Bounds.Width - this.playbackProgressBarDefinition.ProgresIndicatorWidth) / 2;
            var indicatorYOffset = (this.playbackProgressBarDefinition.Bounds.Height - this.playbackProgressBarDefinition.ProgressIndicatorHeight) / 2;

            this.boundsProgressIndicator = new Rectangle(
                this.playbackProgressBarDefinition.Bounds.X + indicatorXOffset,
                this.playbackProgressBarDefinition.Bounds.Y + indicatorYOffset,
                this.playbackProgressBarDefinition.ProgresIndicatorWidth,
                this.playbackProgressBarDefinition.ProgressIndicatorHeight);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Paint.PlaybackToolbox"/> class.
 /// </summary>
 /// <param name='toolboxLayoutDefinition' The layout of the toolbox />
 /// <param name='graphicsDisplay' The graphics texture map - contains images for buttons and controls />
 /// <param name='scale' iPad size scale - i.e.2 for retina and 1 for normal - allows us to multiply up the layout />
 public PlaybackToolbox(ToolboxLayoutDefinition toolboxLayoutDefinition, IGraphicsDisplay graphicsDisplay, int scale)
     : base(toolboxLayoutDefinition, graphicsDisplay, scale)
 {
     this.CreateTools(toolboxLayoutDefinition);
 }
        /// <summary>
        /// Creates the gauge.
        /// </summary>
        /// <param name='graphicsDisplay'>Graphics display.</param>
        private void CreateGauge(IGraphicsDisplay graphicsDisplay)
        {
            this.gaugeBounds = new Rectangle(
                this.Bounds.X + this.speedGaugeDefinition.GaugeHorizontalMargin,
                this.Bounds.Y + this.speedGaugeDefinition.GaugeVerticalMargin,
                this.speedGaugeDefinition.GaugeWidth,
                this.speedGaugeDefinition.GaugeMarkerWidth * 3);

            this.gauge = new HorizontalGauge(
                this.speedGaugeDefinition.BackgroundColor,
                graphicsDisplay,
                this.gaugeBounds,
                this.speedGaugeDefinition.GaugeMarkerWidth,
                this.speedGaugeDefinition.BorderColor,
                0.5f);

            this.gauge.MarkerChanged += (sender, e) =>
            {
                this.OnSpeedChanged(EventArgs.Empty);
            };
        }
Пример #12
0
        private async Task StartDisplayAsync()
        {
            // Create the display
            var disp = new ST7735()
            {
                ChipSelectLine = 0,
                ClockFrequency = 40000000, // Attempt to run at 40 MHz
                ControllerName = "SPI0",
                DataCommandPin = gpioController.OpenPin(12),
                DisplayType = ST7735DisplayType.RRed,
                ResetPin = gpioController.OpenPin(16),

                Orientation = DisplayOrientations.Landscape,
                Width = 160,
                Height = 128,
            };

            // Initialize the display
            await disp.InitializeAsync();

            // Store for future using generic interface
            display = disp;

            // Add to device list
            devices.Add(display);

            // Update the display faster than the default of 1 second
            GraphicsPanel.UpdateInterval = 500;

            // Associate with display panel
            GraphicsPanel.Display = display;

            // Start updates
            GraphicsPanel.AutoUpdate = true;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Paint.Canvas"/> class.
 /// </summary>
 /// <param name='graphicsDisplay' Contains all the graphics for rendering - including the 'paint brush' (empty square) />
 public Canvas(IGraphicsDisplay graphicsDisplay)
 {
     this.graphicsDisplay = graphicsDisplay;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Paint.HorizontalGauge"/> class.
 /// </summary>
 /// <param name='backgroundColor' The background color of the gauge />
 /// <param name='graphicsDisplay' Contains all the graphics for rendering the tools />
 /// <param name='bounds' The bounds of this control/tool />
 /// <param name='markerWidth' The size of the marked (the bit the user drags) />
 /// <param name='gaugeColor' The color of the gauge />
 /// <param name='startMarker' The starting position/value of the marker />
 public HorizontalGauge(Color backgroundColor, IGraphicsDisplay graphicsDisplay, Rectangle bounds, int markerWidth, Color gaugeColor, float startMarker)
     : base(backgroundColor, graphicsDisplay, bounds, markerWidth, gaugeColor, startMarker)
 {
     this.gaugeRectangle = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 3), bounds.Width, bounds.Height / 3);
 }
        /// <summary>
        /// We load any content we need at the beginning of the application life cycle.
        /// Also anything that needs initialising is done here
        /// </summary>
        protected override void LoadContent()
        {
            this.SpriteBatch = new SpriteBatch (GraphicsDeviceManager.GraphicsDevice);

            // determine if we are a retina or not -
            // if so then we'll need to double (scale = 2) our layout locations/sizes
            // and load a bigger spritemap
            bool highResolution = this.DeviceScale  > 1;

            Texture2D graphicsTextureMap = null;
            if (highResolution)
            {
                graphicsTextureMap = Content.Load<Texture2D>("*****@*****.**");
            }
            else
            {
                graphicsTextureMap = Content.Load<Texture2D>("graphics.png");
            }

            this.GraphicsDisplay = new GraphicsDisplay(graphicsTextureMap, this.SpriteBatch, highResolution);

            this.Canvas = new Canvas(this.GraphicsDisplay);

            this.ToolBox = CreateToolbox();

            this.CreateRenderTargets();
        }
 public MicroGraphicsEx(IGraphicsDisplay display) : base(display)
 {
     this.display = display;
 }
        /// <summary>
        /// Creates the rectangles for the background graphics/icons on the gauge
        /// </summary>
        /// <param name='graphicsDisplay'>Graphics display.</param>
        private void CreateGraphicsRectangles(IGraphicsDisplay graphicsDisplay)
        {
            var graphicsRectangleProgressBarLeft = graphicsDisplay.SourceRectangleFromImageType(ImageType.SlowIcon);
            var graphicsRectangleProgressBarRight = graphicsDisplay.SourceRectangleFromImageType(ImageType.SpeedIcon);

            var yDiff = this.speedGaugeDefinition.Bounds.Height - graphicsRectangleProgressBarLeft.Height;

            this.boundsLeftImage = new Rectangle(
                this.speedGaugeDefinition.Bounds.X,
                this.speedGaugeDefinition.Bounds.Y + yDiff / 2,
                graphicsRectangleProgressBarLeft.Width,
                this.speedGaugeDefinition.Bounds.Height - yDiff);

            this.boundsRightImage = new Rectangle(
                this.speedGaugeDefinition.Bounds.X + (this.speedGaugeDefinition.Bounds.Width - graphicsRectangleProgressBarRight.Width),
                this.speedGaugeDefinition.Bounds.Y + yDiff / 2,
                graphicsRectangleProgressBarRight.Width,
                this.speedGaugeDefinition.Bounds.Height - yDiff);

            this.boundsMiddleImage = new Rectangle(
                this.speedGaugeDefinition.Bounds.X + this.boundsLeftImage.Width,
                this.speedGaugeDefinition.Bounds.Y + yDiff / 2,
                this.speedGaugeDefinition.Bounds.Width - (graphicsRectangleProgressBarRight.Width + graphicsRectangleProgressBarLeft.Width),
                this.speedGaugeDefinition.Bounds.Height - yDiff);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Paint.ColorSetter"/> class.
 /// </summary>
 /// <param name='graphicsDisplay' Contains all the graphics for rendering the tools />
 /// <param name='colorSetterDefinition' The layout of the color setter />
 public ColorSetter(IGraphicsDisplay graphicsDisplay, ColorSetterDefinition colorSetterDefinition)
 {
     this.graphicsDisplay = graphicsDisplay;
     this.colorSetterDefinition = colorSetterDefinition;
     this.previousColor = this.color = colorSetterDefinition.BackgroundColor;
 }