mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-10 18:58:10 +00:00
Towards saner generation of previews code. Yeah, I know. I wrote it in
the first place. I was younger then. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7888 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
97a1af408e
commit
760829360d
@ -1,3 +1,8 @@
|
|||||||
|
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* PreviewedInset.[Ch] (previewReady): remove the side effects.
|
||||||
|
Now simply reports whether the preview is ready.
|
||||||
|
|
||||||
2003-10-09 Angus Leeming <leeming@lyx.org>
|
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* PreviewedInset.[Ch]: move PreviewedInset out of namespace lyx::graphics.
|
* PreviewedInset.[Ch]: move PreviewedInset out of namespace lyx::graphics.
|
||||||
|
@ -91,17 +91,8 @@ void PreviewedInset::removePreview(Buffer const & buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PreviewedInset::previewReady(Buffer const & buffer) const
|
bool PreviewedInset::previewReady() const
|
||||||
{
|
{
|
||||||
if (!activated() || !previewWanted(buffer))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!pimage_ || snippet_ != pimage_->snippet()) {
|
|
||||||
graphics::PreviewLoader & ploader =
|
|
||||||
graphics::Previews::get().loader(buffer);
|
|
||||||
pimage_ = ploader.preview(snippet_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pimage_ ? pimage_->image() : false;
|
return pimage_ ? pimage_->image() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
void removePreview(Buffer const &);
|
void removePreview(Buffer const &);
|
||||||
|
|
||||||
/// The preview has been generated and is ready to use.
|
/// The preview has been generated and is ready to use.
|
||||||
bool previewReady(Buffer const &) const;
|
bool previewReady() const;
|
||||||
|
|
||||||
/// If the preview is not ready, returns 0.
|
/// If the preview is not ready, returns 0.
|
||||||
lyx::graphics::PreviewImage const * const pimage() const { return pimage_; }
|
lyx::graphics::PreviewImage const * const pimage() const { return pimage_; }
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* insetinclude.C (metrics, draw): no longer need to pass a Buffer arg
|
||||||
|
to PreviewedInset::previewReady.
|
||||||
|
|
||||||
2003-10-09 Angus Leeming <leeming@lyx.org>
|
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* insetexternal.[Ch] (statusChanged):
|
* insetexternal.[Ch] (statusChanged):
|
||||||
|
@ -539,8 +539,7 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
|
|||||||
|
|
||||||
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
Buffer const * buffer_ptr = mi.base.bv ? mi.base.bv->buffer() : 0;
|
if (preview_->previewReady()) {
|
||||||
if (buffer_ptr && preview_->previewReady(*buffer_ptr)) {
|
|
||||||
dim.asc = preview_->pimage()->ascent();
|
dim.asc = preview_->pimage()->ascent();
|
||||||
dim.des = preview_->pimage()->descent();
|
dim.des = preview_->pimage()->descent();
|
||||||
dim.wid = preview_->pimage()->width();
|
dim.wid = preview_->pimage()->width();
|
||||||
@ -565,10 +564,8 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
void InsetInclude::draw(PainterInfo & pi, int x, int y) const
|
void InsetInclude::draw(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
cache(pi.base.bv);
|
cache(pi.base.bv);
|
||||||
Buffer const * buffer_ptr = pi.base.bv ? pi.base.bv->buffer() : 0;
|
|
||||||
bool const use_preview = buffer_ptr && preview_->previewReady(*buffer_ptr);
|
|
||||||
|
|
||||||
if (!use_preview) {
|
if (!preview_->previewReady()) {
|
||||||
button_.draw(pi, x + button_.box().x1, y);
|
button_.draw(pi, x + button_.box().x1, y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* formula.C (metrics, draw): no longer need to pass a Buffer arg
|
||||||
|
to PreviewedInset::previewReady because it no longer has the side
|
||||||
|
effect of secretly starting preview generation.
|
||||||
|
(draw): call PreviewedInset::generatePreview explicitly if the
|
||||||
|
inset is no longer being edited.
|
||||||
|
|
||||||
2003-10-09 Angus Leeming <leeming@lyx.org>
|
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
* formula.[Ch]: mods to PreviewImpl due to the changes to
|
* formula.[Ch]: mods to PreviewImpl due to the changes to
|
||||||
|
@ -193,11 +193,18 @@ void InsetFormula::read(Buffer const &, LyXLex & lex)
|
|||||||
|
|
||||||
void InsetFormula::draw(PainterInfo & pi, int x, int y) const
|
void InsetFormula::draw(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
cache(pi.base.bv);
|
BufferView * bv = pi.base.bv;
|
||||||
// This initiates the loading of the preview, so should come
|
cache(bv);
|
||||||
// before the metrics are computed.
|
|
||||||
Buffer const * buffer_ptr = pi.base.bv ? pi.base.bv->buffer() : 0;
|
// The previews are drawn only when we're not editing the inset.
|
||||||
bool const use_preview = buffer_ptr && preview_->previewReady(*buffer_ptr);
|
bool const editing_inset = mathcursor && mathcursor->formula() == this;
|
||||||
|
bool const use_preview = !editing_inset && preview_->previewReady();
|
||||||
|
|
||||||
|
if (!editing_inset && bv) {
|
||||||
|
Buffer const * buffer_ptr = bv->buffer();
|
||||||
|
if (buffer_ptr)
|
||||||
|
preview_->generatePreview(*buffer_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
int const w = dim_.wid;
|
int const w = dim_.wid;
|
||||||
int const d = dim_.des;
|
int const d = dim_.des;
|
||||||
@ -208,7 +215,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
|
|||||||
pi.pain.image(x + 1, y - a, w, h, // one pixel gap in front
|
pi.pain.image(x + 1, y - a, w, h, // one pixel gap in front
|
||||||
*(preview_->pimage()->image()));
|
*(preview_->pimage()->image()));
|
||||||
} else {
|
} else {
|
||||||
PainterInfo p(pi.base.bv);
|
PainterInfo p(bv);
|
||||||
p.base.style = LM_ST_TEXT;
|
p.base.style = LM_ST_TEXT;
|
||||||
p.base.font = pi.base.font;
|
p.base.font = pi.base.font;
|
||||||
p.base.font.setColor(LColor::math);
|
p.base.font.setColor(LColor::math);
|
||||||
@ -216,9 +223,7 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
|
|||||||
!= lcolor.getX11Name(LColor::background))
|
!= lcolor.getX11Name(LColor::background))
|
||||||
p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
|
p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
|
||||||
|
|
||||||
if (mathcursor &&
|
if (editing_inset) {
|
||||||
const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
|
|
||||||
{
|
|
||||||
mathcursor->drawSelection(pi);
|
mathcursor->drawSelection(pi);
|
||||||
//p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
|
//p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
|
||||||
}
|
}
|
||||||
@ -262,8 +267,11 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const
|
|||||||
void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
|
void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
|
||||||
{
|
{
|
||||||
view_ = m.base.bv;
|
view_ = m.base.bv;
|
||||||
Buffer const * buffer_ptr = m.base.bv ? m.base.bv->buffer() : 0;
|
|
||||||
if (buffer_ptr && preview_->previewReady(*buffer_ptr)) {
|
bool const editing_inset = mathcursor && mathcursor->formula() == this;
|
||||||
|
bool const use_preview = !editing_inset && preview_->previewReady();
|
||||||
|
|
||||||
|
if (use_preview) {
|
||||||
dim.asc = preview_->pimage()->ascent();
|
dim.asc = preview_->pimage()->ascent();
|
||||||
dim.des = preview_->pimage()->descent();
|
dim.des = preview_->pimage()->descent();
|
||||||
// insert a one pixel gap in front of the formula
|
// insert a one pixel gap in front of the formula
|
||||||
|
Loading…
Reference in New Issue
Block a user