diff --git a/src/apps/fontdemo/ControlView.cpp b/src/apps/fontdemo/ControlView.cpp index a0e82a0886..cad01b58f1 100644 --- a/src/apps/fontdemo/ControlView.cpp +++ b/src/apps/fontdemo/ControlView.cpp @@ -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); } diff --git a/src/apps/fontdemo/ControlView.h b/src/apps/fontdemo/ControlView.h index aac22622b4..4d1e860ce5 100644 --- a/src/apps/fontdemo/ControlView.h +++ b/src/apps/fontdemo/ControlView.h @@ -55,6 +55,7 @@ class ControlView : public BView { BCheckBox* fBoundingboxesCheckBox; BButton* fCyclingFontButton; BMenu* fFontFamilyMenu; + BMenu* fDrawingModeMenu; bool fCycleFonts; int32 fFontStyleindex; }; diff --git a/src/apps/fontdemo/FontDemo.cpp b/src/apps/fontdemo/FontDemo.cpp index 1d3558bb95..2e54b73763 100644 --- a/src/apps/fontdemo/FontDemo.cpp +++ b/src/apps/fontdemo/FontDemo.cpp @@ -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(); + } diff --git a/src/apps/fontdemo/FontDemoView.cpp b/src/apps/fontdemo/FontDemoView.cpp index f88bfdf453..6be1d042c1 100644 --- a/src/apps/fontdemo/FontDemoView.cpp +++ b/src/apps/fontdemo/FontDemoView.cpp @@ -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; diff --git a/src/apps/fontdemo/FontDemoView.h b/src/apps/fontdemo/FontDemoView.h index 652c372e17..b510e4116e 100644 --- a/src/apps/fontdemo/FontDemoView.h +++ b/src/apps/fontdemo/FontDemoView.h @@ -62,6 +62,7 @@ class FontDemoView : public BView { float fFontSize; float fSpacing; int8 fOutLineLevel; + drawing_mode fDrawingMode; BRegion fBoxRegion; BFont fFont; diff --git a/src/apps/fontdemo/messages.h b/src/apps/fontdemo/messages.h index 91eac3034b..b5c89db996 100644 --- a/src/apps/fontdemo/messages.h +++ b/src/apps/fontdemo/messages.h @@ -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