protected override void OnSizeChanged(int w, int h, int oldw, int oldh) { base.OnSizeChanged(w, h, oldw, oldh); // before measure, get the center of view _positionX = Measurements.GetWidth(this) / 2; _positionY = Measurements.GetHeight(this) / 2; int d = System.Math.Min(w, h); _buttonRadius = (int)(d / 2 * 0.25); _joystickRadius = (int)(d / 2 * 0.75); }
protected override void OnDraw(Canvas canvas) { // Set the center values _centerX = Measurements.GetWidth(this) / 2; _centerY = Measurements.GetHeight(this) / 2; // Unexplainable Offsets _centerX = _centerX * 1.5; _centerY = _centerY * 2; // painting the main circle canvas.DrawCircle((int)_centerX, (int)_centerY, _joystickRadius, mainCircle); // painting the secondary circle canvas.DrawCircle((int)_centerX, (int)_centerY, _joystickRadius / 2, secondaryCircle); // paint lines canvas.DrawLine((float)_centerX, (float)_centerY, (float)_centerX, (float)(_centerY - _joystickRadius), verticalLine); canvas.DrawLine((float)(_centerX - _joystickRadius), (float)_centerY, (float)(_centerX + _joystickRadius), (float)_centerY, horizontalLine); canvas.DrawLine((float)_centerX, (float)(_centerY + _joystickRadius), (float)_centerX, (float)_centerY, horizontalLine); // If this is the Initial drawing of the joystick, // then center the control button if (_isInitialDraw) { _positionX = (int)_centerX; _positionY = (int)_centerY; _isInitialDraw = false; } // painting the move button canvas.DrawCircle(_positionX, _positionY, _buttonRadius, button); }