Esempio n. 1
0
        /// <summary>
        /// Repaints cursor on the screen.
        /// </summary>
        ///
        internal void RepaintCursor(Screen screen)
        {
            if (screen == null)
            {
                return;
            }

            // When RepaintCurosr() is called for root window of the screen
            // (having no parent), we need to setup a default cursor (which is an
            // invisible cursor at position ( 0, 0 ).
            //
            if (Parent == null)
            {
                screen.SetCursorPosition(0, 0);
                screen.CursorVisible = false;
            }

            ClipContext clipContext = new ClipContext(screen, Left, Top);

            clipContext.Clip(ClientWidth, ClientHeight);

            if (children.Count > 0)
            {
                ActiveChild.RepaintCursor(screen);
            }
            else
            {
                if (CursorVisible && screen.IsVisible(CursorLeft, CursorTop))
                {
                    screen.SetCursorPosition(
                        screen.Offset.X + CursorLeft, screen.Offset.Y + CursorTop);
                    screen.CursorVisible = true;
                }
            }

            clipContext.Restore();
        }
Esempio n. 2
0
        /////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Repaints window contents on the screen.
        /// </summary>
        ///
        internal bool Repaint(Screen screen, bool parentHasFocus = true)
        {
            if (screen == null)   // FIXME: screen null OR INVISIBLE
            {
                return(false);
            }

            if (!Visible)
            {
                Invalidated = false;
                return(false);
            }

            bool hasFocus = Parent == null || /* root window always has focus */
                            (parentHasFocus && Parent.ActiveChild == this);

            if (Invalidated)
            {
                OnCalculateSize(hasFocus);
            }

            // Setup clipping region and drawing offset
            //
            ClipContext clipContext = new ClipContext(screen, Left, Top);

            clipContext.Clip(ClientWidth, ClientHeight);

            bool repainted  = false;
            bool drawBorder = false;

            if (Invalidated)
            {
                // Setup default cursor position and drawing colors first, then
                // erase background and draw contents
                //
                screen.SetCursorPosition(0, 0);

                if (hasFocus)
                {
                    screen.BackColor = BackColor;
                    screen.ForeColor = ForeColor;
                }
                else
                {
                    screen.BackColor = BackColorInact;
                    screen.ForeColor = ForeColorInact;
                }

                ColorContext savedColor = new ColorContext(screen);

                OnEraseBackground(screen);

                savedColor.Restore();

                OnDrawContents(screen, hasFocus);

                savedColor.Restore();

                drawBorder  = true;
                repainted   = true;
                Invalidated = false;
            }

            // Repaint children.
            // Algorithm: At the beginning, 'repainted' flag is usually false.
            // First child, which returns that it has repainted itself, turns-on
            // 'repainted' flag further on so the all consecutive siblings are
            // invalidated (and repainted).
            //
            foreach (Window subWindow in children)
            {
                if (repainted)
                {
                    subWindow.Invalidate();  // Force child to be Repaint()-ed
                }

                if (subWindow.Repaint(screen, hasFocus))
                {
                    repainted = true;
                }
            }

            // Draw window edges (with parent's offset but without clipping!)
            //
            if (drawBorder)
            {
                clipContext.RestoreClipRegion();

                if (hasFocus)
                {
                    screen.BackColor = BorderBackColor;
                    screen.ForeColor = BorderForeColor;
                }
                else
                {
                    screen.BackColor = BorderBackColorInact;
                    screen.ForeColor = BorderForeColorInact;
                }

                OnDrawBorder(screen, hasFocus);
            }

            // Restore clipping region and drawing offset
            //
            clipContext.Restore();

            return(repainted);
        }