add 't' to toggle tiling modes

Review URL: https://codereview.appspot.com/6446138

git-svn-id: http://skia.googlecode.com/svn/trunk@5109 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-08-15 14:41:58 +00:00
parent 5d8d18651a
commit 67b89eeeb0
3 changed files with 55 additions and 2 deletions

View File

@ -792,6 +792,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fScale = false;
fRequestGrabImage = false;
fPipeState = SkOSMenu::kOffState;
fTilingState = SkOSMenu::kOffState;
fMeasureFPS = false;
fLCDState = SkOSMenu::kMixedState;
fAAState = SkOSMenu::kMixedState;
@ -837,9 +838,14 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fAppMenu->assignKeyEquivalentToItem(itemID, 'n');
itemID = fAppMenu->appendTriState("Hinting", "Hinting", sinkID, fHintingState);
fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID,
fPipeState);
fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P');
itemID = fAppMenu->appendTriState("Tiling", "Tiling", sinkID, fTilingState);
fAppMenu->assignKeyEquivalentToItem(itemID, 't');
#ifdef DEBUGGER
itemID = fAppMenu->appendSwitch("Debugger", "Debugger", sinkID, fDebugger);
fAppMenu->assignKeyEquivalentToItem(itemID, 'q');
@ -1618,6 +1624,18 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
this->inval(NULL);
return true;
}
if (SkOSMenu::FindTriState(evt, "Tiling", &fTilingState)) {
int nx = 1, ny = 1;
switch (fTilingState) {
case SkOSMenu::kOffState: nx = 1; ny = 1; break;
case SkOSMenu::kMixedState: nx = 1; ny = 4; break;
case SkOSMenu::kOnState: nx = 2; ny = 2; break;
}
(void)SampleView::SetTileCount(curr_view(this), nx, ny);
this->updateTitle();
this->inval(NULL);
return true;
}
if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) {
this->toggleSlideshow();
return true;
@ -2152,6 +2170,7 @@ void SampleWindow::onSizeChange() {
static const char is_sample_view_tag[] = "sample-is-sample-view";
static const char repeat_count_tag[] = "sample-set-repeat-count";
static const char set_use_pipe_tag[] = "sample-set-use-pipe";
static const char set_tile_count_tag[] = "sample-set-tile-count";
bool SampleView::IsSampleView(SkView* view) {
SkEvent evt(is_sample_view_tag);
@ -2170,11 +2189,22 @@ bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) {
return view->doEvent(evt);
}
bool SampleView::SetTileCount(SkView* view, int nx, int ny) {
SkEvent evt(set_tile_count_tag);
evt.setFast32((ny << 16) | nx);
return view->doEvent(evt);
}
bool SampleView::onEvent(const SkEvent& evt) {
if (evt.isType(repeat_count_tag)) {
fRepeatCount = evt.getFast32();
return true;
}
if (evt.isType(set_tile_count_tag)) {
unsigned packed = evt.getFast32();
fTileCount.set(packed & 0xFFFF, packed >> 16);
return true;
}
int32_t pipeHolder;
if (evt.findS32(set_use_pipe_tag, &pipeHolder)) {
fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder);
@ -2291,11 +2321,30 @@ void SampleView::draw(SkCanvas* canvas) {
void SampleView::onDraw(SkCanvas* canvas) {
this->onDrawBackground(canvas);
const SkScalar cw = this->width() / fTileCount.width();
const SkScalar ch = this->height() / fTileCount.height();
for (int i = 0; i < fRepeatCount; i++) {
for (int y = 0; y < fTileCount.height(); ++y) {
for (int x = 0; x < fTileCount.width(); ++x) {
SkAutoCanvasRestore acr(canvas, true);
canvas->clipRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch));
this->onDrawContent(canvas);
}
}
}
if (!fTileCount.equals(1, 1)) {
SkPaint paint;
paint.setColor(0x60FF00FF);
paint.setStyle(SkPaint::kStroke_Style);
for (int y = 0; y < fTileCount.height(); ++y) {
for (int x = 0; x < fTileCount.width(); ++x) {
canvas->drawRect(SkRect::MakeXYWH(x * cw, y * ch, cw, ch), paint);
}
}
}
}
void SampleView::onDrawBackground(SkCanvas* canvas) {
canvas->drawColor(fBGColor);

View File

@ -180,6 +180,7 @@ private:
SkOSMenu::TriState fAAState;
SkOSMenu::TriState fFilterState;
SkOSMenu::TriState fHintingState;
SkOSMenu::TriState fTilingState;
unsigned fFlipAxis;
int fMSAASampleCount;

View File

@ -109,6 +109,7 @@ class SampleView : public SkView {
public:
SampleView() : fPipeState(SkOSMenu::kOffState),
fBGColor(SK_ColorWHITE), fRepeatCount(1) {
fTileCount.set(1, 1);
}
void setBGColor(SkColor color) { fBGColor = color; }
@ -116,6 +117,7 @@ public:
static bool IsSampleView(SkView*);
static bool SetRepeatDraw(SkView*, int count);
static bool SetUsePipe(SkView*, SkOSMenu::TriState);
static bool SetTileCount(SkView*, int nx, int ny);
/**
* Call this to request menu items from a SampleView.
@ -141,6 +143,7 @@ protected:
private:
int fRepeatCount;
SkISize fTileCount;
typedef SkView INHERITED;
};