Exemple #1
0
        public void InitVals()
        {
            _nStepSize  = 20;
            _nAngle     = -90;
            _nAngleStep = 90;
            _fPenDown   = true;
            _nInput     = 0;
            SetColor(0x0);
            var rect = new NativeMethods.WinRect();

            NativeMethods.GetClientRect(_hwnd, ref rect);
            _position = new Point((rect.Right - rect.Left) / 2,
                                  (rect.Bottom - rect.Top) / 2);
        }
        void DrawPoint(int ptindx, IntPtr hclr)
        {
            Point point = _pts[ptindx];
            var   rect  = new NativeMethods.WinRect(
                (int)point.X,
                (int)point.Y,
                (int)(point.X + 3),
                (int)(point.Y + 3)
                );

            NativeMethods.FillRect(_hdc, ref rect, hclr);
            //if (point.X != 0 && point.Y != 0)
            //{
            //    NativeMethods.SelectObject(_hdc, hclr);
            //    NativeMethods.MoveToEx(_hdc, (int)point.X, (int)point.Y, ref _prevPos);
            //    var nxt = GetNextIndex(_ptIndex);
            //    var nextPoint = _pts[nxt];
            //    NativeMethods.LineTo(_hdc, (int)nextPoint.X, (int)nextPoint.Y);
            //}
        }
        void InitCachedImagesOfAnimals()
        {
            if (_hdcCached != IntPtr.Zero)
            {
                NativeMethods.DeleteDC(_hdcCached);
            }
            _hdcCached = NativeMethods.CreateCompatibleDC(_hdc);
            var hBitmap = NativeMethods.CreateCompatibleBitmap(_hdc,
                                                               nTotRows * CellWidth,
                                                               nTotCols * CellHeight);

            NativeMethods.SelectObject(_hdcCached, hBitmap);
            IntPtr br;
            var    rect = new NativeMethods.WinRect();

            for (int i = 0; i < 255; i++) // for each age
            {
                rect.Left   = i * _CellWidth;
                rect.Right  = rect.Left + _CellWidth;
                rect.Top    = 0;
                rect.Bottom = _CellHeight;
                br          = NativeMethods.CreateSolidBrush(new IntPtr(0xff00 - i * 0x100));
                NativeMethods.FillRect(_hdcCached, ref rect, br);
                NativeMethods.DeleteObject(br);
                br          = NativeMethods.CreateSolidBrush(new IntPtr(0xff - i));
                rect.Top    = _CellHeight;
                rect.Bottom = rect.Top + _CellHeight;
                NativeMethods.FillRect(_hdcCached, ref rect, br);
                NativeMethods.DeleteObject(br);
            }
            // now draw an empty cell
            rect.Top   += _CellHeight;
            rect.Bottom = rect.Top + _CellHeight;
            rect.Left   = 0;
            rect.Right  = _CellWidth;
            br          = NativeMethods.CreateSolidBrush(new IntPtr(0xffffff));
            NativeMethods.FillRect(_hdcCached, ref rect, br);
            NativeMethods.DeleteObject(br);
            NativeMethods.DeleteObject(hBitmap);
        }
Exemple #4
0
 public void Draw()
 {
     if (_fShowTurtle)
     {
         IntPtr hdc = NativeMethods.GetDC(_hwnd);
         NativeMethods.SelectObject(hdc, _colorTurtle);
         var cosT = Math.Cos((90 + _nAngle) * piOver180); // cos(Theta)
         var sinT = Math.Sin((90 + _nAngle) * piOver180); // sin(Theta)
         NativeMethods.SetROP2(hdc, NativeMethods.RasterOps.R2_NOTXORPEN);
         NativeMethods.MoveToEx(hdc, (int)_position.X, (int)_position.Y, ref _prevPos);
         for (int i = 0; i < _turtle.Length / 2; i++)
         {
             var x1 = _nTurtleSize * _turtle[i, 0];
             var y1 = _nTurtleSize * _turtle[i, 1];
             NativeMethods.LineTo(
                 hdc,
                 (int)(_position.X + x1 * cosT + y1 * sinT),
                 (int)(_position.Y + x1 * sinT - y1 * cosT)
                 );
         }
         // now the other half of the turtle
         NativeMethods.MoveToEx(hdc, (int)_position.X, (int)_position.Y, ref _prevPos);
         for (int i = 0; i < _turtle.Length / 2; i++)
         {
             var x1 = -_nTurtleSize * _turtle[i, 0];
             var y1 = -_nTurtleSize * _turtle[i, 1];
             NativeMethods.LineTo(
                 hdc,
                 (int)(_position.X + x1 * cosT - y1 * sinT),
                 (int)(_position.Y + x1 * sinT + y1 * cosT)
                 );
         }
         var rect = new NativeMethods.WinRect();
         NativeMethods.GetClientRect(_hwnd, ref rect);
         NativeMethods.ValidateRect(_hwnd, ref rect);
         NativeMethods.SetROP2(hdc, NativeMethods.RasterOps.R2_COPYPEN);
         NativeMethods.ReleaseDC(_hwnd, hdc);
     }
 }