mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
fix collapsables drawing problems
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8547 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3f70e153ee
commit
728193eacc
@ -1,3 +1,12 @@
|
|||||||
|
2004-03-27 Alfredo Braunstein <abraunst@lyx.org>
|
||||||
|
|
||||||
|
* insettext.C (draw): handle the responsability of adding the
|
||||||
|
ouside offset to collapsable. Clean code a bit.
|
||||||
|
|
||||||
|
* insetcollapsable.[Ch] (metrics, draw): handle the derivation
|
||||||
|
from insettext correctly, solve a couple of off-by-one drawing
|
||||||
|
bugs
|
||||||
|
|
||||||
2004-03-25 Angus Leeming <leeming@lyx.org>
|
2004-03-25 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* insetcaption.C (draw): squash warning about unused variable.
|
* insetcaption.C (draw): squash warning about unused variable.
|
||||||
|
@ -119,24 +119,28 @@ void InsetCollapsable::dimension_collapsed(Dimension & dim) const
|
|||||||
|
|
||||||
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
|
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
||||||
if (status_ == Inlined) {
|
if (status_ == Inlined) {
|
||||||
InsetText::metrics(mi, dim);
|
InsetText::metrics(mi, dim);
|
||||||
} else {
|
} else {
|
||||||
dimension_collapsed(dim);
|
dimension_collapsed(dim);
|
||||||
if (status_ == Open) {
|
if (status_ == Open) {
|
||||||
Dimension insetdim;
|
InsetText::metrics(mi, textdim_);
|
||||||
InsetText::metrics(mi, insetdim);
|
openinlined_ = (textdim_.wid + dim.wid <= mi.base.textwidth);
|
||||||
openinlined_ = (insetdim.wid + dim.wid <= mi.base.textwidth);
|
|
||||||
if (openinlined_) {
|
if (openinlined_) {
|
||||||
dim.wid += insetdim.wid;
|
dim.wid += textdim_.wid;
|
||||||
dim.des = max(dim.des, insetdim.des);
|
dim.des = max(dim.des, textdim_.des);
|
||||||
dim.asc = max(dim.asc, insetdim.asc);
|
dim.asc = max(dim.asc, textdim_.asc);
|
||||||
} else {
|
} else {
|
||||||
dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
|
dim.des += textdim_.height() + TEXT_TO_BOTTOM_OFFSET;
|
||||||
dim.wid = max(dim.wid, insetdim.wid);
|
dim.wid = max(dim.wid, textdim_.wid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
||||||
|
dim.des += TEXT_TO_INSET_OFFSET;
|
||||||
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
||||||
|
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
||||||
dim_ = dim;
|
dim_ = dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +153,8 @@ void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
|
|||||||
|
|
||||||
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
setPosCache(pi, x, y);
|
x += TEXT_TO_INSET_OFFSET;
|
||||||
|
y += TEXT_TO_INSET_OFFSET;
|
||||||
|
|
||||||
if (status_ == Inlined) {
|
if (status_ == Inlined) {
|
||||||
InsetText::draw(pi, x, y);
|
InsetText::draw(pi, x, y);
|
||||||
@ -162,15 +167,17 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
|
|||||||
button_dim.y1 = y - aa + pi.base.bv->top_y();
|
button_dim.y1 = y - aa + pi.base.bv->top_y();
|
||||||
button_dim.y2 = y - aa + pi.base.bv->top_y() + dimc.height();
|
button_dim.y2 = y - aa + pi.base.bv->top_y() + dimc.height();
|
||||||
|
|
||||||
draw_collapsed(pi, x, y);
|
draw_collapsed(pi, x, y - aa + dimc.asc);
|
||||||
if (status_ == Open) {
|
if (status_ == Open) {
|
||||||
x += scroll();
|
|
||||||
if (openinlined_)
|
if (openinlined_)
|
||||||
InsetText::draw(pi, x + dimc.width(), y - aa + InsetText::ascent());
|
InsetText::draw(pi, x + dimc.width(),
|
||||||
|
y - aa + textdim_.asc);
|
||||||
else
|
else
|
||||||
InsetText::draw(pi, x, y - aa + dimc.height() + InsetText::ascent());
|
InsetText::draw(pi, x, dimc.height()
|
||||||
|
+ y - aa + textdim_.asc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setPosCache(pi, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,6 +119,8 @@ private:
|
|||||||
mutable CollapseStatus status_;
|
mutable CollapseStatus status_;
|
||||||
/// a substatus of the Open status, determined automatically in metrics
|
/// a substatus of the Open status, determined automatically in metrics
|
||||||
mutable bool openinlined_;
|
mutable bool openinlined_;
|
||||||
|
///
|
||||||
|
mutable Dimension textdim_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -174,12 +174,7 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
{
|
{
|
||||||
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
|
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
|
||||||
setViewCache(mi.base.bv);
|
setViewCache(mi.base.bv);
|
||||||
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
|
||||||
text_.metrics(mi, dim);
|
text_.metrics(mi, dim);
|
||||||
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
||||||
dim.des += TEXT_TO_INSET_OFFSET;
|
|
||||||
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
|
||||||
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
|
||||||
dim_ = dim;
|
dim_ = dim;
|
||||||
font_ = mi.base.font;
|
font_ = mi.base.font;
|
||||||
text_.font_ = mi.base.font;
|
text_.font_ = mi.base.font;
|
||||||
@ -192,21 +187,20 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
|
|||||||
// update our idea of where we are
|
// update our idea of where we are
|
||||||
setPosCache(pi, x, y);
|
setPosCache(pi, x, y);
|
||||||
|
|
||||||
// repaint the background if needed
|
|
||||||
x += TEXT_TO_INSET_OFFSET;
|
|
||||||
if (backgroundColor() != LColor::background)
|
|
||||||
clearInset(pi.pain, x, y);
|
|
||||||
|
|
||||||
BufferView * bv = pi.base.bv;
|
BufferView * bv = pi.base.bv;
|
||||||
bv->hideCursor();
|
bv->hideCursor();
|
||||||
|
|
||||||
x += scroll();
|
x += scroll();
|
||||||
y += bv->top_y() - text_.ascent();
|
y -= text_.ascent();
|
||||||
|
|
||||||
text_.draw(pi, x, y);
|
// repaint the background if needed
|
||||||
|
if (backgroundColor() != LColor::background)
|
||||||
|
clearInset(pi.pain, x, y);
|
||||||
|
|
||||||
|
text_.draw(pi, x, y + bv->top_y());
|
||||||
|
|
||||||
if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED)
|
if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED)
|
||||||
drawFrame(pi.pain, xo_, yo_ - bv->top_y());
|
drawFrame(pi.pain, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -218,11 +212,17 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
|
|||||||
|
|
||||||
void InsetText::drawFrame(Painter & pain, int x, int y) const
|
void InsetText::drawFrame(Painter & pain, int x, int y) const
|
||||||
{
|
{
|
||||||
int const frame_x = x + TEXT_TO_INSET_OFFSET / 2;
|
int const w = text_.width();
|
||||||
int const frame_y = y - dim_.asc + TEXT_TO_INSET_OFFSET / 2;
|
int const h = text_.height();
|
||||||
int const frame_w = text_.width();
|
pain.rectangle(x, y, w, h, frameColor());
|
||||||
int const frame_h = text_.height();
|
}
|
||||||
pain.rectangle(frame_x, frame_y, frame_w, frame_h, frameColor());
|
|
||||||
|
|
||||||
|
void InsetText::clearInset(Painter & pain, int x, int y) const
|
||||||
|
{
|
||||||
|
int const w = text_.width();
|
||||||
|
int const h = text_.height();
|
||||||
|
pain.fillRectangle(x, y, w, h, backgroundColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -477,24 +477,6 @@ void InsetText::removeNewlines()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetText::clearInset(Painter & pain, int x, int y) const
|
|
||||||
{
|
|
||||||
int w = dim_.wid;
|
|
||||||
int h = dim_.asc + dim_.des;
|
|
||||||
int ty = y - dim_.asc;
|
|
||||||
|
|
||||||
if (ty < 0) {
|
|
||||||
h += ty;
|
|
||||||
ty = 0;
|
|
||||||
}
|
|
||||||
if (ty + h > pain.paperHeight())
|
|
||||||
h = pain.paperHeight();
|
|
||||||
if (xo_ + w > pain.paperWidth())
|
|
||||||
w = pain.paperWidth();
|
|
||||||
pain.fillRectangle(x + 1, ty + 1, w - 3, h - 1, backgroundColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LyXText * InsetText::getText(int i) const
|
LyXText * InsetText::getText(int i) const
|
||||||
{
|
{
|
||||||
return (i == 0) ? const_cast<LyXText*>(&text_) : 0;
|
return (i == 0) ? const_cast<LyXText*>(&text_) : 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user