post event to ourself to update the title after our constructor
(so we can see the title of the first slide)
git-svn-id: http://skia.googlecode.com/svn/trunk@2625 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 2578696..aeb71ad 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -74,6 +74,10 @@
static SampleWindow* gSampleWindow;
+static void postEventToSink(SkEvent* evt, SkEventSink* sink) {
+ evt->setTargetID(sink->getSinkID())->post();
+}
+
///////////////
class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager {
public:
@@ -386,6 +390,7 @@
static const char gTitleEvtName[] = "SampleCode_Title_Event";
static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event";
static const char gFastTextEvtName[] = "SampleCode_FastText_Event";
+static const char gUpdateWindowTitleEvtName[] = "SampleCode_UpdateWindowTitle";
bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) {
if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) {
@@ -666,6 +671,12 @@
if (this->height() && this->width()) {
this->onSizeChange();
}
+
+ // can't call this synchronously, since it may require a subclass to
+ // to implement, or the caller may need us to have returned from the
+ // constructor first. Hence we post an event to ourselves.
+// this->updateTitle();
+ postEventToSink(new SkEvent(gUpdateWindowTitleEvtName), this);
}
SampleWindow::~SampleWindow() {
@@ -1258,6 +1269,10 @@
}
}
bool SampleWindow::onEvent(const SkEvent& evt) {
+ if (evt.isType(gUpdateWindowTitleEvtName)) {
+ this->updateTitle();
+ return true;
+ }
if (evt.isType(ANIMATING_EVENTTYPE)) {
if (fAnimating) {
this->nextSample();