xref: /haiku/src/tests/servers/app/font_spacing/main.cpp (revision 9f739dd2e868114ce19ae73afcff07caf2ddb8b6)
1 /*
2  * Copyright 2014 Stephan Aßmus <superstippi@gmx.de>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 
6 
7 #include <algorithm>
8 #include <stdio.h>
9 #include <string.h>
10 
11 #include <Application.h>
12 #include <Bitmap.h>
13 #include <GradientLinear.h>
14 #include <Message.h>
15 #include <Picture.h>
16 #include <LayoutBuilder.h>
17 #include <List.h>
18 #include <PopUpMenu.h>
19 #include <Resources.h>
20 #include <Roster.h>
21 #include <ScrollView.h>
22 #include <String.h>
23 #include <StringView.h>
24 #include <View.h>
25 #include <Window.h>
26 
27 
28 static const char* kAppSignature = "application/x.vnd-Haiku.FontSpacing";
29 
30 
31 class TestView : public BView {
32 public:
33 								TestView();
34 	virtual						~TestView();
35 
36 	virtual	void				Draw(BRect updateRect);
37 };
38 
39 
40 TestView::TestView()
41 	:
42 	BView(NULL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
43 {
44 }
45 
46 
47 TestView::~TestView()
48 {
49 }
50 
51 
52 void
53 TestView::Draw(BRect updateRect)
54 {
55 	float scale = Bounds().Width() / 400.0f;
56 
57 	if (scale < 0.25f)
58 		scale = 0.25f;
59 	else if (scale > 3.0f)
60 		scale = 3.0f;
61 
62 	SetScale(scale);
63 
64 	const char* string = "Testing the various BFont spacing modes.";
65 
66 	BFont font;
67 	SetFont(&font);
68 	DrawString(string, BPoint(30.0f, 25.0f));
69 
70 	font.SetSpacing(B_STRING_SPACING);
71 	SetFont(&font);
72 	DrawString(string, BPoint(30.0f, 45.0f));
73 
74 	font.SetSpacing(B_CHAR_SPACING);
75 	SetFont(&font);
76 	DrawString(string, BPoint(30.0f, 65.0f));
77 }
78 
79 
80 // #pragma mark -
81 
82 
83 int
84 main(int argc, char** argv)
85 {
86 	BApplication app(kAppSignature);
87 
88 	BWindow* window = new BWindow(BRect(50, 50, 450, 450), "Font spacing test",
89 		B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_QUIT_ON_WINDOW_CLOSE
90 			| B_AUTO_UPDATE_SIZE_LIMITS);
91 
92 	BLayoutBuilder::Group<>(window)
93 		.Add(new TestView())
94 	;
95 
96 	window->Show();
97 
98 	app.Run();
99 	return 0;
100 }
101