added a menu to change the drawing mode

bounding boxes are now drawn alternatively red and green to differenciate between characters


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20751 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-04-19 17:23:54 +00:00
parent 421a4def57
commit f4841bebd4
6 changed files with 88 additions and 22 deletions
+48 -1
View File
@@ -40,6 +40,7 @@ ControlView::ControlView(BRect rect)
fBoundingboxesCheckBox(NULL),
fCyclingFontButton(NULL),
fFontFamilyMenu(NULL),
fDrawingModeMenu(NULL),
fCycleFonts(false),
fFontStyleindex(0)
{
@@ -111,6 +112,51 @@ ControlView::AttachedToWindow()
new BMessage(ALIASING_MSG));
fAliasingCheckBox->SetValue(B_CONTROL_ON);
AddChild(fAliasingCheckBox);
rect.OffsetBy(0.0, offsetX);
fDrawingModeMenu = new BMenu("drawingmodemenu");
BMessage* drawingMsg = NULL;
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_COPY);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_COPY", drawingMsg));
fDrawingModeMenu->ItemAt(0)->SetMarked(true);
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_OVER);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_OVER", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_ERASE);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_ERASE", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_INVERT);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_INVERT", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_ADD);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_ADD", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_SUBTRACT);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_SUBTRACT", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_BLEND);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_BLEND", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_MIN);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_MIN", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_MAX);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_MAX", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_SELECT);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_SELECT", drawingMsg));
drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG);
drawingMsg->AddInt32("_mode", B_OP_ALPHA);
fDrawingModeMenu->AddItem(new BMenuItem("B_OP_ALPHA", drawingMsg));
fDrawingModeMenu->SetLabelFromMarked(true);
BMenuField *drawingModeMenuField = new BMenuField(rect, "FontMenuField", "Drawing mode:", fDrawingModeMenu, true);
drawingModeMenuField->SetDivider(5+StringWidth("Drawing mode:"));
AddChild(drawingModeMenuField);
rect.OffsetBy(0.0, 22);
fBoundingboxesCheckBox = new BCheckBox(rect, "BoundingBoxes", "Bounding boxes",
@@ -327,7 +373,8 @@ void
ControlView::SetTarget(BHandler* handler)
{
delete fMessenger;
fMessenger = new BMessenger(handler);
fMessenger = new BMessenger(handler);
fDrawingModeMenu->SetTargetForItems(handler);
}
+1
View File
@@ -55,6 +55,7 @@ class ControlView : public BView {
BCheckBox* fBoundingboxesCheckBox;
BButton* fCyclingFontButton;
BMenu* fFontFamilyMenu;
BMenu* fDrawingModeMenu;
bool fCycleFonts;
int32 fFontStyleindex;
};
+19 -18
View File
@@ -17,6 +17,24 @@
FontDemo::FontDemo()
: BApplication("application/x-vnd.Haiku-FontDemo")
{
// Create the demo window where we draw the string
BWindow* demoWindow = new BWindow(BRect(80, 30, 490, 300), "FontDemo",
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
FontDemoView* demoView = new FontDemoView(demoWindow->Bounds());
demoWindow->AddChild(demoView);
BWindow* controlWindow = new BWindow(BRect(500, 30, 700, 402), "Controls",
B_FLOATING_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL,
B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS);
ControlView* controlView = new ControlView(controlWindow->Bounds());
controlWindow->AddChild(controlView);
controlView->SetTarget(demoView);
demoWindow->Show();
controlWindow->Show();
}
@@ -28,24 +46,7 @@ FontDemo::~FontDemo()
void
FontDemo::ReadyToRun()
{
// Create the demo window where we draw the string
BWindow* demoWindow = new BWindow(BRect(80, 30, 490, 300), "FontDemo",
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
FontDemoView* demoView = new FontDemoView(demoWindow->Bounds());
demoWindow->AddChild(demoView);
BWindow* controlWindow = new BWindow(BRect(500,30, 700, 352), "Controls",
B_FLOATING_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL,
B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS);
ControlView* controlView = new ControlView(controlWindow->Bounds());
controlWindow->AddChild(controlView);
controlView->SetTarget(demoView);
demoWindow->Show();
controlWindow->Show();
}
+18 -3
View File
@@ -27,6 +27,7 @@ FontDemoView::FontDemoView(BRect rect)
fBufferView(NULL),
fString(NULL),
fOutLineLevel(0),
fDrawingMode(B_OP_COPY),
fBoundingBoxes(false),
fDrawShapes(false)
{
@@ -76,6 +77,9 @@ FontDemoView::_DrawView(BView* view)
{
if (!view)
return;
view->SetDrawingMode(B_OP_COPY);
BRect rect = view->Bounds();
view->SetHighColor(255, 255, 255);
@@ -152,12 +156,15 @@ FontDemoView::_DrawView(BView* view)
view->StrokeShape(fShapes[i]);
} else {
view->SetHighColor(0, 0, 0);
view->SetDrawingMode(B_OP_OVER);
view->SetDrawingMode(fDrawingMode);
view->DrawChar(fString[i], BPoint(xCoordArray[i], yCoordArray[i]));
}
if (BoundingBoxes() && !OutLineLevel()) {
view->SetHighColor(255, 0, 0);
if (i % 2)
view->SetHighColor(0, 255, 0);
else
view->SetHighColor(255, 0, 0);
view->SetDrawingMode(B_OP_COPY);
view->StrokeRect(boundBoxes[i]);
}
@@ -167,7 +174,7 @@ FontDemoView::_DrawView(BView* view)
xCoord += (escapementArray[i] /*+ escapeDeltas[i].nonspace + escapeDeltas[i].space*/)
* FontSize() + Spacing();
printf("xCoord %f\n", xCoord);
//printf("xCoord %f\n", xCoord);
}
}
@@ -281,6 +288,14 @@ FontDemoView::MessageReceived(BMessage* msg)
break;
}
case DRAWINGMODE_CHANGED_MSG:
{
if (msg->FindInt32("_mode", (int32 *)&fDrawingMode) == B_OK) {
Invalidate(/*&fBoxRegion*/);
}
break;
}
case BOUNDING_BOX_MSG:
{
bool boundingbox = false;
+1
View File
@@ -62,6 +62,7 @@ class FontDemoView : public BView {
float fFontSize;
float fSpacing;
int8 fOutLineLevel;
drawing_mode fDrawingMode;
BRegion fBoxRegion;
BFont fFont;
+1
View File
@@ -19,6 +19,7 @@ const uint32 CYCLING_FONTS_MSG = 'cycl';
const uint32 CYCLING_FONTS_UPDATE_MSG = 'cycU';
const uint32 FONTSTYLE_CHANGED_MSG = 'fonS';
const uint32 FONTFAMILY_CHANGED_MSG = 'fonF';
const uint32 DRAWINGMODE_CHANGED_MSG = 'drmF';
const uint32 TEXT_CHANGED_MSG = 'text';
#endif // MESSAGES_H