On Monday 08 July 2002 1:17 pm, Juergen Vigna wrote: > Angus Leeming wrote: > > Could you two great minds think of ways of improving the interface to do > > what we'd like to do. The rest should be hidden inside the > > implementation. > > Well I cannot comment on your implementation (I don't have the time > to look over it in detail), but I will give you a realtime example > of what I think and why it should be in BufferView. > > Think of being Andre opening your workfile and scrolling till the > end of the document. What should happens now: > > 1. All previews/graphics should be converted to a loadable format > > 2. I would like to display the part of the graphics I'm actually in > and am not interested to wait till all other graphics I passed > truth are displayed to. > > 3. Only the really needed graphics should be loaded and displayed > > 4. Who knows about where I am in the document? Yes ONLY LyXText > which is part of the BufferView and BufferView is generally > the passed pointer. > > 5. BufferView should now after I stopped scrolling for "n" bits > of defined time request the loading of the graphic segments > I'm displaying right now. For this it should advise the insets > actually displayed to load it's graphics and fix it's width > (if it differs from the saved one which could be). > > 6. We have to do a rebreak of the text starting at the first displayed > paragraph-row. > > 7. We have to redraw the screen. > > That is how I see it. But please fill in the gaps how you would see > the whole process and where I'm wrong. > > Jug
I don't think you're wrong. I'd just like to implement it so that the Inset does as little as possible. I think I see how we'd do this, but I need your help to turn it into working code. The plan ======= 1. Don't load all image files once they are converted. 2. insets ascertain whether they should use the previewed image with void InsetFormula::draw(BufferView * bv, LyXFont const & font, int y, float & xx, bool) const { if (preview_->usePreview()) { pi.pain.image(x + 1, y - a + 1, w - 2, h - 2, *(preview_->pimage_->image())); ... } If we modify this usePreview call, we can use that to invode startLoading, albeit without the inset knowing anything about this. Within, InsetFormula::usePreview is: bool InsetFormula::PreviewImpl::usePreview() const { // If the cached grfx::PreviewImage is invalid, update it. string const snippet = latexString(); if (!pimage_ || snippet != pimage_->snippet()) { grfx::PreviewLoader & ploader = grfx::Previews::get().loader(view->buffer()); pimage_ = ploader.preview(snippet); } if (!pimage_) return false; return pimage_->image(); } So, we already have the mechanism to trigger the loading of the image. Just modify PreviewLoader::preview to something like: PreviewImage const * PreviewLoader::Impl::preview(string const & latex_snippet, Inset * inset) const { Cache::const_iterator it = cache_.find(latex_snippet); PreviewImage const * pimage = (it == cache_.end()) ? 0 : it->second.get(); + // psuedo code + if (pimage && pimage->status() == WaitingToLoad) { + // call checkVisibility(inset) in 2 secs time + startTimer(2, inset, pimage, &PreviewImage::checkVisibility) + } + return pimage; } void PreviewImage::checkVisibility(Inset * inset) { if (!inset || iloader_->status() != WaitingToLoad) return; if (!inset->isVisible()) return; image->startLoading(); } So,, Jürgen, what should I use for "inset->isVisible()". I have a Buffer & at my disposal. Angus