3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
10 * Splash screen code added by Angus Leeming
16 #include "font_metrics.h"
21 #include "BufferView.h"
23 #include "bufferparams.h"
24 #include "coordcache.h"
33 #include "metricsinfo.h"
34 #include "paragraph.h"
35 #include "rowpainter.h"
38 #include "graphics/GraphicsImage.h"
39 #include "graphics/GraphicsLoader.h"
41 #include "support/filetools.h" // LibFileSearch
43 #include <boost/utility.hpp>
44 #include <boost/bind.hpp>
45 #include <boost/signals/trackable.hpp>
47 using lyx::support::libFileSearch;
57 class SplashScreen : boost::noncopyable, boost::signals::trackable {
59 /// This is a singleton class. Get the instance.
60 static SplashScreen const & get();
62 lyx::graphics::Image const * image() const { return loader_.image(); }
64 string const & text() const { return text_; }
66 LyXFont const & font() const { return font_; }
68 void connect(lyx::graphics::Loader::slot_type const & slot) const {
69 loader_.connect(slot);
72 void startLoading() const {
73 if (loader_.status() == lyx::graphics::WaitingToLoad)
74 loader_.startLoading();
78 /** Make the c-tor private so we can control how many objects
84 lyx::graphics::Loader loader_;
85 /// The text to be written on top of the pixmap
92 SplashScreen const & SplashScreen::get()
94 static SplashScreen singleton;
99 SplashScreen::SplashScreen()
100 : text_(lyx_version ? lyx_version : "unknown")
102 if (!lyxrc.show_banner)
105 string const file = libFileSearch("images", "banner", "ppm");
109 // The font used to display the version info
110 font_.setFamily(LyXFont::SANS_FAMILY);
111 font_.setSeries(LyXFont::BOLD_SERIES);
112 font_.setSize(LyXFont::SIZE_NORMAL);
113 font_.setColor(LColor::yellow);
115 // Load up the graphics file
122 LyXScreen::LyXScreen()
123 : greyed_out_(true), cursor_visible_(false)
125 // Start loading the pixmap as soon as possible
126 if (lyxrc.show_banner) {
127 SplashScreen const & splash = SplashScreen::get();
128 splash.connect(boost::bind(&LyXScreen::checkAndGreyOut, this));
129 splash.startLoading();
134 LyXScreen::~LyXScreen()
139 void LyXScreen::checkAndGreyOut()
146 void LyXScreen::showCursor(BufferView & bv)
154 Cursor_Shape shape = BAR_SHAPE;
156 LyXText const & text = *bv.getLyXText();
157 LyXFont const & realfont = text.real_current_font;
158 BufferParams const & bp = bv.buffer()->params();
159 bool const samelang = realfont.language() == bp.language;
160 bool const isrtl = realfont.isVisibleRightToLeft();
162 if (!samelang || isrtl != bp.language->rightToLeft()) {
165 shape = REVERSED_L_SHAPE;
168 // The ERT language hack needs fixing up
169 if (realfont.language() == latex_language)
172 LyXFont const font = bv.cursor().getFont();
173 int const asc = font_metrics::maxAscent(font);
174 int const des = font_metrics::maxDescent(font);
178 bv.cursor().getPos(x, y);
180 //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
182 // if it doesn't touch the screen, don't try to show it
183 if (y + h < 0 || y >= workarea().workHeight())
186 cursor_visible_ = true;
187 showCursor(x, y, h, shape);
191 void LyXScreen::hideCursor()
193 if (!cursor_visible_)
196 cursor_visible_ = false;
201 void LyXScreen::toggleCursor(BufferView & bv)
210 void LyXScreen::prepareCursor()
212 cursor_visible_ = false;
216 void LyXScreen::redraw(BufferView & bv, ViewMetricsInfo const & vi)
219 workarea().getPainter().start();
221 lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
222 int const ymin = std::max(vi.y1, 0);
224 ( vi.p2 < vi.size - 1 ? vi.y2 : workarea().workHeight() );
225 expose(0, ymin, workarea().workWidth(), ymax - ymin);
226 workarea().getPainter().end();
227 theCoords.doneUpdating();
231 void LyXScreen::greyOut()
234 workarea().getPainter().start();
236 workarea().getPainter().fillRectangle(0, 0,
237 workarea().workWidth(),
238 workarea().workHeight(),
241 // Add a splash screen to the centre of the work area
242 SplashScreen const & splash = SplashScreen::get();
243 lyx::graphics::Image const * const splash_image = splash.image();
245 int const w = splash_image->getWidth();
246 int const h = splash_image->getHeight();
248 int x = (workarea().workWidth() - w) / 2;
249 int y = (workarea().workHeight() - h) / 2;
251 workarea().getPainter().image(x, y, w, h, *splash_image);
256 workarea().getPainter().text(x, y, splash.text(), splash.font());
258 expose(0, 0, workarea().workWidth(), workarea().workHeight());
259 workarea().getPainter().end();