Cleaned up handling of what things should be drawn by using the DrawWhat enumeration type.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1072 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-06 03:05:40 +00:00
parent 6c782bb033
commit b586790421
16 changed files with 113 additions and 82 deletions
+5 -5
View File
@@ -18,6 +18,7 @@ DECLARE_TYPEOF_COLLECTION(wxPoint);
IMPLEMENT_VALUE_VIEWER(Image);
void ImageValueViewer::draw(RotatedDC& dc) {
DrawWhat what = viewer.drawWhat(this);
// reset?
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
int a = dc.trAngle(0); //% TODO : Add getAngle()?
@@ -45,8 +46,8 @@ void ImageValueViewer::draw(RotatedDC& dc) {
if (!image.Ok() && style().default_image.isReady()) {
image = style().default_image.generate(GeneratedImage::Options(w, h, &getStylePackage(), &getLocalPackage()));
is_default = true;
if (viewer.drawEditing()) {
bitmap = imagePlaceholder(dc, w, h, image, viewer.drawEditing());
if (what & DRAW_EDITING) {
bitmap = imagePlaceholder(dc, w, h, image, what & DRAW_EDITING);
if (alpha_mask || a) {
image = bitmap.ConvertToImage(); // we need to convert back to an image
} else {
@@ -57,7 +58,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
// checkerboard placeholder
if (!image.Ok() && !bitmap.Ok() && style().width > 40) {
// placeholder bitmap
bitmap = imagePlaceholder(dc, w, h, wxNullImage, viewer.drawEditing());
bitmap = imagePlaceholder(dc, w, h, wxNullImage, what & DRAW_EDITING);
if (alpha_mask || a) {
// we need to convert back to an image
image = bitmap.ConvertToImage();
@@ -83,8 +84,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
void ImageValueViewer::drawFieldBorder(RotatedDC& dc) {
if (!alpha_mask) {
ValueViewer::drawFieldBorder(dc);
} else if (viewer.drawBorders() && field().editable) {
dc.SetPen(viewer.borderPen(isCurrent()));
} else if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points;
alpha_mask->convexHull(points);
+4 -8
View File
@@ -32,14 +32,10 @@ void TextValueViewer::draw(RotatedDC& dc) {
v.prepare(dc, value().value(), style(), viewer.getContext());
dc.setStretch(getStretch());
}
if (viewer.drawFocus() && isCurrent()) {
v.draw(dc, style(), DRAW_ACTIVE);
}
if (viewer.drawBorders()) dc.SetPen(viewer.borderPen(isCurrent()));
v.draw(dc, style(), (DrawWhat)(
DRAW_NORMAL
| (viewer.drawBorders() ? DRAW_BORDERS : 0)
));
DrawWhat what = viewer.drawWhat(this);
v.draw(dc, style(), (DrawWhat)(what & DRAW_ACTIVE));
setFieldBorderPen(dc);
v.draw(dc, style(), (DrawWhat)(what & ~DRAW_ACTIVE));
}
void TextValueViewer::onValueChange() {
+13 -3
View File
@@ -40,9 +40,19 @@ Rotation ValueViewer::getRotation() const {
return Rotation(getStyle()->angle, getStyle()->getExternalRect(), 1.0, getStretch());
}
bool ValueViewer::setFieldBorderPen(RotatedDC& dc) {
if (!getField()->editable) return false;
DrawWhat what = viewer.drawWhat(this);
if (!(what & DRAW_BORDERS)) return false;
dc.SetPen( (what & DRAW_ACTIVE)
? wxPen(Color(0,128,255), 1, wxSOLID)
: wxPen(Color(128,128,128), 1, wxDOT)
);
return true;
}
void ValueViewer::drawFieldBorder(RotatedDC& dc) {
if (viewer.drawBorders() && getField()->editable) {
dc.SetPen(viewer.borderPen(isCurrent()));
if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(dc.getInternalRect().grow(dc.trInvS(1)));
}
@@ -56,7 +66,7 @@ bool ValueViewer::nativeLook() const {
return viewer.nativeLook();
}
bool ValueViewer::isCurrent() const {
return viewer.focusedViewer() == this;
return viewer.viewerIsCurrent(this);
}
void ValueViewer::onStyleChange(int changes) {
+2
View File
@@ -75,6 +75,8 @@ class ValueViewer : public StyleListener {
protected:
ValueP valueP; ///< The value we are currently viewing
/// Set the pen for drawing the border, returns true if a border needs to be drawn
bool setFieldBorderPen(RotatedDC& dc);
/// Draws a border around the field
void drawFieldBorder(RotatedDC& dc);