SunsetHigh.ListPanel.onMoveCursor C# (CSharp) Method

onMoveCursor() public method

public onMoveCursor ( Direction dir ) : void
dir Direction
return void
        public override void onMoveCursor(Direction dir)
        {
            if (this.entries.Count == 0)
                return;

            int oldCursor = this.cursor;

            if (dir.Equals(Direction.North))
            {
                if (this.rowFirst)
                {
                    this.cursor -= this.cols;
                    if (this.cursor < 0) this.cursor += this.rows * this.cols;
                    while (this.cursor >= this.entries.Count) this.cursor -= this.cols;
                }
                else
                {
                    this.cursor -= 1;
                    if ((this.cursor + 1) % this.rows == 0) this.cursor += this.rows;
                    while (this.cursor >= this.entries.Count) this.cursor -= 1;
                }
            }
            if (dir.Equals(Direction.East))
            {
                if (this.rowFirst)
                {
                    this.cursor += 1;
                    if (this.cursor >= this.entries.Count) this.cursor = (this.rows - 1) * this.cols;
                    //else if (this.cursor % this.cols == 0) this.cursor -= this.cols;
                }
                else
                {
                    this.cursor += this.rows;
                    if (this.cursor >= this.rows * this.cols) this.cursor %= (this.rows * this.cols);
                    else if (this.cursor >= this.entries.Count) this.cursor %= this.rows;
                }
            }
            if (dir.Equals(Direction.South))
            {
                if (this.rowFirst)
                {
                    this.cursor += this.cols;
                    if (this.cursor >= this.rows * this.cols) this.cursor %= (this.rows * this.cols);
                    else if (this.cursor >= this.entries.Count) this.cursor %= this.cols;
                }
                else
                {
                    this.cursor += 1;
                    if (this.cursor >= this.entries.Count) this.cursor = (this.cols - 1) * this.rows;
                    else if (this.cursor % this.rows == 0) this.cursor -= this.rows;
                }
            }
            if (dir.Equals(Direction.West))
            {
                if (this.rowFirst)
                {
                    this.cursor -= 1;
                    if (this.cursor < 0) this.cursor += this.cols;
                    //if ((this.cursor + 1) % this.cols == 0) this.cursor += this.cols;
                    //while (this.cursor >= this.entries.Count) this.cursor -= 1;
                }
                else
                {
                    this.cursor -= this.rows;
                    if (this.cursor < 0) this.cursor += this.rows * this.cols;
                    while (this.cursor >= this.entries.Count) this.cursor -= this.rows;
                }
            }

            if (this.isScrolling())
            {
                if (this.cursor >= (this.scrollTopRow + this.scrollRowsOnPanel) * this.cols
                    || this.cursor < this.scrollTopRow * this.cols)
                {
                    int oldScrollCurrentRow = this.scrollTopRow;
                    int newScrollCurrentRow = this.cursor / this.cols;
                    if (newScrollCurrentRow > oldScrollCurrentRow)
                    {
                        if (newScrollCurrentRow - (this.scrollRowsOnPanel - 1) >= 0)
                            this.scrollTopRow = newScrollCurrentRow - (this.scrollRowsOnPanel - 1);
                        else
                            this.scrollTopRow = 0;
                    }
                    else
                        this.scrollTopRow = newScrollCurrentRow;

                    this.scrollBar.adjustY(this.scrollTopRow, this.rows);
                    foreach (MenuEntry entry in this.entries)
                    {
                        entry.setY(entry.getY() - (this.scrollTopRow - oldScrollCurrentRow) * scrollOffsetBetweenEntries);
                    }
                }
            }

            if (this.cursor != oldCursor)
            {
                this.entries[oldCursor].onUnhover();
                this.entries[this.cursor].onHover();
            }
        }