xref: /haiku/src/add-ons/translators/hvif/HVIFView.cpp (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * Copyright 2009, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Michael Lotz, mmlr@mlotz.ch
7  */
8 
9 #include "HVIFView.h"
10 #include "HVIFTranslator.h"
11 
12 #include <String.h>
13 #include <StringView.h>
14 
15 #include <stdio.h>
16 
17 #define HVIF_SETTING_RENDER_SIZE_CHANGED	'rsch'
18 
19 
20 HVIFView::HVIFView(const BRect &frame, const char *name, uint32 resizeMode,
21 	uint32 flags, TranslatorSettings *settings)
22 	:	BView(frame, name, resizeMode, flags),
23 		fSettings(settings)
24 {
25 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
26 
27 	font_height fontHeight;
28 	be_bold_font->GetHeight(&fontHeight);
29 	float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
30 
31 	BRect rect(10, 10, 200, 10 + height);
32 	BStringView *stringView = new BStringView(rect, "title",
33 		"Native Haiku Icon Format Translator");
34 	stringView->SetFont(be_bold_font);
35 	stringView->ResizeToPreferred();
36 	AddChild(stringView);
37 
38 	rect.OffsetBy(0, height + 10);
39 	char version[256];
40 	snprintf(version, sizeof(version), "Version %d.%d.%d, %s",
41 		int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)),
42 		int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)),
43 		int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)),
44 		__DATE__);
45 	stringView = new BStringView(rect, "version", version);
46 	stringView->ResizeToPreferred();
47 	AddChild(stringView);
48 
49 	GetFontHeight(&fontHeight);
50 	height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
51 
52 	rect.OffsetBy(0, height + 5);
53 	stringView = new BStringView(rect, "copyright",
54 		B_UTF8_COPYRIGHT"2009 Haiku Inc.");
55 	stringView->ResizeToPreferred();
56 	AddChild(stringView);
57 
58 	rect.OffsetBy(0, height + 5);
59 	int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
60 	BString label = "Render Size: ";
61 	label << renderSize;
62 	fRenderSize = new BSlider(rect, "renderSize", label.String(), NULL, 1, 32);
63 
64 	fRenderSize->ResizeToPreferred();
65 	fRenderSize->SetValue(renderSize / 8);
66 	fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM);
67 	fRenderSize->SetHashMarkCount(16);
68 	fRenderSize->SetModificationMessage(
69 		new BMessage(HVIF_SETTING_RENDER_SIZE_CHANGED));
70 	AddChild(fRenderSize);
71 }
72 
73 
74 void
75 HVIFView::AttachedToWindow()
76 {
77 	fRenderSize->SetTarget(this);
78 }
79 
80 
81 void
82 HVIFView::MessageReceived(BMessage *message)
83 {
84 	switch (message->what) {
85 		case HVIF_SETTING_RENDER_SIZE_CHANGED:
86 		{
87 			int32 value = fRenderSize->Value();
88 			if (value <= 0 || value > 32)
89 				break;
90 
91 			value *= 8;
92 			fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE, &value);
93 			fSettings->SaveSettings();
94 
95 			BString newLabel = "Render Size: ";
96 			newLabel << value;
97 			fRenderSize->SetLabel(newLabel.String());
98 			return;
99 		}
100 	}
101 
102 	BView::MessageReceived(message);
103 }
104