Improved console scrolling.
parent
eca8f06c84
commit
9cc7f01549
|
@ -17,6 +17,12 @@
|
|||
using namespace std;
|
||||
|
||||
|
||||
static int pmod(int n, int m)
|
||||
{
|
||||
return n >= 0 ? n % m : m - (-(n + 1) % m) - 1;
|
||||
}
|
||||
|
||||
|
||||
Console::Console(int _nRows, int _nColumns) :
|
||||
ostream(&sbuf),
|
||||
text(NULL),
|
||||
|
@ -25,8 +31,9 @@ Console::Console(int _nRows, int _nColumns) :
|
|||
row(0),
|
||||
column(0),
|
||||
windowRow(0),
|
||||
windowWidth(1),
|
||||
windowHeight(1),
|
||||
windowHeight(10),
|
||||
xscale(1),
|
||||
yscale(1),
|
||||
font(NULL),
|
||||
autoScroll(true)
|
||||
{
|
||||
|
@ -49,7 +56,7 @@ void Console::begin()
|
|||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(0, windowWidth, 0, windowHeight);
|
||||
gluOrtho2D(0, xscale, 0, yscale);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
@ -81,7 +88,8 @@ void Console::render(int rowHeight)
|
|||
glPushMatrix();
|
||||
for (int i = 0; i < rowHeight; i++)
|
||||
{
|
||||
int r = (nRows - rowHeight + 1 + windowRow + i) % nRows;
|
||||
//int r = (nRows - rowHeight + 1 + windowRow + i) % nRows;
|
||||
int r = pmod(row + windowRow + i, nRows);
|
||||
for (int j = 0; j < nColumns; j++)
|
||||
{
|
||||
char ch = text[r * (nColumns + 1) + j];
|
||||
|
@ -99,10 +107,10 @@ void Console::render(int rowHeight)
|
|||
}
|
||||
|
||||
|
||||
void Console::setWindowSize(int w, int h)
|
||||
void Console::setScale(int w, int h)
|
||||
{
|
||||
windowWidth = w;
|
||||
windowHeight = h;
|
||||
xscale = w;
|
||||
yscale = h;
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,7 +133,7 @@ void Console::newline()
|
|||
column = 0;
|
||||
|
||||
if (autoScroll)
|
||||
windowRow = row;
|
||||
windowRow = -(windowHeight - 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -192,6 +200,12 @@ void Console::setWindowRow(int _row)
|
|||
}
|
||||
|
||||
|
||||
void Console::setWindowHeight(int _height)
|
||||
{
|
||||
windowHeight = _height;
|
||||
}
|
||||
|
||||
|
||||
int Console::getWidth() const
|
||||
{
|
||||
return nColumns;
|
||||
|
|
|
@ -43,7 +43,7 @@ class Console : public std::ostream
|
|||
void end();
|
||||
void render(int rowHeight);
|
||||
|
||||
void setWindowSize(int, int);
|
||||
void setScale(int, int);
|
||||
void setFont(TextureFont*);
|
||||
|
||||
void print(char);
|
||||
|
@ -57,6 +57,7 @@ class Console : public std::ostream
|
|||
int getColumn() const;
|
||||
int getWindowRow() const;
|
||||
void setWindowRow(int);
|
||||
void setWindowHeight(int);
|
||||
|
||||
int getHeight() const;
|
||||
int getWidth() const;
|
||||
|
@ -70,8 +71,10 @@ class Console : public std::ostream
|
|||
|
||||
int windowRow;
|
||||
|
||||
int windowWidth;
|
||||
int windowHeight;
|
||||
|
||||
int xscale;
|
||||
int yscale;
|
||||
TextureFont* font;
|
||||
|
||||
ConsoleStreamBuf sbuf;
|
||||
|
|
|
@ -316,6 +316,7 @@ CelestiaCore::CelestiaCore() :
|
|||
|
||||
clog.rdbuf(console.rdbuf());
|
||||
cerr.rdbuf(console.rdbuf());
|
||||
console.setWindowHeight(ConsolePageRows);
|
||||
}
|
||||
|
||||
CelestiaCore::~CelestiaCore()
|
||||
|
@ -848,23 +849,22 @@ void CelestiaCore::joystickButton(int button, bool down)
|
|||
|
||||
static void scrollConsole(Console& con, int lines)
|
||||
{
|
||||
int currentRow = con.getWindowRow();
|
||||
int topRow = con.getWindowRow();
|
||||
int height = con.getHeight();
|
||||
|
||||
if (lines < 0)
|
||||
{
|
||||
if ((topRow <= currentRow) != (topRow + lines <= currentRow))
|
||||
console.setWindowRow(currentRow);
|
||||
if (topRow + lines > -height)
|
||||
console.setWindowRow(topRow + lines);
|
||||
else
|
||||
console.setWindowRow((topRow + lines) % height);
|
||||
console.setWindowRow(-(height - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((topRow < currentRow) != (topRow + lines < currentRow))
|
||||
console.setWindowRow(currentRow);
|
||||
if (topRow + lines <= -ConsolePageRows)
|
||||
console.setWindowRow(topRow + lines);
|
||||
else
|
||||
console.setWindowRow((topRow + lines) % height);
|
||||
console.setWindowRow(-(ConsolePageRows - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2033,7 +2033,7 @@ void CelestiaCore::resize(GLsizei w, GLsizei h)
|
|||
renderer->resize(w, h);
|
||||
if (overlay != NULL)
|
||||
overlay->setWindowSize(w, h);
|
||||
console.setWindowSize(w, h);
|
||||
console.setScale(w, h);
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
|
|
Loading…
Reference in New Issue