2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-08-12 14:27:47 +00:00
|
|
|
#include "DebuggerViews.h"
|
2011-06-16 20:49:55 +00:00
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
DebuggerCommandsView::DebuggerCommandsView() {
|
2011-06-16 20:49:55 +00:00
|
|
|
fBGColor = 0xFFBBBBBB;
|
|
|
|
fTopIndex = 0;
|
|
|
|
fHighlight = 0;
|
2011-08-12 14:27:47 +00:00
|
|
|
fResizing = false;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-06-16 20:49:55 +00:00
|
|
|
SkPaint p;
|
2011-08-12 14:27:47 +00:00
|
|
|
p.setTextSize(SkIntToScalar(SKDEBUGGER_TEXTSIZE));
|
2011-06-16 20:49:55 +00:00
|
|
|
fSpacing = p.getFontSpacing();
|
|
|
|
fCentered = false;
|
|
|
|
fRange = (int)(this->height()/fSpacing) - 1;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
DebuggerCommandsView::~DebuggerCommandsView() {
|
|
|
|
fList.deleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DebuggerCommandsView::onEvent(const SkEvent& evt) {
|
|
|
|
if (evt.isType(SKDEBUGGER_COMMANDTYPE)) {
|
|
|
|
*fList.append() = new SkString(evt.findString(SKDEBUGGER_ATOM));
|
2011-06-16 20:49:55 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
void DebuggerCommandsView::onSizeChange() {
|
|
|
|
fRange = (int)(this->height()/fSpacing);
|
2011-06-16 20:49:55 +00:00
|
|
|
this->INHERITED::onSizeChange();
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
void DebuggerCommandsView::alignCenter() {
|
|
|
|
if (!fCentered || fHighlight < fRange/2 || fHighlight > (fList.count() - fRange/2)) {
|
2011-06-16 20:49:55 +00:00
|
|
|
return;
|
2011-08-12 14:27:47 +00:00
|
|
|
} else {
|
2012-08-23 18:14:13 +00:00
|
|
|
if (fHighlight > (fTopIndex + fRange/2))
|
2011-06-16 20:49:55 +00:00
|
|
|
fTopIndex += fHighlight - (fTopIndex + fRange/2);
|
2011-08-12 14:27:47 +00:00
|
|
|
if (fHighlight < (fTopIndex + fRange/2))
|
2011-06-16 20:49:55 +00:00
|
|
|
fTopIndex -= (fTopIndex + fRange/2) - fHighlight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
int DebuggerCommandsView::nextItem() {
|
|
|
|
if (fHighlight < fList.count() - 1)
|
2011-06-16 20:49:55 +00:00
|
|
|
++fHighlight;
|
2011-08-12 14:27:47 +00:00
|
|
|
if (fHighlight < fTopIndex || fHighlight > (fTopIndex + fRange))
|
2011-06-16 20:49:55 +00:00
|
|
|
fTopIndex = fHighlight;
|
2011-08-12 14:27:47 +00:00
|
|
|
if (fHighlight == (fTopIndex + fRange))
|
2011-06-16 20:49:55 +00:00
|
|
|
++fTopIndex;
|
|
|
|
this->alignCenter();
|
|
|
|
this->inval(NULL);
|
|
|
|
return fHighlight;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
int DebuggerCommandsView::prevItem() {
|
2011-06-16 20:49:55 +00:00
|
|
|
if (fHighlight > 0)
|
|
|
|
--fHighlight;
|
2011-08-12 14:27:47 +00:00
|
|
|
if (fHighlight < fTopIndex || fHighlight > (fTopIndex + fRange))
|
2011-06-16 20:49:55 +00:00
|
|
|
fTopIndex = fHighlight;
|
|
|
|
this->alignCenter();
|
|
|
|
this->inval(NULL);
|
|
|
|
return fHighlight;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
int DebuggerCommandsView::scrollUp() {
|
2011-06-16 20:49:55 +00:00
|
|
|
if (fTopIndex > 0)
|
|
|
|
--fTopIndex;
|
|
|
|
this->inval(NULL);
|
|
|
|
return fHighlight;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
int DebuggerCommandsView::scrollDown() {
|
|
|
|
if (fTopIndex < (fList.count() - 1))
|
2011-06-16 20:49:55 +00:00
|
|
|
++fTopIndex;
|
|
|
|
this->inval(NULL);
|
|
|
|
return fHighlight;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
void DebuggerCommandsView::highlight(int index) {
|
|
|
|
SkASSERT(index >= 0 && index < fList.count());
|
2011-06-16 20:49:55 +00:00
|
|
|
if (fHighlight != index) {
|
|
|
|
fHighlight = index;
|
|
|
|
this->alignCenter();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
int DebuggerCommandsView::selectHighlight(int ypos) {
|
2011-06-16 20:49:55 +00:00
|
|
|
int i = (int)(ypos/fSpacing) + fTopIndex;
|
2011-08-12 14:27:47 +00:00
|
|
|
if (i >= fList.count()) {
|
|
|
|
i = fList.count() - 1;
|
2011-06-16 20:49:55 +00:00
|
|
|
}
|
|
|
|
if (fHighlight != i) {
|
|
|
|
fHighlight = i;
|
|
|
|
this->alignCenter();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
return fHighlight;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
void DebuggerCommandsView::toggleCentered() {
|
2011-06-16 20:49:55 +00:00
|
|
|
fCentered = !fCentered;
|
|
|
|
this->alignCenter();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
void DebuggerCommandsView::onDraw(SkCanvas* canvas) {
|
2011-06-16 20:49:55 +00:00
|
|
|
canvas->drawColor(fBGColor);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-06-16 20:49:55 +00:00
|
|
|
SkPaint p;
|
2011-08-12 14:27:47 +00:00
|
|
|
p.setTextSize(SkIntToScalar(SKDEBUGGER_TEXTSIZE));
|
2011-06-16 20:49:55 +00:00
|
|
|
p.setAntiAlias(true);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-06-16 20:49:55 +00:00
|
|
|
//draw highlight
|
|
|
|
int selected = fHighlight - fTopIndex;
|
|
|
|
SkRect r = {0, fSpacing * selected, this->width(), fSpacing * (selected+1)};
|
2011-08-12 14:27:47 +00:00
|
|
|
p.setColor(SKDEBUGGER_HIGHLIGHTCOLOR);
|
2011-06-16 20:49:55 +00:00
|
|
|
canvas->drawRect(r, p);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
|
|
|
int endIndex = fTopIndex + fRange;
|
2011-08-12 14:27:47 +00:00
|
|
|
if (endIndex > fList.count())
|
|
|
|
endIndex = fList.count();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-08-12 14:27:47 +00:00
|
|
|
p.setColor(SKDEBUGGER_TEXTCOLOR);
|
2011-06-16 20:49:55 +00:00
|
|
|
int pos;
|
|
|
|
for (int i = fTopIndex; i < endIndex; ++i) {
|
|
|
|
pos = i - fTopIndex;
|
2012-08-23 18:14:13 +00:00
|
|
|
canvas->drawText(fList[i]->c_str(), fList[i]->size(),
|
2011-06-16 20:49:55 +00:00
|
|
|
0, fSpacing - 2 + fSpacing * pos, p);
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
p.setColor(SKDEBUGGER_RESIZEBARCOLOR);
|
2012-08-23 18:14:13 +00:00
|
|
|
r = SkRect::MakeXYWH(this->width() - SKDEBUGGER_RESIZEBARSIZE, 0,
|
2011-08-12 14:27:47 +00:00
|
|
|
SKDEBUGGER_RESIZEBARSIZE, this->height());
|
|
|
|
canvas->drawRect(r, p);
|
2012-08-14 20:27:54 +00:00
|
|
|
}
|
|
|
|
|