before formatting

This commit is contained in:
2022-12-14 13:56:19 +03:00
parent c74ba871cd
commit 430a41fefc
14 changed files with 912 additions and 623 deletions

View File

@@ -18,6 +18,7 @@
*/
#include "piscreentiles.h"
#include "piscreendrawer.h"
@@ -37,7 +38,7 @@ TileSimple::TileSimple(const TileSimple::Row & r): PIScreenTile() {
void TileSimple::sizeHint(int & w, int & h) const {
w = h = 0;
piForeachC (Row & r, content)
piForeachC(Row & r, content)
w = piMaxi(w, r.first.size_s());
h = content.size_s();
}
@@ -57,13 +58,13 @@ void TileSimple::drawEvent(PIScreenDrawer * d) {
}
// TileScrollBar
TileScrollBar::TileScrollBar(const PIString & n) {
direction = Vertical;
thickness = 1;
minimum_ = value_ = 0;
maximum_ = 100;
maximum_ = 100;
}
@@ -122,15 +123,15 @@ bool TileScrollBar::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileList
TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
alignment = Left;
alignment = Left;
focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab | FocusOnMouseOrWheel;
lhei = offset = cur = 0;
mouse_sel = false;
selection_mode = sm;
scroll = new TileScrollBar();
mouse_sel = false;
selection_mode = sm;
scroll = new TileScrollBar();
scroll->size_policy = Ignore;
addTile(scroll);
}
@@ -138,26 +139,26 @@ TileList::TileList(const PIString & n, SelectionMode sm): PIScreenTile(n) {
void TileList::sizeHint(int & w, int & h) const {
w = h = 0;
piForeachC (Row & r, content)
piForeachC(Row & r, content)
w = piMaxi(w, r.first.size_s());
h = 3;
}
void TileList::resizeEvent(int w, int h) {
scroll->x_ = x_ + width_ - 1;
scroll->y_ = y_;
scroll->width_ = 1;
scroll->x_ = x_ + width_ - 1;
scroll->y_ = y_;
scroll->width_ = 1;
scroll->height_ = height_;
}
void TileList::drawEvent(PIScreenDrawer * d) {
lhei = height_ - 2;
lhei = height_ - 2;
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 (ie < content.size_s()) d->drawText(x_, y_ + height_ - 1, PIString(" \\/ ").repeat(width_ / 4), Green, Default, Bold);
//piCout << is << ie << offset << lhei << content.size_s();
// 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;
@@ -172,7 +173,7 @@ void TileList::drawEvent(PIScreenDrawer * d) {
case Right: rx = x_ + width_ - 1 - r.first.size_s(); break;
};
CharFlags cf = r.second.flags;
Color cc = (Color)r.second.color_char;
Color cc = (Color)r.second.color_char;
if (selected[i]) {
cf |= Bold;
cc = Yellow;
@@ -188,9 +189,7 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
lhei = height_ - 2;
int oo(0), osp = piMini(3, lhei / 4);
switch (key.key) {
case PIKbdListener::PageUp:
cur -= lhei / 2;
oo -= lhei / 2;
case PIKbdListener::PageUp: cur -= lhei / 2; oo -= lhei / 2;
case PIKbdListener::UpArrow:
cur--;
oo--;
@@ -207,7 +206,8 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
switch (selection_mode) {
case NoSelection: return false;
case SingleSelection:
if (selected.isEmpty()) selected << cur;
if (selected.isEmpty())
selected << cur;
else {
bool add = !selected[cur];
selected.clear();
@@ -216,8 +216,10 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
raiseEvent(TileEvent(SelectionChanged));
return true;
case MultiSelection:
if (selected[cur]) selected.remove(cur);
else selected << cur;
if (selected[cur])
selected.remove(cur);
else
selected << cur;
raiseEvent(TileEvent(SelectionChanged));
break;
}
@@ -238,17 +240,14 @@ bool TileList::keyEvent(PIKbdListener::KeyEvent key) {
if (offset >= content.size_s() - lhei) offset = content.size_s() - lhei;
if (offset < 0) offset = 0;
return true;
case PIKbdListener::Home:
cur = offset = 0;
return true;
case PIKbdListener::Home: cur = offset = 0; return true;
case PIKbdListener::End:
cur = content.size_s() - 1;
cur = content.size_s() - 1;
offset = content.size_s() - lhei;
if (offset < 0) offset = 0;
return true;
case PIKbdListener::Return:
if (cur >= 0 && cur < content.size_s())
raiseEvent(TileEvent(RowPressed, cur));
if (cur >= 0 && cur < content.size_s()) raiseEvent(TileEvent(RowPressed, cur));
return true;
case '*':
if (selection_mode == TileList::MultiSelection) {
@@ -278,12 +277,8 @@ bool TileList::mouseEvent(PIKbdListener::MouseEvent me) {
if (mp < 0 || mp >= content.size_s()) return true;
cur = mp;
switch (me.action) {
case PIKbdListener::MouseButtonPress:
mouse_sel = !selected.contains(cur);
break;
case PIKbdListener::MouseButtonDblClick:
keyEvent(PIKbdListener::KeyEvent(PIKbdListener::Return));
return true;
case PIKbdListener::MouseButtonPress: mouse_sel = !selected.contains(cur); break;
case PIKbdListener::MouseButtonDblClick: keyEvent(PIKbdListener::KeyEvent(PIKbdListener::Return)); return true;
default: break;
}
if (me.buttons[PIKbdListener::MouseRight]) {
@@ -294,8 +289,10 @@ bool TileList::mouseEvent(PIKbdListener::MouseEvent me) {
raiseEvent(TileEvent(SelectionChanged));
break;
case MultiSelection:
if (mouse_sel) selected << cur;
else selected.remove(cur);
if (mouse_sel)
selected << cur;
else
selected.remove(cur);
raiseEvent(TileEvent(SelectionChanged));
break;
default: break;
@@ -311,7 +308,7 @@ bool TileList::wheelEvent(PIKbdListener::WheelEvent we) {
}
// TileButton
TileButton::TileButton(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
@@ -327,7 +324,7 @@ void TileButton::sizeHint(int & w, int & h) const {
void TileButton::drawEvent(PIScreenDrawer * d) {
Color cb = has_focus ? Blue : Cyan;
Color ct = has_focus ? White : Black;
int ff = has_focus ? Bold : 0;
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);
@@ -351,25 +348,25 @@ bool TileButton::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileButtons
TileButtons::TileButtons(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
direction = Horizontal;
alignment = PIScreenTypes::Center;
cur = 0;
direction = Horizontal;
alignment = PIScreenTypes::Center;
cur = 0;
}
void TileButtons::sizeHint(int & w, int & h) const {
w = h = 0;
if (direction == Horizontal) {
piForeachC (Button & b, content)
piForeachC(Button & b, content)
w += b.first.size_s() + 4;
w += piMaxi(0, content.size_s() - 1) * 2;
h += 1;
} else {
piForeachC (Button & b, content)
piForeachC(Button & b, content)
w = piMaxi(w, b.first.size_s() + 4);
h += content.size_s();
h += piMaxi(0, content.size_s() - 1);
@@ -387,12 +384,11 @@ void TileButtons::drawEvent(PIScreenDrawer * d) {
case PIScreenTypes::Right: dx = width_ - shw; break;
default: break;
}
if (direction == PIScreenTypes::Horizontal)
cx += dx;
if (direction == PIScreenTypes::Horizontal) cx += dx;
for (int i = 0; i < content.size_s(); ++i) {
Color cb = Cyan;
Color ct = Black;
int ff = 0;
int ff = 0;
if (i == cur && has_focus) {
cb = Blue;
ct = White;
@@ -430,9 +426,7 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
if (cur >= content.size_s()) cur = content.size_s() - 1;
return true;
case PIKbdListener::Space:
case PIKbdListener::Return:
raiseEvent(TileEvent(ButtonSelected, cur));
return true;
case PIKbdListener::Return: raiseEvent(TileEvent(ButtonSelected, cur)); return true;
};
return PIScreenTile::keyEvent(key);
}
@@ -441,8 +435,7 @@ bool TileButtons::keyEvent(PIKbdListener::KeyEvent key) {
bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
if (me.action == PIKbdListener::MouseMove || me.action == PIKbdListener::MouseButtonPress) {
for (int i = 0; i < btn_rects.size_s(); ++i)
if (me.x >= btn_rects[i].x0 && me.x < btn_rects[i].x1 &&
me.y >= btn_rects[i].y0 && me.y < btn_rects[i].y1) {
if (me.x >= btn_rects[i].x0 && me.x < btn_rects[i].x1 && me.y >= btn_rects[i].y0 && me.y < btn_rects[i].y1) {
cur = i;
break;
}
@@ -454,11 +447,11 @@ bool TileButtons::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileCheck
TileCheck::TileCheck(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | NextByArrowsAll | FocusOnMouse;
toggled = false;
toggled = false;
}
@@ -471,7 +464,7 @@ void TileCheck::sizeHint(int & w, int & h) const {
void TileCheck::drawEvent(PIScreenDrawer * d) {
Color cb = has_focus ? Blue : Cyan;
Color ct = has_focus ? White : Black;
int ff = has_focus ? Bold : 0;
int ff = has_focus ? Bold : 0;
PIString cs("[ ]");
if (toggled) cs[1] = '*';
d->fillRect(x_, y_, x_ + width_, y_ + 1, ' ', Default, cb);
@@ -499,12 +492,12 @@ bool TileCheck::mouseEvent(PIKbdListener::MouseEvent me) {
}
// TileProgress
TileProgress::TileProgress(const PIString & n): PIScreenTile(n) {
maximum = 100.;
value = 0.;
suffix = " %";
value = 0.;
suffix = " %";
}
@@ -515,7 +508,7 @@ 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);
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);
@@ -532,10 +525,10 @@ void TileProgress::drawEvent(PIScreenDrawer * d) {
}
// TilePICout
TilePICout::TilePICout(const PIString & n): TileList(n) {
max_lines = 1024;
max_lines = 1024;
selection_mode = TileList::SingleSelection;
PICout::setOutputDevices(PICout::Buffer);
}
@@ -545,14 +538,13 @@ void TilePICout::drawEvent(PIScreenDrawer * d) {
PIString out = PICout::getBufferAndClear();
if (!out.isEmpty()) {
PIStringList l = out.split("\n");
bool scroll = (cur == content.size_s() - 1) || !has_focus;
piForeachC (PIString & s, l)
bool scroll = (cur == content.size_s() - 1) || !has_focus;
piForeachC(PIString & s, l)
content << TileList::Row(s.trimmed(), format);
if (content.size_s() > max_lines)
content.remove(0, content.size_s() - max_lines);
if (content.size_s() > max_lines) content.remove(0, content.size_s() - max_lines);
if (scroll) {
offset = piMaxi(0, content.size_s() - lhei);
cur = content.size_s() - 1;
cur = content.size_s() - 1;
}
}
TileList::drawEvent(d);
@@ -569,16 +561,16 @@ bool TilePICout::keyEvent(PIKbdListener::KeyEvent key) {
}
// TileInput
TileInput::TileInput(const PIString & n): PIScreenTile(n) {
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
focus_flags = CanHasFocus | NextByTab | FocusOnMouse;
back_format.color_back = White;
format.color_char = Black;
format.color_back = White;
max_length = 1024;
format.color_char = Black;
format.color_back = White;
max_length = 1024;
cur = offset = 0;
inv = false;
inv = false;
}
@@ -591,10 +583,8 @@ 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);
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);
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);
if (!has_focus) return;
Color cb = (Color)format.color_char, cc = (Color)format.color_back;
if (tm_blink.elapsed_m() >= 650) {
@@ -641,14 +631,13 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
reserCursor();
return true;
case PIKbdListener::End:
cur = text.size_s();
cur = text.size_s();
offset = text.size_s() - lwid;
if (offset < 0) offset = 0;
reserCursor();
return true;
case PIKbdListener::Backspace:
if (cur > text.size_s() || text.isEmpty())
return true;
if (cur > text.size_s() || text.isEmpty()) return true;
text.remove(cur - 1, 1);
cur--;
if (cur > text.size_s()) cur = text.size_s();
@@ -658,8 +647,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
reserCursor();
return true;
case PIKbdListener::Delete:
if (cur >= text.size_s() || text.isEmpty())
return true;
if (cur >= text.size_s() || text.isEmpty()) return true;
text.remove(cur, 1);
if (cur < 0) cur = 0;
if (cur > text.size_s()) cur = text.size_s();
@@ -685,8 +673,7 @@ bool TileInput::keyEvent(PIKbdListener::KeyEvent key) {
case PIKbdListener::F9:
case PIKbdListener::F10:
case PIKbdListener::F11:
case PIKbdListener::F12:
break;
case PIKbdListener::F12: break;
default:
text.insert(cur, PIChar((ushort)key.key));
cur++;