code format
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Basic PIScreen tile
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Basic PIScreen tile
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piscreentile.h"
|
||||
|
||||
#include "piscreendrawer.h"
|
||||
|
||||
|
||||
@@ -25,24 +26,23 @@ using namespace PIScreenTypes;
|
||||
|
||||
|
||||
PIScreenTile::PIScreenTile(const PIString & n, Direction d, SizePolicy p): PIObject(n) {
|
||||
direction = d;
|
||||
size_policy = p;
|
||||
focus_flags = 0;
|
||||
screen = 0;
|
||||
direction = d;
|
||||
size_policy = p;
|
||||
focus_flags = 0;
|
||||
screen = 0;
|
||||
minimumWidth = minimumHeight = x_ = y_ = width_ = height_ = pw = ph = 0;
|
||||
maximumWidth = maximumHeight = 65535;
|
||||
marginLeft = marginRight = marginTop = marginBottom = spacing = 0;
|
||||
parent = 0;
|
||||
back_symbol = ' ';
|
||||
visible = true;
|
||||
has_focus = false;
|
||||
parent = 0;
|
||||
back_symbol = ' ';
|
||||
visible = true;
|
||||
has_focus = false;
|
||||
}
|
||||
|
||||
|
||||
PIScreenTile::~PIScreenTile() {
|
||||
//piCout << this << "~";
|
||||
if (screen)
|
||||
screen->tileRemovedInternal(this);
|
||||
// piCout << this << "~";
|
||||
if (screen) screen->tileRemovedInternal(this);
|
||||
setScreen(0);
|
||||
deleteChildren();
|
||||
if (!parent) return;
|
||||
@@ -76,20 +76,18 @@ void PIScreenTile::removeTile(PIScreenTile * t) {
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIScreenTile * > PIScreenTile::children(bool only_visible) {
|
||||
PIVector<PIScreenTile * > ret;
|
||||
piForeach (PIScreenTile * t, tiles)
|
||||
if (t->visible || !only_visible)
|
||||
ret << t << t->children(only_visible);
|
||||
PIVector<PIScreenTile *> PIScreenTile::children(bool only_visible) {
|
||||
PIVector<PIScreenTile *> ret;
|
||||
piForeach(PIScreenTile * t, tiles)
|
||||
if (t->visible || !only_visible) ret << t << t->children(only_visible);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIScreenTile * PIScreenTile::childUnderMouse(int x, int y) {
|
||||
piForeach (PIScreenTile * t, tiles) {
|
||||
piForeach(PIScreenTile * t, tiles) {
|
||||
if (!t->visible) continue;
|
||||
if (x >= t->x_ && (x - t->x_) < t->width_ &&
|
||||
y >= t->y_ && (y - t->y_) < t->height_) {
|
||||
if (x >= t->x_ && (x - t->x_) < t->width_ && y >= t->y_ && (y - t->y_) < t->height_) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -105,13 +103,13 @@ void PIScreenTile::raiseEvent(TileEvent e) {
|
||||
|
||||
void PIScreenTile::setScreen(PIScreenBase * s) {
|
||||
screen = s;
|
||||
piForeach (PIScreenTile * t, tiles)
|
||||
piForeach(PIScreenTile * t, tiles)
|
||||
t->setScreen(s);
|
||||
}
|
||||
|
||||
|
||||
void PIScreenTile::deleteChildren() {
|
||||
piForeach (PIScreenTile * t, tiles) {
|
||||
piForeach(PIScreenTile * t, tiles) {
|
||||
t->parent = 0;
|
||||
delete t;
|
||||
}
|
||||
@@ -129,9 +127,16 @@ void PIScreenTile::drawEventInternal(PIScreenDrawer * d) {
|
||||
if (!visible) {
|
||||
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)
|
||||
piForeach(PIScreenTile * t, tiles)
|
||||
t->drawEventInternal(d);
|
||||
}
|
||||
|
||||
@@ -141,18 +146,22 @@ void PIScreenTile::sizeHint(int & w, int & h) const {
|
||||
h = 0;
|
||||
if (tiles.isEmpty()) return;
|
||||
int sl = spacing * (tiles.size_s() - 1);
|
||||
if (direction == Horizontal) w += sl;
|
||||
else h += sl;
|
||||
piForeachC (PIScreenTile * t, tiles) {
|
||||
if (direction == Horizontal)
|
||||
w += sl;
|
||||
else
|
||||
h += sl;
|
||||
piForeachC(PIScreenTile * t, tiles) {
|
||||
if (!t->visible) continue;
|
||||
int cw(0), ch(0);
|
||||
t->sizeHint(cw, ch);
|
||||
cw = piClampi(cw, t->minimumWidth, t->maximumWidth);
|
||||
ch = piClampi(ch, t->minimumHeight, t->maximumHeight);
|
||||
if (direction == Horizontal) {
|
||||
w += cw; h = piMaxi(h, ch);
|
||||
w += cw;
|
||||
h = piMaxi(h, ch);
|
||||
} else {
|
||||
h += ch; w = piMaxi(w, cw);
|
||||
h += ch;
|
||||
w = piMaxi(w, cw);
|
||||
}
|
||||
}
|
||||
w += marginLeft + marginRight;
|
||||
@@ -163,7 +172,7 @@ 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);
|
||||
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());
|
||||
@@ -180,7 +189,7 @@ void PIScreenTile::layout() {
|
||||
cs = (direction == Horizontal) ? cw : ch;
|
||||
as += cs;
|
||||
}
|
||||
hints[i] = cs;
|
||||
hints[i] = cs;
|
||||
asizes[i] = 0.f;
|
||||
}
|
||||
if (as <= ts) {
|
||||
@@ -188,10 +197,10 @@ void PIScreenTile::layout() {
|
||||
SizePolicy pol = Fixed;
|
||||
if (ecnt > 0) {
|
||||
acnt = ecnt;
|
||||
pol = Expanding;
|
||||
pol = Expanding;
|
||||
} else if (pcnt > 0) {
|
||||
acnt = pcnt;
|
||||
pol = Preferred;
|
||||
pol = Preferred;
|
||||
}
|
||||
if (acnt > 0) {
|
||||
float add_a = float(ts - as), add_s = add_a / acnt, add_da(0.);
|
||||
@@ -210,8 +219,7 @@ void PIScreenTile::layout() {
|
||||
for (int j = 0; j < tiles.size_s(); ++j) {
|
||||
if (i == j) continue;
|
||||
if (max_tl[j]) continue;
|
||||
if (tiles[j]->size_policy == pol && tiles[j]->visible && tiles[j]->needLayout())
|
||||
asizes[j] += pas;
|
||||
if (tiles[j]->size_policy == pol && tiles[j]->visible && tiles[j]->needLayout()) asizes[j] += pas;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,16 +241,15 @@ void PIScreenTile::layout() {
|
||||
t->x_ = cx;
|
||||
t->y_ = cy;
|
||||
if (direction == Horizontal) {
|
||||
t->width_ = hints[i];
|
||||
t->width_ = hints[i];
|
||||
t->height_ = ts2;
|
||||
cx += hints[i] + spacing;
|
||||
} else {
|
||||
t->width_ = ts2;
|
||||
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_);
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user