Ceneter SudokuView and keep it square. Avoid flickering when resizing. R5 build fixes.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22212 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2007-09-09 20:06:07 +00:00
parent cf8b3687f4
commit cff9bca41c
7 changed files with 98 additions and 9 deletions

View File

@ -0,0 +1,44 @@
/*
* Copyright 2007, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "CenteredViewContainer.h"
CenteredViewContainer::CenteredViewContainer(BView *target, BRect frame, const char* name, uint32 resizingMode)
: BView(frame, name, resizingMode, B_WILL_DRAW | B_FRAME_EVENTS)
, fTarget(target)
{
SetViewColor(B_TRANSPARENT_COLOR);
// to avoid flickering
AddChild(fTarget);
_CenterTarget(frame.Width(), frame.Height());
}
CenteredViewContainer::~CenteredViewContainer()
{
}
void
CenteredViewContainer::Draw(BRect updateRect)
{
FillRect(updateRect);
}
void
CenteredViewContainer::FrameResized(float width, float height)
{
BView::FrameResized(width, height);
_CenterTarget(width, height);
}
void CenteredViewContainer::_CenterTarget(float width, float height)
{
float size = width < height ? width : height;
float left = floor((width - size) / 2);
float top = floor((height - size) / 2);
fTarget->MoveTo(left, top);
fTarget->ResizeTo(size, size);
fTarget->FrameResized(size, size);
// in BeOS R5 BView::FrameResized is not (always) called automatically
// after ResizeTo()
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2007, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef CENTERED_VIEW_CONTAINER_H
#define CENTERED_VIEW_CONTAINER_H
#include <View.h>
class CenteredViewContainer : public BView {
public:
CenteredViewContainer(BView *target, BRect frame, const char* name, uint32 resizingMode);
virtual ~CenteredViewContainer();
void Draw(BRect updateRect);
void FrameResized(float width, float height);
private:
void _CenterTarget(float width, float height);
BView *fTarget;
};
#endif // CENTERED_VIEW_CONTAINER_H

View File

@ -3,6 +3,7 @@ SubDir HAIKU_TOP src apps sudoku ;
SetSubDirSupportedPlatformsBeOSCompatible ;
Application Sudoku :
CenteredViewContainer.cpp
ProgressWindow.cpp
Sudoku.cpp
SudokuField.cpp

View File

@ -10,6 +10,7 @@
#include "SudokuField.h"
#include "SudokuSolver.h"
#include <stdio.h>
SudokuGenerator::SudokuGenerator()
{

View File

@ -55,8 +55,11 @@ SudokuView::SudokuView(BRect frame, const char* name,
if (settings.FindBool("show cursor", &fShowCursor) != B_OK)
fShowCursor = false;
SetViewColor(255, 255, 240);
SetLowColor(ViewColor());
SetViewColor(B_TRANSPARENT_COLOR);
// to avoid flickering
rgb_color color = { 255, 255, 240 };
fBackgroundColor = color;
SetLowColor(color);
FrameResized(0, 0);
}
@ -99,7 +102,7 @@ SudokuView::_FilterString(const char* data, size_t dataLength, char* buffer,
continue;
if (!_ValidCharacter(data[i])) {
return B_BAD_DATA;
return B_BAD_VALUE;
}
buffer[out++] = data[i];
@ -737,6 +740,11 @@ SudokuView::_DrawHints(uint32 x, uint32 y)
void
SudokuView::Draw(BRect /*updateRect*/)
{
// draw one pixel border otherwise not covered
// by lines and fields
SetLowColor(fBackgroundColor);
StrokeRect(Bounds(), B_SOLID_LOW);
// draw lines
uint32 size = fField->Size();
@ -778,8 +786,10 @@ SudokuView::Draw(BRect /*updateRect*/)
//SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
SetLowColor(255, 255, 210);
FillRect(_Frame(x, y), B_SOLID_LOW);
} else
SetLowColor(ViewColor());
} else {
SetLowColor(fBackgroundColor);
FillRect(_Frame(x, y), B_SOLID_LOW);
}
if (fShowKeyboardFocus && x == fKeyboardX && y == fKeyboardY)
_DrawKeyboardFocus();

View File

@ -75,6 +75,7 @@ private:
void _DrawKeyboardFocus();
void _DrawHints(uint32 x, uint32 y);
rgb_color fBackgroundColor;
SudokuField* fField;
uint32 fBlockSize;
float fWidth, fHeight, fBaseline;

View File

@ -6,6 +6,7 @@
#include "SudokuWindow.h"
#include "CenteredViewContainer.h"
#include "ProgressWindow.h"
#include "Sudoku.h"
#include "SudokuField.h"
@ -156,9 +157,13 @@ SudokuWindow::SudokuWindow()
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(top);
fSudokuView = new SudokuView(top->Bounds().InsetByCopy(10, 10),
"sudoku view", settings, B_FOLLOW_ALL);
top->AddChild(fSudokuView);
fSudokuView = new SudokuView(top->Bounds().InsetByCopy(10, 10).OffsetToSelf(0, 0),
"sudoku view", settings, B_FOLLOW_NONE);
CenteredViewContainer * container = new CenteredViewContainer(fSudokuView,
top->Bounds().InsetByCopy(10, 10),
"center", B_FOLLOW_ALL);
container->SetHighColor(top->ViewColor());
top->AddChild(container);
// add menu