If all fields for a specific value are set, mark it.
* In this case, the value is drawn a bit less intense than incomplete values. * Make the keyboard focus background color depend on the actual background color. * No longer allow to drag remove random hint values after removing a value from a field.
This commit is contained in:
@@ -251,6 +251,21 @@ SudokuField::IsEmpty() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
SudokuField::IsValueCompleted(uint32 value) const
|
||||||
|
{
|
||||||
|
uint32 count = 0;
|
||||||
|
for (uint32 y = 0; y < fSize; y++) {
|
||||||
|
for (uint32 x = 0; x < fSize; x++) {
|
||||||
|
if (ValueAt(x, y) == value)
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count == Size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask)
|
SudokuField::SetHintMaskAt(uint32 x, uint32 y, uint32 hintMask)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public:
|
|||||||
|
|
||||||
bool IsSolved() const;
|
bool IsSolved() const;
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
|
bool IsValueCompleted(uint32 value) const;
|
||||||
|
|
||||||
uint32 Size() const { return fSize; }
|
uint32 Size() const { return fSize; }
|
||||||
uint32 BlockSize() const { return fBlockSize; }
|
uint32 BlockSize() const { return fBlockSize; }
|
||||||
|
|||||||
@@ -814,21 +814,30 @@ SudokuView::MouseDown(BPoint where)
|
|||||||
| B_TERTIARY_MOUSE_BUTTON)) != 0) {
|
| B_TERTIARY_MOUSE_BUTTON)) != 0) {
|
||||||
// double click or other buttons set a value
|
// double click or other buttons set a value
|
||||||
if ((fField->FlagsAt(x, y) & kInitialValue) == 0) {
|
if ((fField->FlagsAt(x, y) & kInitialValue) == 0) {
|
||||||
|
bool wasCompleted;
|
||||||
if (fField->ValueAt(x, y) > 0) {
|
if (fField->ValueAt(x, y) > 0) {
|
||||||
|
value = fField->ValueAt(x, y) - 1;
|
||||||
|
wasCompleted = fField->IsValueCompleted(value + 1);
|
||||||
|
|
||||||
fField->SetValueAt(x, y, 0);
|
fField->SetValueAt(x, y, 0);
|
||||||
fShowHintX = x;
|
fShowHintX = x;
|
||||||
fShowHintY = y;
|
fShowHintY = y;
|
||||||
} else {
|
} else {
|
||||||
|
wasCompleted = fField->IsValueCompleted(value + 1);
|
||||||
|
|
||||||
fField->SetValueAt(x, y, value + 1);
|
fField->SetValueAt(x, y, value + 1);
|
||||||
BMessenger(this).SendMessage(kMsgCheckSolved);
|
BMessenger(this).SendMessage(kMsgCheckSolved);
|
||||||
|
|
||||||
|
// allow dragging to remove the hint from other fields
|
||||||
|
fLastHintValueSet = false;
|
||||||
|
fLastHintValue = value;
|
||||||
|
fLastField = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
_InvalidateField(x, y);
|
if (wasCompleted != fField->IsValueCompleted(value + 1))
|
||||||
|
Invalidate();
|
||||||
// allow dragging to remove the hint from other fields
|
else
|
||||||
fLastHintValueSet = false;
|
_InvalidateField(x, y);
|
||||||
fLastHintValue = value;
|
|
||||||
fLastField = field;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1204,8 +1213,8 @@ SudokuView::Draw(BRect /*updateRect*/)
|
|||||||
|| (fShowKeyboardFocus && x == fKeyboardX
|
|| (fShowKeyboardFocus && x == fKeyboardX
|
||||||
&& y == fKeyboardY))
|
&& y == fKeyboardY))
|
||||||
&& (fField->FlagsAt(x, y) & kInitialValue) == 0) {
|
&& (fField->FlagsAt(x, y) & kInitialValue) == 0) {
|
||||||
//SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
|
// TODO: make color more intense
|
||||||
SetLowColor(255, 255, 210);
|
SetLowColor(tint_color(fBackgroundColor, B_DARKEN_2_TINT));
|
||||||
FillRect(_Frame(x, y), B_SOLID_LOW);
|
FillRect(_Frame(x, y), B_SOLID_LOW);
|
||||||
} else {
|
} else {
|
||||||
SetLowColor(fBackgroundColor);
|
SetLowColor(fBackgroundColor);
|
||||||
@@ -1222,13 +1231,16 @@ SudokuView::Draw(BRect /*updateRect*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetFont(&fFieldFont);
|
SetFont(&fFieldFont);
|
||||||
if (fField->FlagsAt(x, y) & kInitialValue)
|
if ((fField->FlagsAt(x, y) & kInitialValue) != 0)
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
else {
|
else {
|
||||||
if ((fHintFlags & kMarkInvalid) == 0
|
if ((fHintFlags & kMarkInvalid) == 0
|
||||||
|| fField->ValidMaskAt(x, y) & (1UL << (value - 1)))
|
|| fField->ValidMaskAt(x, y) & (1UL << (value - 1))) {
|
||||||
SetHighColor(0, 0, 200);
|
if (fField->IsValueCompleted(value))
|
||||||
else
|
SetHighColor(60, 60, 150);
|
||||||
|
else
|
||||||
|
SetHighColor(0, 0, 220);
|
||||||
|
} else
|
||||||
SetHighColor(200, 0, 0);
|
SetHighColor(200, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user