* Use varargs in Canvas::print.

* Added min/max size to display::Window. Added flags for windows that
should be on located at the left/bottom side of a Frame.

* Reversed print order in WindowLog*.

* Added display::TextElement and subclasses for flexible printing to a
char buffer with associated attributes. Added display::Attributes and
display::Canvas::print_attributes.

* Added display::WindowText for use with display::TextElement's.

* Added ui::ElementMenu for generic menus, and started work adding
this to ui::Download.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@751 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-08-06 18:20:56 +00:00
parent 62beb9d9ed
commit 0b45062eb3
66 changed files with 1350 additions and 256 deletions
+214 -64
View File
@@ -58,11 +58,8 @@ Frame::Frame() :
bool
Frame::is_width_dynamic() const {
switch (m_type) {
case TYPE_NONE:
return false;
case TYPE_WINDOW:
return m_window->is_active() && m_window->is_width_dynamic();
case TYPE_NONE: return false;
case TYPE_WINDOW: return m_window->is_active() && m_window->is_width_dynamic();
case TYPE_ROW:
case TYPE_COLUMN:
@@ -79,11 +76,8 @@ Frame::is_width_dynamic() const {
bool
Frame::is_height_dynamic() const {
switch (m_type) {
case TYPE_NONE:
return false;
case TYPE_WINDOW:
return m_window->is_active() && m_window->is_height_dynamic();
case TYPE_NONE: return false;
case TYPE_WINDOW: return m_window->is_active() && m_window->is_height_dynamic();
case TYPE_ROW:
case TYPE_COLUMN:
@@ -97,35 +91,82 @@ Frame::is_height_dynamic() const {
return false;
}
Frame::pair_type
bool
Frame::has_left_frame() const {
switch (m_type) {
case TYPE_NONE:
case TYPE_ROW: return false;
case TYPE_WINDOW: return m_window->is_active() && m_window->is_left();
case TYPE_COLUMN:
for (size_type i = 0; i < m_containerSize; ++i)
if (m_container[i]->has_left_frame())
return true;
return false;
}
return false;
}
bool
Frame::has_bottom_frame() const {
switch (m_type) {
case TYPE_NONE:
case TYPE_COLUMN: return false;
case TYPE_WINDOW: return m_window->is_active() && m_window->is_bottom();
case TYPE_ROW:
for (size_type i = 0; i < m_containerSize; ++i)
if (m_container[i]->has_bottom_frame())
return true;
return false;
}
return false;
}
Frame::bounds_type
Frame::preferred_size() const {
switch (m_type) {
case TYPE_NONE:
return pair_type(0, 0);
return bounds_type(0, 0, 0, 0);
case TYPE_WINDOW:
if (m_window->is_active())
return pair_type(std::max<uint32_t>(m_window->min_width(), 1), std::max<uint32_t>(m_window->min_height(), 1));
return bounds_type(m_window->min_width(), m_window->min_height(),
m_window->max_width(), m_window->max_height());
else
return pair_type(0, 0);
return bounds_type(0, 0, 0, 0);
case TYPE_ROW:
case TYPE_COLUMN:
{
pair_type accum(0, 0);
bounds_type accum(0, 0, 0, 0);
for (size_type i = 0; i < m_containerSize; ++i) {
pair_type p = m_container[i]->preferred_size();
bounds_type p = m_container[i]->preferred_size();
accum.first += p.first;
accum.second += p.second;
accum.minWidth += p.minWidth;
accum.minHeight += p.minHeight;
if (p.maxWidth == Window::extent_full || accum.maxWidth == Window::extent_full)
accum.maxWidth = Window::extent_full;
else
accum.maxWidth += p.maxWidth;
if (p.maxHeight == Window::extent_full || accum.maxHeight == Window::extent_full)
accum.maxHeight = Window::extent_full;
else
accum.maxHeight += p.maxHeight;
}
return accum;
}
}
return pair_type(0, 0);
return bounds_type(0, 0, 0, 0);
}
void
@@ -185,6 +226,12 @@ Frame::initialize_column(size_type size) {
void
Frame::clear() {
switch (m_type) {
case TYPE_WINDOW:
if (m_window != NULL)
m_window->set_offscreen(true);
break;
case TYPE_ROW:
case TYPE_COLUMN:
for (size_type i = 0; i < m_containerSize; ++i) {
@@ -249,41 +296,64 @@ Frame::balance(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
m_width = width;
m_height = height;
if (m_type == TYPE_NONE)
return;
switch (m_type) {
case TYPE_NONE: break;
case TYPE_WINDOW: balance_window(x, y, width, height); break;
case TYPE_ROW: balance_row(x, y, width, height); break;
case TYPE_COLUMN: balance_column(x, y, width, height); break;
}
}
if (m_type == TYPE_WINDOW) {
// Ensure that we don't draw windows that are offscreen or have
// zero extent.
if (width == 0 || height == 0 || !m_window->is_active()) {
m_window->set_offscreen(true);
return;
}
m_window->set_offscreen(false);
m_window->resize(x, y, width, height);
m_window->mark_dirty();
inline void
Frame::balance_window(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
// Ensure that we don't draw windows that are offscreen or have
// zero extent.
if (width == 0 || height == 0 || !m_window->is_active()) {
m_window->set_offscreen(true);
return;
}
if (width > m_window->max_width()) {
if (m_window->is_left())
x += width - m_window->max_width();
width = m_window->max_width();
}
if (height > m_window->max_height()) {
if (m_window->is_bottom())
y += height - m_window->max_height();
height = m_window->max_height();
}
m_window->set_offscreen(false);
m_window->resize(x, y, width, height);
m_window->mark_dirty();
}
inline void
Frame::balance_row(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
// Find the size of the static frames. The dynamic frames are added
// to a temporary list for the second pass. Each frame uses the
// m_width and m_height as temporary storage for width and height in
// this algorithm.
size_type dynamicSize = 0;
Frame* dynamicFrames[max_size];
size_type dynamicSize = 0;
dynamic_type dynamicFrames[max_size];
int remaining = m_type == TYPE_ROW ? height : width;
int remaining = height;
for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) {
pair_type p = (*itr)->preferred_size();
(*itr)->m_width = p.first;
(*itr)->m_height = p.second;
bounds_type bounds = (*itr)->preferred_size();
if ((*itr)->is_height_dynamic()) {
(*itr)->m_height = 0;
dynamicFrames[dynamicSize++] = std::make_pair(*itr, bounds);
if ((m_type == TYPE_ROW && (*itr)->is_height_dynamic()) || (m_type == TYPE_COLUMN && (*itr)->is_width_dynamic()))
dynamicFrames[dynamicSize++] = *itr;
else
remaining -= m_type == TYPE_ROW ? p.second : p.first;
} else {
(*itr)->m_height = bounds.minHeight;
remaining -= bounds.minHeight;
}
}
// Sort the dynamic frames by the min size in the direction we are
@@ -292,42 +362,122 @@ Frame::balance(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
// following frames.
//
// Else if we're short, only give each what they require.
std::sort(dynamicFrames, dynamicFrames + dynamicSize,
rak::greater2(rak::on(rak::const_mem_ref(&dynamic_type::second), rak::const_mem_ref(&Frame::bounds_type::minHeight)),
rak::on(rak::const_mem_ref(&dynamic_type::second), rak::const_mem_ref(&Frame::bounds_type::minHeight))));
if (m_type == TYPE_ROW)
std::sort(dynamicFrames, dynamicFrames + dynamicSize, rak::greater2(rak::mem_ptr(&Frame::m_height), rak::mem_ptr(&Frame::m_height)));
else
std::sort(dynamicFrames, dynamicFrames + dynamicSize, rak::greater2(rak::mem_ptr(&Frame::m_width), rak::mem_ptr(&Frame::m_width)));
bool retry;
for (Frame **itr = dynamicFrames, **last = dynamicFrames + dynamicSize; itr != last; ++itr, --dynamicSize) {
uint32_t s = std::max<uint32_t>((std::max(remaining, 0) + dynamicSize - 1) / dynamicSize,
m_type == TYPE_ROW ? (*itr)->m_height : (*itr)->m_width);
do {
retry = false;
for (dynamic_type *itr = dynamicFrames, *last = dynamicFrames + dynamicSize; itr != last; ++itr) {
uint32_t adjust = (std::max(remaining, 0) + std::distance(itr, last) - 1) / std::distance(itr, last);
remaining -= s;
if (m_type == TYPE_ROW)
(*itr)->m_height = s;
else
(*itr)->m_width = s;
}
adjust += itr->first->m_height;
adjust = std::max(adjust, itr->second.minHeight);
adjust = std::min(adjust, itr->second.maxHeight);
remaining -= adjust - itr->first->m_height;
retry = retry || itr->first->m_height != adjust;
itr->first->m_height = adjust;
}
} while (retry && remaining > 0);
// Use the pre-calculated frame sizes to balance the sub-frames. If
// the frame is too small, it will set the remaining windows to zero
// extent which will flag them as offscreen.
for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) {
if (m_type == TYPE_ROW) {
(*itr)->balance(x, y, m_width, std::min((*itr)->m_height, height));
// If there is any remaining space, check if we want to shift
// the subsequent frames to the other side of this frame.
if (remaining > 0 && (*itr)->has_bottom_frame()) {
(*itr)->m_height += remaining;
remaining = 0;
}
y += (*itr)->m_height;
height -= (*itr)->m_height;
(*itr)->balance(x, y, m_width, std::min((*itr)->m_height, height));
y += (*itr)->m_height;
height -= (*itr)->m_height;
}
}
inline void
Frame::balance_column(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
// Find the size of the static frames. The dynamic frames are added
// to a temporary list for the second pass. Each frame uses the
// m_width and m_height as temporary storage for width and height in
// this algorithm.
size_type dynamicSize = 0;
dynamic_type dynamicFrames[max_size];
int remaining = width;
for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) {
bounds_type bounds = (*itr)->preferred_size();
if ((*itr)->is_width_dynamic()) {
(*itr)->m_width = 0;
dynamicFrames[dynamicSize++] = std::make_pair(*itr, bounds);
} else {
(*itr)->balance(x, y, std::min((*itr)->m_width, width), m_height);
x += (*itr)->m_width;
width -= (*itr)->m_width;
(*itr)->m_width = bounds.minWidth;
remaining -= bounds.minWidth;
}
}
// Sort the dynamic frames by the min size in the direction we are
// interested in. Then try to satisfy the largest first, and if we
// have any remaining space we can use that to extend it and any
// following frames.
//
// Else if we're short, only give each what they require.
std::sort(dynamicFrames, dynamicFrames + dynamicSize,
rak::greater2(rak::on(rak::const_mem_ref(&dynamic_type::second), rak::const_mem_ref(&Frame::bounds_type::minWidth)),
rak::on(rak::const_mem_ref(&dynamic_type::second), rak::const_mem_ref(&Frame::bounds_type::minWidth))));
bool retry;
do {
retry = false;
for (dynamic_type *itr = dynamicFrames, *last = dynamicFrames + dynamicSize; itr != last; ++itr) {
uint32_t adjust = (std::max(remaining, 0) + std::distance(itr, last) - 1) / std::distance(itr, last);
adjust += itr->first->m_width;
adjust = std::max(adjust, itr->second.minWidth);
adjust = std::min(adjust, itr->second.maxWidth);
remaining -= adjust - itr->first->m_width;
retry = retry || itr->first->m_width != adjust;
itr->first->m_width = adjust;
}
} while (retry && remaining > 0);
// Use the pre-calculated frame sizes to balance the sub-frames. If
// the frame is too small, it will set the remaining windows to zero
// extent which will flag them as offscreen.
for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) {
// If there is any remaining space, check if we want to shift
// the subsequent frames to the other side of this frame.
if (remaining > 0 && (*itr)->has_left_frame()) {
(*itr)->m_width += remaining;
remaining = 0;
}
(*itr)->balance(x, y, std::min((*itr)->m_width, width), m_height);
y += (*itr)->m_width;
width -= (*itr)->m_width;
}
}
}