-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSTLLogoView.cpp
94 lines (78 loc) · 2.45 KB
/
STLLogoView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* STLover - A powerful tool for viewing and manipulating 3D STL models
* Copyright (C) 2020 Gerasim Troeglazov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "STLApp.h"
#include "STLLogoView.h"
#include "STLWindow.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "STLoverLogoView"
STLLogoView::STLLogoView(BRect frame)
: BView(frame, "logoview", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_PULSE_NEEDED | B_FULL_UPDATE_ON_RESIZE)
{
appIcon = STLoverApplication::GetIcon(NULL, 164);
fLabelColor = {255, 255, 255, 255};
}
STLLogoView::~STLLogoView()
{
delete appIcon;
}
void
STLLogoView::MouseDown(BPoint p)
{
uint32 buttons = Window()->CurrentMessage()->FindInt32("buttons");
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
if (buttons & B_PRIMARY_MOUSE_BUTTON) {
BRect iconRect = appIcon->Bounds();
iconRect.OffsetTo(iconPos);
if (iconRect.Contains(p))
Window()->PostMessage(MSG_FILE_OPEN);
}
}
void
STLLogoView::Pulse()
{
Window()->PostMessage(MSG_PULSE);
}
void
STLLogoView::SetText(const char* text)
{
fLabel.SetTo(text);
Draw(Bounds());
}
void
STLLogoView::SetTextColor(uint8 r, uint8 g, uint8 b)
{
fLabelColor.red = r;
fLabelColor.green = g;
fLabelColor.blue = b;
Draw(Bounds());
}
void
STLLogoView::Draw(BRect rect)
{
const char *text = fLabel.String();
SetDrawingMode(B_OP_OVER);
SetHighColor(30, 30, 51);
FillRect(Bounds());
SetDrawingMode(B_OP_ALPHA);
iconPos = BPoint((Bounds().Width() - appIcon->Bounds().Width()) / 2.0,
(Bounds().Height() - appIcon->Bounds().Height()) / 2.0);
DrawBitmap(appIcon, iconPos);
BFont font(be_plain_font);
BPoint textPos((Bounds().Width() - font.StringWidth(text)) / 2.0,
iconPos.y + appIcon->Bounds().Height() + 24);
SetHighColor(fLabelColor);
DrawString(text, textPos);
}