diff options
author | yangsu@google.com <yangsu@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-08-02 13:39:12 +0000 |
---|---|---|
committer | yangsu@google.com <yangsu@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-08-02 13:39:12 +0000 |
commit | 921091f29e2ecfec55f4d1ac5611b4aa4731e7d6 (patch) | |
tree | b69f4dd41cb0f5db5be7fac4a26fdd9ddbbc5444 /samplecode | |
parent | e938b19445155f71197aac003ea914f59645c471 (diff) |
Set up global options for SampleApp and now allows SampleApp to request menu items from the slides
http://codereview.appspot.com/4807056/
git-svn-id: http://skia.googlecode.com/svn/trunk@2024 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleApp.cpp | 109 | ||||
-rw-r--r-- | samplecode/SampleApp.h | 14 | ||||
-rw-r--r-- | samplecode/SampleCode.h | 10 |
3 files changed, 124 insertions, 9 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index f548b60046..0d70f660df 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -431,13 +431,32 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev fFatBitsScale = 8; fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold); fShowZoomer = false; - + fZoomLevel = 0; fZoomScale = SK_Scalar1; fSaveToPdf = false; fPdfCanvas = NULL; + int sinkID = this->getSinkID(); + fAppMenu.setTitle("Global Settings"); + fAppMenu.appendList("Device Type", "Device Type", sinkID, 0, "Raster", "Picture", "OpenGL", NULL); + fAppMenu.appendTriState("AA", "AA", sinkID, SkOSMenu::kMixedState); + fAppMenu.appendTriState("LCD", "LCD", sinkID, SkOSMenu::kMixedState); + fAppMenu.appendTriState("Filter", "Filter", sinkID, SkOSMenu::kMixedState); + fAppMenu.appendTriState("Hinting", "Hinting", sinkID, SkOSMenu::kMixedState); + fAppMenu.appendSwitch("Pipe", "Pipe" , sinkID, fUsePipe); + fAppMenu.appendSwitch("Slide Show", "Slide Show" , sinkID, false); + fAppMenu.appendSwitch("Clip", "Clip" , sinkID, fUseClip); + fAppMenu.appendSwitch("Measure FPS", "Measure FPS" , sinkID, fMeasureFPS); + fAppMenu.appendSwitch("Flip X", "Flip X" , sinkID, false); + fAppMenu.appendSwitch("Flip Y", "Flip Y" , sinkID, false); + fAppMenu.appendSwitch("Zoomer", "Zoomer" , sinkID, fShowZoomer); + fAppMenu.appendAction("Save to PDF", sinkID); + + this->addMenu(&fAppMenu); + this->addMenu(&fSlideMenu); + // this->setConfig(SkBitmap::kRGB_565_Config); this->setConfig(SkBitmap::kARGB_8888_Config); this->setVisibleP(true); @@ -578,7 +597,7 @@ void SampleWindow::draw(SkCanvas* canvas) { m.preTranslate(-cx, -cy); canvas->concat(m); } - + // Apply any gesture matrix if (true) { const SkMatrix& localM = fGesture.localM(); @@ -592,7 +611,7 @@ void SampleWindow::draw(SkCanvas* canvas) { this->inval(NULL); } } - + if (fNClip) { this->INHERITED::draw(canvas); SkBitmap orig = capture_bitmap(canvas); @@ -629,7 +648,7 @@ void SampleWindow::draw(SkCanvas* canvas) { if (fShowZoomer && !fSaveToPdf) { showZoomer(canvas); } - + // do this last fDevManager->publishCanvas(fDeviceType, canvas, this); } @@ -1005,6 +1024,70 @@ bool SampleWindow::onEvent(const SkEvent& evt) { this->inval(NULL); return true; } + int selected = -1; + if (SkOSMenu::FindListIndex(&evt, "Device Type", &selected)) { + this->setDeviceType((DeviceType)selected); + return true; + } + SkOSMenu::TriState state; + if (SkOSMenu::FindTriState(&evt, "AA", &state)) { + fAAState = (SkTriState)state; + this->updateTitle(); + this->inval(NULL); + } + if (SkOSMenu::FindTriState(&evt, "LCD", &state)) { + fLCDState = (SkTriState)state; + this->updateTitle(); + this->inval(NULL); + } + if (SkOSMenu::FindTriState(&evt, "Filter", &state)) { + fFilterState = (SkTriState)state; + this->updateTitle(); + this->inval(NULL); + } + if (SkOSMenu::FindTriState(&evt, "Hinting", &state)) { + fHintingState = (SkTriState)state; + this->updateTitle(); + this->inval(NULL); + } + if (SkOSMenu::FindSwitchState(&evt, "Pipe", NULL)) { + this->togglePipe(); + return true; + } + if (SkOSMenu::FindSwitchState(&evt, "Slide Show", NULL)) { + this->toggleSlideshow(); + return true; + } + if (SkOSMenu::FindSwitchState(&evt, "Clip", NULL)) { + fUseClip = !fUseClip; + this->inval(NULL); + this->updateTitle(); + return true; + } + if (SkOSMenu::FindSwitchState(&evt, "Measure FPS", NULL)) { + this->toggleFPS(); + return true; + } + if (SkOSMenu::FindSwitchState(&evt, "Flip X", NULL)) { + fFlipAxis ^= kFlipAxis_X; + this->updateTitle(); + this->inval(NULL); + return true; + } + if (SkOSMenu::FindSwitchState(&evt, "Flip Y", NULL)) { + fFlipAxis ^= kFlipAxis_Y; + this->updateTitle(); + this->inval(NULL); + return true; + } + if (SkOSMenu::FindSwitchState(&evt, "Zoomer", NULL)) { + this->toggleZoomer(); + return true; + } + if (SkOSMenu::FindAction(&evt,"Save to PDF")) { + this->saveToPdf(); + return true; + } return this->INHERITED::onEvent(evt); } @@ -1169,6 +1252,13 @@ bool SampleWindow::onHandleChar(SkUnichar uni) { return this->INHERITED::onHandleChar(uni); } +void SampleWindow::setDeviceType(DeviceType type) { + if (type != fDeviceType && fDevManager->supportsDeviceType(fDeviceType)) + fDeviceType = type; + this->updateTitle(); + this->inval(NULL); +} + void SampleWindow::toggleFPS() { fMeasureFPS = !fMeasureFPS; this->inval(NULL); @@ -1191,6 +1281,11 @@ void SampleWindow::toggleRendering() { this->inval(NULL); } +void SampleWindow::togglePipe() { + fUsePipe = !fUsePipe; + this->updateTitle(); +} + #include "SkDumpCanvas.h" bool SampleWindow::onHandleKey(SkKey key) { @@ -1326,6 +1421,12 @@ void SampleWindow::loadView(SkView* view) { this->attachChildToFront(view)->unref(); view->setSize(this->width(), this->height()); + //repopulate the slide menu when a view is loaded + fSlideMenu.reset(); + if (SampleView::IsSampleView(view)) + ((SampleView*)view)->requestMenus(&fSlideMenu); + this->onUpdateMenu(&fSlideMenu); + this->updateTitle(); } diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 43b979943b..b3f3c9334d 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -18,6 +18,7 @@ #include "SkTDArray.h" #include "SkTouchGesture.h" #include "SkWindow.h" +#include "SkOSMenu.h" class GrContext; class GrRenderTarget; @@ -29,9 +30,9 @@ class SkTypeface; class SkData; enum SkTriState { - kFalse_SkTriState, - kTrue_SkTriState, - kUnknown_SkTriState, + kFalse_SkTriState = SkOSMenu::kOffState, + kTrue_SkTriState = SkOSMenu::kOnState, + kUnknown_SkTriState = SkOSMenu::kMixedState, }; class SampleWindow : public SkOSWindow { @@ -83,9 +84,11 @@ public: virtual void draw(SkCanvas* canvas); + void setDeviceType(DeviceType type); void toggleRendering(); void toggleSlideshow(); void toggleFPS(); + void togglePipe(); GrContext* getGrContext() const { return fDevManager->getGrContext(); } @@ -167,6 +170,11 @@ private: int fScrollTestX, fScrollTestY; SkScalar fZoomCenterX, fZoomCenterY; + //Stores global settings + SkOSMenu fAppMenu; + //Stores slide specific settings + SkOSMenu fSlideMenu; + void loadView(SkView*); void updateTitle(); diff --git a/samplecode/SampleCode.h b/samplecode/SampleCode.h index 7bc1c516f1..c22533aa28 100644 --- a/samplecode/SampleCode.h +++ b/samplecode/SampleCode.h @@ -12,7 +12,7 @@ #include "SkEvent.h" #include "SkKey.h" #include "SkView.h" - +class SkOSMenu; class GrContext; class SampleCode { @@ -69,11 +69,17 @@ public: static bool IsSampleView(SkView*); static bool SetRepeatDraw(SkView*, int count); static bool SetUsePipe(SkView*, bool); + + //call this to request menu items from a SampleView. A SampleView can + //overwrite this method to add new items of various types to the menu and + //change its title. The events attached to any new menu items must be + //handled in the onEvent method. See SkOSMenu.h for helper functions. + virtual void requestMenus(SkOSMenu* menu) {} protected: virtual void onDrawBackground(SkCanvas*); virtual void onDrawContent(SkCanvas*) = 0; - + // overrides virtual bool onEvent(const SkEvent& evt); virtual bool onQuery(SkEvent* evt); |