Ejemplo n.º 1
0
FontDemoView::FontDemoView(BRect rect)
	: BView(rect, "FontDemoView", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS),
	fBitmap(NULL),
	fBufferView(NULL),
	fString(NULL),
	fFontSize(50.0),
	fSpacing(0.0),
	fOutLineLevel(0),
	fDrawingMode(B_OP_COPY),
	fBoundingBoxes(false),
	fDrawShapes(false),
	fShapes(NULL)
{
	SetViewColor(B_TRANSPARENT_COLOR);
	SetString("Haiku, Inc.");
	SetFontSize(fFontSize);
	SetAntialiasing(true);

	_NewBitmap(Bounds());
}
Ejemplo n.º 2
0
void
FontDemoView::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case TEXT_CHANGED_MSG:
		{
			const char* text = NULL;
			if (msg->FindString("_text", &text) == B_OK) {
				SetString(text);
				Invalidate(/*&fBoxRegion*/);
			}
			break;
		}

		case FONTSTYLE_CHANGED_MSG:
		{
			BMessage fontMessage;
			if (msg->FindMessage("_fontMessage", &fontMessage) != B_OK)
				return;

			const char* family;
			const char* style;
			if (fontMessage.FindString("_family", &family) != B_OK
				|| fontMessage.FindString("_style", &style) != B_OK)
				return;

			fFont.SetFamilyAndStyle(family, style);
			Invalidate();
			break;
		}

		case FONTFAMILY_CHANGED_MSG:
		{
			BMessage fontMessage;
			if (msg->FindMessage("_fontMessage", &fontMessage) != B_OK)
				return;

			const char* family;
			if (fontMessage.FindString("_family", &family) != B_OK)
				return;

			font_style style;
			if (get_font_style(const_cast<char*>(family), 0, &style) == B_OK) {
				fFont.SetFamilyAndStyle(family, style);
				Invalidate(/*&fBoxRegion*/);
			}
			break;
		}

		case FONTSIZE_MSG:
		{
			float size = 0.0;
			if (msg->FindFloat("_size", &size) == B_OK) {
				SetFontSize(size);
				Invalidate(/*&fBoxRegion*/);
			}
			break;
		}

		case FONTSHEAR_MSG:
		{
			float shear = 90.0;
			if (msg->FindFloat("_shear", &shear) == B_OK) {
				SetFontShear(shear);
				Invalidate(/*&fBoxRegion*/);
			 }
			break;
		}

		case ROTATION_MSG:
		{
			float rotation = 0.0;
			if (msg->FindFloat("_rotation", &rotation) == B_OK) {
				SetFontRotation(rotation);
				Invalidate(/*&fBoxRegion*/);
			 }
			break;
		}

		case SPACING_MSG:
		{
			float space = 0.0;
			if (msg->FindFloat("_spacing", &space) == B_OK) {
				SetSpacing(space);
				Invalidate(/*&fBoxRegion*/);
			 }
			break;
		}

		case OUTLINE_MSG:
		{
			int8 outline = 0;
			if (msg->FindInt8("_outline", &outline) == B_OK) {
				SetOutlineLevel(outline);
				Invalidate(/*&fBoxRegion*/);
			 }
			break;
		}

		case ALIASING_MSG:
		{
			bool aliased = false;
			if (msg->FindBool("_aliased", &aliased) == B_OK) {
				SetAntialiasing(aliased);
				Invalidate(/*&fBoxRegion*/);
			}
			break;
		}

		case DRAWINGMODE_CHANGED_MSG:
		{
			if (msg->FindInt32("_mode", (int32 *)&fDrawingMode) == B_OK) {
				Invalidate(/*&fBoxRegion*/);
				switch (fDrawingMode) {
					case B_OP_COPY:
						printf("Drawing mode: B_OP_COPY\n");
						break;
					case B_OP_OVER:
						printf("Drawing mode: B_OP_OVER\n");
						break;
					case B_OP_ERASE:
						printf("Drawing mode: B_OP_ERASE\n");
						break;
					case B_OP_INVERT:
						printf("Drawing mode: B_OP_INVERT\n");
						break;
					case B_OP_ADD:
						printf("Drawing mode: B_OP_ADD\n");
						break;
					case B_OP_SUBTRACT:
						printf("Drawing mode: B_OP_SUBTRACT\n");
						break;
					case B_OP_BLEND:
						printf("Drawing mode: B_OP_BLEND\n");
						break;
 					case B_OP_MIN:
						printf("Drawing mode: B_OP_MIN\n");
						break;
					case B_OP_MAX:
						printf("Drawing mode: B_OP_MAX\n");
						break;
					case B_OP_SELECT:
						printf("Drawing mode: B_OP_SELECT\n");
						break;
					case B_OP_ALPHA:
						printf("Drawing mode: B_OP_ALPHA\n");
						break;
					default:
						printf("Drawing mode: %d\n", fDrawingMode);
				}
			}
			break;
		}

		case BOUNDING_BOX_MSG:
		{
			bool boundingbox = false;
			if (msg->FindBool("_boundingbox", &boundingbox) == B_OK) {
				SetDrawBoundingBoxes(boundingbox);
				Invalidate(/*&fBoxRegion*/);
			}
			break;
		}

		default:
			BView::MessageReceived(msg);
			break;
	}
}