piethernet

git-svn-id: svn://db.shs.com.ru/pip@38 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-03-20 14:05:31 +00:00
parent 94b4870d94
commit f89764d6bc
20 changed files with 283 additions and 42 deletions

View File

@@ -379,10 +379,14 @@ bool PIScreen::nextFocus(PIScreenTile * rt, PIKbdListener::KeyEvent key) {
if (tile_focus) {
if (tile_focus->focus_flags[NextByTab] && key.key == PIKbdListener::Tab)
next = 1;
if (tile_focus->focus_flags[NextByArrows]) {
if (tile_focus->focus_flags[NextByArrowsHorizontal]) {
if (key.key == PIKbdListener::LeftArrow) next = -1;
if (key.key == PIKbdListener::RightArrow) next = 1;
}
if (tile_focus->focus_flags[NextByArrowsVertical]) {
if (key.key == PIKbdListener::UpArrow) next = -1;
if (key.key == PIKbdListener::DownArrow) next = 1;
}
}
//piCout << ftl.size() << ind << next;
if (next != 0) {

View File

@@ -79,7 +79,7 @@ void TileSimple::drawEvent(PIScreenDrawer * d) {
TileList::TileList(const PIString & n): PIScreenTile(n) {
alignment = Left;
focus_flags = CanHasFocus | NextByArrows | NextByTab;
focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab;
lhei = offset = cur = 0;
selection_mode = NoSelection;
}
@@ -206,6 +206,39 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
TileButton::TileButton(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll;
}
void TileButton::sizeHint(int & w, int & h) const {
w = text.size_s() + 2;
h = 1;
}
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);
}
bool TileButton::keyEvent(PIKbdListener::KeyEvent key) {
if (key.key == PIKbdListener::Space || key.key == PIKbdListener::Return) {
raiseEvent(TileEvent(ButtonClicked));
return true;
}
return PIScreenTile::keyEvent(key);
}
TileButtons::TileButtons(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab;
direction = Horizontal;
@@ -217,13 +250,13 @@ void TileButtons::sizeHint(int & w, int & h) const {
w = h = 0;
if (direction == Horizontal) {
piForeachC (Button & b, content)
w += b.first.size_s() + 2;
w += b.first.size_s() + 4;
w += piMaxi(0, content.size_s() - 1) * 2;
h += 3;
h += 1;
} else {
piForeachC (Button & b, content)
w = piMaxi(w, b.first.size_s() + 2 + 4);
h += content.size_s() * 3;
w = piMaxi(w, b.first.size_s() + 4);
h += content.size_s();
h += piMaxi(0, content.size_s() - 1);
}
}
@@ -243,15 +276,17 @@ void TileButtons::drawEvent(PIScreenDrawer * d) {
Button & b(content[i]);
int cw = b.first.size_s() + 2, xo(0);
if (direction == Vertical) {
cw = width - 4;
cw = width - 2;
xo = (cw - b.first.size_s()) / 2 - 1;
}
d->fillRect(cx, cy, cx + cw, cy + 3, ' ', Default, cb);
d->drawText(cx + 1 + xo, cy + 1, b.first, ct, Transparent, ff);
d->fillRect(cx, cy, cx + cw + 2, cy + 1, ' ', Default, cb);
d->drawText(cx, cy, "[", ct, Transparent, ff);
d->drawText(cx + xo + 2, cy, b.first, ct, Transparent, ff);
d->drawText(cx + cw + 1, cy, "]", ct, Transparent, ff);
if (direction == Horizontal)
cx += b.first.size_s() + 4;
cx += b.first.size_s() + 6;
else
cy += 4;
cy += 2;
}
}
@@ -275,3 +310,72 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
};
return PIScreenTile::keyEvent(key);
}
TileCheck::TileCheck(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll;
toggled = false;
}
void TileCheck::sizeHint(int & w, int & h) const {
w = text.size_s() + 4;
h = 1;
}
void TileCheck::drawEvent(PIScreenDrawer * d) {
Color cb = has_focus ? Blue : Cyan;
Color ct = has_focus ? White : Black;
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);
}
bool TileCheck::keyEvent(PIKbdListener::KeyEvent key) {
if (key.key == PIKbdListener::Space || key.key == PIKbdListener::Return) {
toggled = !toggled;
raiseEvent(TileEvent(Toggled, toggled));
return true;
}
return PIScreenTile::keyEvent(key);
}
TileProgress::TileProgress(const PIString & n): PIScreenTile(n) {
maximum = 100.;
value = 0.;
suffix = " %";
}
void TileProgress::sizeHint(int & w, int & h) const {
w = 20;
h = 1;
}
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);
if (w < sx)
d->drawText(x + sx, y, s, Black, Transparent);
else if (w >= sx + s.size_s())
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);
}
}

View File

@@ -67,6 +67,23 @@ protected:
class TileButton: public PIScreenTile {
public:
TileButton(const PIString & n = PIString());
enum EventType {
ButtonClicked
};
PIScreenTypes::CellFormat format;
PIString text;
protected:
void sizeHint(int & w, int & h) const;
void drawEvent(PIScreenDrawer * d);
bool keyEvent(PIKbdListener::KeyEvent key);
};
class TileButtons: public PIScreenTile {
public:
TileButtons(const PIString & n = PIString());
@@ -83,4 +100,38 @@ protected:
};
class TileCheck: public PIScreenTile {
public:
TileCheck(const PIString & n = PIString());
enum EventType {
Toggled
};
PIScreenTypes::CellFormat format;
PIString text;
bool toggled;
protected:
void sizeHint(int & w, int & h) const;
void drawEvent(PIScreenDrawer * d);
bool keyEvent(PIKbdListener::KeyEvent key);
};
class TileProgress: public PIScreenTile {
public:
TileProgress(const PIString & n = PIString());
PIScreenTypes::CellFormat format;
PIString prefix;
PIString suffix;
double maximum;
double value;
protected:
void sizeHint(int & w, int & h) const;
void drawEvent(PIScreenDrawer * d);
};
#endif // PISCREENTILES_H

View File

@@ -74,7 +74,9 @@ namespace PIScreenTypes {
enum FocusFlag {
CanHasFocus /** Tile can has focus */ = 0x1,
NextByTab /** Focus passed to next tile by tab key */ = 0x2,
NextByArrows /** Focus passed to next tile by arrow keys */ = 0x4
NextByArrowsHorizontal /** Focus passed to next tile by arrow keys left or right */ = 0x4,
NextByArrowsVertical /** Focus passed to next tile by arrow keys up or down */ = 0x8,
NextByArrowsAll /** Focus passed to next tile by any arrow key */ = NextByArrowsHorizontal | NextByArrowsVertical
};
typedef PIFlags<CharFlag> CharFlags;