git-svn-id: svn://db.shs.com.ru/pip@249 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-09-01 15:03:56 +00:00
parent bae0456042
commit 5d296fa5a5
14 changed files with 352 additions and 99 deletions

View File

@@ -199,8 +199,8 @@ public:
void getCursor(int & x, int & y) {
GetConsoleScreenBufferInfo(console, &sbi);
x = sbi.dwCursorPosition.X + sbi.srWindow.Left;
y = sbi.dwCursorPosition.Y + sbi.srWindow.Top;
x = sbi.dwCursorPosition.X - sbi.srWindow.Left;
y = sbi.dwCursorPosition.Y - sbi.srWindow.Top;
}

View File

@@ -472,8 +472,8 @@ void PIScreen::begin() {
void PIScreen::run() {
console.prepare();
root.width = drawer_.width = console.width;
root.height = drawer_.height = console.height;
root.width_ = drawer_.width = console.width;
root.height_ = drawer_.height = console.height;
root.layout();
root.drawEventInternal(&drawer_);
if (tile_dialog) {
@@ -481,12 +481,12 @@ void PIScreen::run() {
tile_dialog->sizeHint(sw, sh);
sw = piClampi(sw, tile_dialog->minimumWidth, tile_dialog->maximumWidth);
sh = piClampi(sh, tile_dialog->minimumHeight, tile_dialog->maximumHeight);
tile_dialog->x = (console.width - sw) / 2;
tile_dialog->y = (console.height - sh) / 2;
tile_dialog->width = sw;
tile_dialog->height = sh;
tile_dialog->x_ = (console.width - sw) / 2;
tile_dialog->y_ = (console.height - sh) / 2;
tile_dialog->width_ = sw;
tile_dialog->height_ = sh;
tile_dialog->layout();
int dx = tile_dialog->x - 1, dy = tile_dialog->y - 1, dw = tile_dialog->width, dh = tile_dialog->height;
int dx = tile_dialog->x_ - 1, dy = tile_dialog->y_ - 1, dw = tile_dialog->width_, dh = tile_dialog->height_;
drawer_.drawFrame(dx, dy, dx + dw + 1, dy + dh + 1, (Color)tile_dialog->back_format.color_char,
(Color)tile_dialog->back_format.color_back, (CharFlags)tile_dialog->back_format.flags);
tile_dialog->drawEventInternal(&drawer_);

View File

@@ -29,7 +29,7 @@ PIScreenTile::PIScreenTile(const PIString & n, Direction d, SizePolicy p): PIObj
size_policy = p;
focus_flags = 0;
screen = 0;
minimumWidth = minimumHeight = x = y = width = height = pw = ph = 0;
minimumWidth = minimumHeight = x_ = y_ = width_ = height_ = pw = ph = 0;
maximumWidth = maximumHeight = 65535;
marginLeft = marginRight = marginTop = marginBottom = spacing = 0;
parent = 0;
@@ -121,7 +121,7 @@ void PIScreenTile::drawEventInternal(PIScreenDrawer * d) {
//d->clearRect(x, y, x + width, y + height);
return;
}
d->fillRect(x, y, x + width, y + height, back_symbol, (Color)back_format.color_char, (Color)back_format.color_back, back_format.flags);
d->fillRect(x_, y_, x_ + width_, y_ + height_, back_symbol, (Color)back_format.color_char, (Color)back_format.color_back, back_format.flags);
drawEvent(d);
piForeach (PIScreenTile * t, tiles)
t->drawEventInternal(d);
@@ -155,8 +155,8 @@ void PIScreenTile::sizeHint(int & w, int & h) const {
void PIScreenTile::layout() {
if (tiles.isEmpty() || !visible) return;
int as(0), ts(0), ts2(0), ecnt(0), pcnt(0);
ts = (direction == Horizontal) ? (width - marginLeft - marginRight) : (height - marginTop - marginBottom);
ts2 = (direction != Horizontal) ? (width - marginLeft - marginRight) : (height - marginTop - marginBottom);
ts = (direction == Horizontal) ? (width_ - marginLeft - marginRight) : (height_ - marginTop - marginBottom);
ts2 = (direction != Horizontal) ? (width_ - marginLeft - marginRight) : (height_ - marginTop - marginBottom);
ts -= spacing * (tiles.size_s() - 1);
PIVector<int> hints(tiles.size_s());
PIVector<float> asizes(tiles.size_s());
@@ -218,25 +218,25 @@ void PIScreenTile::layout() {
}
}
}
int cx = x + marginLeft, cy = y + marginTop;
int cx = x_ + marginLeft, cy = y_ + marginTop;
for (int i = 0; i < tiles.size_s(); ++i) {
PIScreenTile * t(tiles[i]);
if (!t->visible) continue;
t->x = cx;
t->y = cy;
t->x_ = cx;
t->y_ = cy;
if (direction == Horizontal) {
t->width = hints[i];
t->height = ts2;
t->width_ = hints[i];
t->height_ = ts2;
cx += hints[i] + spacing;
} else {
t->width = ts2;
t->height = hints[i];
t->width_ = ts2;
t->height_ = hints[i];
cy += hints[i] + spacing;
}
if (t->pw != t->width || t->ph != t->height)
t->resizeEvent(t->width, t->height);
t->pw = t->width;
t->ph = t->height;
if (t->pw != t->width_ || t->ph != t->height_)
t->resizeEvent(t->width_, t->height_);
t->pw = t->width_;
t->ph = t->height_;
t->layout();
}
}

View File

@@ -46,6 +46,11 @@ public:
bool hasFocus() const {return has_focus;}
void setMargins(int m) {marginLeft = marginRight = marginTop = marginBottom = m;}
void setMargins(int l, int r, int t, int b) {marginLeft = l; marginRight = r; marginTop = t; marginBottom = b;}
int x() const {return x_;}
int y() const {return y_;}
int width() const {return width_;}
int height() const {return height_;}
PIScreenTypes::Direction direction;
PIScreenTypes::SizePolicy size_policy;
@@ -81,7 +86,7 @@ protected:
PIVector<PIScreenTile * > tiles;
PIScreenTile * parent;
PIScreenTypes::PIScreenBase * screen;
int x, y, width, height;
int x_, y_, width_, height_;
bool has_focus;
private:

View File

@@ -48,11 +48,11 @@ void TileSimple::drawEvent(PIScreenDrawer * d) {
Row & r(content[i]);
int rx = 0;
switch (alignment) {
case Left: rx = x; break;
case Center: rx = x + (width - r.first.size_s()) / 2; break;
case Right: rx = x + width - r.first.size_s(); break;
case Left: rx = x_; break;
case Center: rx = x_ + (width_ - r.first.size_s()) / 2; break;
case Right: rx = x_ + width_ - r.first.size_s(); break;
};
d->drawText(rx, y + i, r.first, (Color)r.second.color_char, (Color)r.second.color_back, r.second.flags);
d->drawText(rx, y_ + i, r.first, (Color)r.second.color_char, (Color)r.second.color_back, r.second.flags);
}
}
@@ -77,23 +77,23 @@ void TileList::sizeHint(int & w, int & h) const {
void TileList::drawEvent(PIScreenDrawer * d) {
vert_line = d->artChar(PIScreenDrawer::LineVertical);
lhei = height - 2;
lhei = height_ - 2;
//int osp = piMini(3, lhei / 4);
int is = piClampi(offset, 0, piMaxi(0, content.size_s() - 1)), ie = piClampi(offset + lhei, 0, content.size_s());
if (is > 0) d->drawText(x, y, PIString(" /\\ ").repeat(width / 4), Green, Default, Bold);
if (is > 0) d->drawText(x_, y_, PIString(" /\\ ").repeat(width_ / 4), Green, Default, Bold);
//piCout << is << ie << offset << lhei << content.size_s();
for (int i = is; i < ie; ++i) {
Row & r(content[i]);
bool sel = i == cur && has_focus;
if (sel) {
int cy = y + i - is + 1;
d->drawLine(x, cy, x + width - 2, cy, ' ', Default, Blue);
int cy = y_ + i - is + 1;
d->drawLine(x_, cy, x_ + width_ - 2, cy, ' ', Default, Blue);
}
int rx(0);
switch (alignment) {
case Left: rx = x; break;
case Center: rx = x + (width - 1 - r.first.size_s()) / 2; break;
case Right: rx = x + width - 1 - r.first.size_s(); break;
case Left: rx = x_; break;
case Center: rx = x_ + (width_ - 1 - r.first.size_s()) / 2; break;
case Right: rx = x_ + width_ - 1 - r.first.size_s(); break;
};
CharFlags cf = r.second.flags;
Color cc = (Color)r.second.color_char;
@@ -101,18 +101,18 @@ void TileList::drawEvent(PIScreenDrawer * d) {
cf |= Bold;
cc = Yellow;
}
d->drawText(rx, y + i - is + 1, r.first, cc, sel ? Blue : Default, cf);
d->drawText(rx, y_ + i - is + 1, r.first, cc, sel ? Blue : Default, cf);
}
int cx = x + width - 1;
d->drawLine(cx, y + 1, cx, y + height - 2, vert_line, Green);
int cx = x_ + width_ - 1;
d->drawLine(cx, y_ + 1, cx, y_ + height_ - 2, vert_line, Green);
if (content.size_s() > 1)
d->drawPixel(cx, y + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green);
if (ie < content.size_s()) d->drawText(x, y + height - 1, PIString(" \\/ ").repeat(width / 4), Green, Default, Bold);
d->drawPixel(cx, y_ + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green);
if (ie < content.size_s()) d->drawText(x_, y_ + height_ - 1, PIString(" \\/ ").repeat(width_ / 4), Green, Default, Bold);
}
bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
lhei = height - 2;
lhei = height_ - 2;
int oo(0), osp = piMini(3, lhei / 4);
switch (key.key) {
case PIKbdListener::PageUp:
@@ -216,10 +216,10 @@ void TileButton::drawEvent(PIScreenDrawer * d) {
Color cb = has_focus ? Blue : Cyan;
Color ct = has_focus ? White : Black;
int ff = has_focus ? Bold : 0;
d->fillRect(x, y, x + width, y + 1, ' ', Default, cb);
d->drawText(x, y, "[", ct, Transparent, ff);
d->drawText(x + (width - text.size_s()) / 2, y, text, ct, Transparent, ff);
d->drawText(x + width - 1, y, "]", ct, Transparent, ff);
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
d->drawText(x_, y_, "[", ct, Transparent, ff);
d->drawText(x_ + (width_ - text.size_s()) / 2, y_, text, ct, Transparent, ff);
d->drawText(x_ + width_ - 1, y_, "]", ct, Transparent, ff);
}
@@ -259,12 +259,12 @@ void TileButtons::sizeHint(int & w, int & h) const {
void TileButtons::drawEvent(PIScreenDrawer * d) {
int cx = x, cy = y, shw, shh;
int cx = x_, cy = y_, shw, shh;
sizeHint(shw, shh);
int dx = 0;
switch (alignment) {
case PIScreenTypes::Center: dx = (width - shw) / 2; break;
case PIScreenTypes::Right: dx = width - shw; break;
case PIScreenTypes::Center: dx = (width_ - shw) / 2; break;
case PIScreenTypes::Right: dx = width_ - shw; break;
default: break;
}
if (direction == PIScreenTypes::Horizontal)
@@ -281,7 +281,7 @@ void TileButtons::drawEvent(PIScreenDrawer * d) {
Button & b(content[i]);
int cw = b.first.size_s() + 2, xo(0);
if (direction == Vertical) {
cw = width - 2;
cw = width_ - 2;
xo = (cw - b.first.size_s()) / 2 - 1;
}
d->fillRect(cx, cy, cx + cw + 2, cy + 1, ' ', Default, cb);
@@ -337,9 +337,9 @@ void TileCheck::drawEvent(PIScreenDrawer * d) {
int ff = has_focus ? Bold : 0;
PIString cs("[ ]");
if (toggled) cs[1] = '*';
d->fillRect(x, y, x + width, y + 1, ' ', Default, cb);
d->drawText(x, y, cs, ct, Transparent, ff);
d->drawText(x + 4, y, text, ct, Transparent, ff);
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
d->drawText(x_, y_, cs, ct, Transparent, ff);
d->drawText(x_ + 4, y_, text, ct, Transparent, ff);
}
@@ -371,17 +371,17 @@ void TileProgress::sizeHint(int & w, int & h) const {
void TileProgress::drawEvent(PIScreenDrawer * d) {
int v = maximum == 0. ? 0 : piClampd(piRoundd(value / maximum * 100.), 0, 100);
PIString s = prefix + PIString::fromNumber(piRoundd(value)) + suffix;
int w = piRoundd(v / 100. * width), sx = (width - s.size_s()) / 2;
d->fillRect(x, y, x + width, y + 1, ' ', Default, Cyan);
d->fillRect(x, y, x + w, y + 1, ' ', Default, Blue);
int w = piRoundd(v / 100. * width_), sx = (width_ - s.size_s()) / 2;
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, Cyan);
d->fillRect(x_, y_, x_ + w, y_ + 1, ' ', Default, Blue);
if (w < sx)
d->drawText(x + sx, y, s, Black, Transparent);
d->drawText(x_ + sx, y_, s, Black, Transparent);
else if (w >= sx + s.size_s())
d->drawText(x + sx, y, s, White, Transparent);
d->drawText(x_ + sx, y_, s, White, Transparent);
else {
int fw = w - sx;
d->drawText(x + sx, y, s.left(fw), White, Transparent);
d->drawText(x + sx + fw, y, s.cutLeft(fw), Black, Transparent);
d->drawText(x_ + sx, y_, s.left(fw), White, Transparent);
d->drawText(x_ + sx + fw, y_, s.cutLeft(fw), Black, Transparent);
}
}
@@ -443,12 +443,12 @@ void TileInput::sizeHint(int & w, int & h) const {
void TileInput::drawEvent(PIScreenDrawer * d) {
PIString ps = text.mid(offset, width - 2);
d->drawText(x + 1, y, ps, (Color)format.color_char, Transparent, (CharFlags)format.flags);
PIString ps = text.mid(offset, width_ - 2);
d->drawText(x_ + 1, y_, ps, (Color)format.color_char, Transparent, (CharFlags)format.flags);
if (offset > 0)
d->drawText(x, y, "<", Green, Black, Bold);
if (text.size_s() - offset >= width - 2)
d->drawText(x + width - 1, y, ">", Green, Black, Bold);
d->drawText(x_, y_, "<", Green, Black, Bold);
if (text.size_s() - offset >= width_ - 2)
d->drawText(x_ + width_ - 1, y_, ">", Green, Black, Bold);
if (!has_focus) return;
Color cb = (Color)format.color_char, cc = (Color)format.color_back;
if (tm_blink.elapsed_m() >= 650) {
@@ -456,12 +456,12 @@ void TileInput::drawEvent(PIScreenDrawer * d) {
inv = !inv;
}
if (inv) piSwap(cb, cc);
d->drawText(x + 1 + cur - offset, y, text.mid(cur, 1).expandLeftTo(1, ' '), cc, cb, (CharFlags)format.flags);
d->drawText(x_ + 1 + cur - offset, y_, text.mid(cur, 1).expandLeftTo(1, ' '), cc, cb, (CharFlags)format.flags);
}
bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
int lwid = piMaxi(0, width - 2);
int lwid = piMaxi(0, width_ - 2);
int oo(0), osp = piMini(3, lwid / 4);
lwid--;
switch (key.key) {

View File

@@ -124,6 +124,16 @@ void PITerminal::write(PIKbdListener::SpecialKey k, PIKbdListener::KeyModifiers
}
void PITerminal::write(PIKbdListener::KeyEvent ke) {
if (isSpecialKey(ke.key)) write((PIKbdListener::SpecialKey)ke.key, ke.modifiers);
else {
PIByteArray ba;
ba << uchar(PIChar(ke.key).toConcole1Byte());
write(ba);
}
}
PIVector<PIVector<PIScreenTypes::Cell> > PITerminal::content() {
readConsole();
return cells;

View File

@@ -44,6 +44,7 @@ public:
void write(const PIByteArray & d);
void write(PIKbdListener::SpecialKey k, PIKbdListener::KeyModifiers m);
void write(PIKbdListener::KeyEvent ke);
PIVector<PIVector<PIScreenTypes::Cell> > content();
static bool isSpecialKey(int k);

View File

@@ -271,7 +271,7 @@ public:
/** \fn void tickEvent(void * data, int delimiter)
* \brief Raise on timer tick
* \details \b Data can be set with function \a setData(void * data) or from constructor.
* \b Delimiter if frequency delimiter, 1 for main loop. */
* \b Delimiter is frequency delimiter, 1 for main loop. */
//! \}