3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
11 * Splash screen code added by Angus Leeming
18 #include "font_metrics.h"
22 #include "BufferView.h"
24 #include "bufferparams.h"
25 #include "coordcache.h"
34 #include "metricsinfo.h"
35 #include "paragraph.h"
36 #include "rowpainter.h"
39 #include "graphics/GraphicsImage.h"
40 #include "graphics/GraphicsLoader.h"
42 #include "support/filetools.h" // LibFileSearch
44 #include <boost/utility.hpp>
45 #include <boost/bind.hpp>
46 #include <boost/signals/trackable.hpp>
48 using lyx::support::libFileSearch;
59 class SplashScreen : boost::noncopyable, boost::signals::trackable {
61 /// This is a singleton class. Get the instance.
62 static SplashScreen const & get();
64 lyx::graphics::Image const * image() const { return loader_.image(); }
66 string const & text() const { return text_; }
68 LyXFont const & font() const { return font_; }
70 void connect(lyx::graphics::Loader::slot_type const & slot) const {
71 loader_.connect(slot);
74 void startLoading() const {
75 if (loader_.status() == lyx::graphics::WaitingToLoad)
76 loader_.startLoading();
80 /** Make the c-tor private so we can control how many objects
86 lyx::graphics::Loader loader_;
87 /// The text to be written on top of the pixmap
94 SplashScreen const & SplashScreen::get()
96 static SplashScreen singleton;
101 SplashScreen::SplashScreen()
102 : text_(lyx_version ? lyx_version : "unknown")
104 if (!lyxrc.show_banner)
107 string const file = libFileSearch("images", "banner", "ppm");
111 // The font used to display the version info
112 font_.setFamily(LyXFont::SANS_FAMILY);
113 font_.setSeries(LyXFont::BOLD_SERIES);
114 font_.setSize(LyXFont::SIZE_NORMAL);
115 font_.setColor(LColor::yellow);
117 // Load up the graphics file
121 WorkArea::WorkArea(BufferView * buffer_view)
122 : buffer_view_(buffer_view), greyed_out_(true)
124 // Start loading the pixmap as soon as possible
125 if (lyxrc.show_banner) {
126 SplashScreen const & splash = SplashScreen::get();
127 splash.connect(boost::bind(&WorkArea::checkAndGreyOut, this));
128 splash.startLoading();
133 void WorkArea::setBufferView(BufferView * buffer_view)
135 buffer_view_ = buffer_view;
139 BufferView & WorkArea::bufferView()
141 return *buffer_view_;
145 BufferView const & WorkArea::bufferView() const
147 return *buffer_view_;
151 void WorkArea::checkAndGreyOut()
158 void WorkArea::redraw(BufferView & bv, ViewMetricsInfo const & vi)
161 getPainter().start();
162 paintText(*buffer_view_, vi);
163 lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
164 int const ymin = std::max(vi.y1, 0);
166 ( vi.p2 < vi.size - 1 ? vi.y2 : height() );
167 expose(0, ymin, width(), ymax - ymin);
169 theCoords.doneUpdating();
173 void WorkArea::greyOut()
176 getPainter().start();
178 getPainter().fillRectangle(0, 0,
183 // Add a splash screen to the centre of the work area
184 SplashScreen const & splash = SplashScreen::get();
185 lyx::graphics::Image const * const splash_image = splash.image();
187 int const w = splash_image->getWidth();
188 int const h = splash_image->getHeight();
190 int x = (width() - w) / 2;
191 int y = (height() - h) / 2;
193 getPainter().image(x, y, w, h, *splash_image);
198 getPainter().text(x, y, splash.text(), splash.font());
200 expose(0, 0, width(), height());
204 } // namespace frontend