ultimatepp/uppdev/Bugs/LineEditScroll/main.cpp
cxl 351994a6cc Adding uppdev....
git-svn-id: svn://ultimatepp.org/upp/trunk@328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2008-08-15 08:36:24 +00:00

67 lines
1.3 KiB
C++

#include "LineEditScroll.h"
class ScrollBugWindow : public TopWindow {
public:
typedef ScrollBugWindow CLASSNAME;
ScrollBugWindow();
private:
void Animate();
private:
LineEdit editor;
Vector<char> matrix;
enum { WIDTH = 80, HEIGHT = 160 };
Point pos;
int sync_ticks;
TimeCallback tc_anim;
};
ScrollBugWindow::ScrollBugWindow()
{
matrix.SetCount(WIDTH * HEIGHT, ' ');
pos = Point(0, 0);
sync_ticks = msecs();
Add(editor.SizePos());
Sizeable().Zoomable();
Title("Line editor scrolling bug");
tc_anim.Set(-10, THISBACK(Animate));
}
void ScrollBugWindow::Animate()
{
String rowfmt = NFormat("Row #%d: ", pos.y + 1);
rowfmt.Cat('*', pos.y + 1);
rowfmt << " \\";
matrix[pos.y * WIDTH + pos.x] = (pos.x < rowfmt.GetLength() ? rowfmt[pos.x] : ' ');
if(pos.x & 1) {
if(--pos.y < 0) {
pos.y = 0;
pos.x++;
}
}
else {
if(++pos.y >= HEIGHT) {
pos.y = HEIGHT - 1;
pos.x++;
}
}
if(pos.x >= WIDTH) {
Fill(matrix.Begin(), matrix.End(), ' ');
pos = Point(0, 0);
}
if(msecs(sync_ticks) >= 500) {
String text;
for(int i = 0; i < HEIGHT; i++) {
text.Cat(matrix.GetIter(i * WIDTH), WIDTH);
text.Cat('\n');
}
editor <<= text;
sync_ticks = msecs();
}
}
GUI_APP_MAIN
{
ScrollBugWindow().Run();
}