-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoastColorWindow.h
More file actions
112 lines (97 loc) · 3.18 KB
/
Copy pathRoastColorWindow.h
File metadata and controls
112 lines (97 loc) · 3.18 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
/* RoastColorWindow.h – Coffee Toolkit
*
* Analyses a photograph of coffee to estimate its Agtron
* roast score, using CIE luminance of the sampled region.
*
* Agtron scale: 25 (very dark/Italian) … 95 (very light/green)
*/
#include <Window.h>
#include <Bitmap.h>
#include <Button.h>
#include <FilePanel.h>
#include <Messenger.h>
#include <Rect.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TextView.h>
#include <View.h>
// Agtron scale limits — shared by RoastGaugeView and RoastColorWindow
static const float kAgtronMin = 25.0f;
static const float kAgtronMax = 95.0f;
// -------------------------------------------------------
// RoastGaugeView
//
// Horizontal bar with a dark-to-light coffee colour gradient
// and roast-level band labels. A white triangle pointer
// marks the measured Agtron value.
// -------------------------------------------------------
class RoastGaugeView : public BView {
public:
RoastGaugeView(BRect frame);
void Draw(BRect updateRect) override;
void SetAgtron(float agtron); // pass -1 for no reading
private:
float fAgtron;
};
// -------------------------------------------------------
// ThumbView
//
// Displays a BBitmap preview. The user can click-drag to
// select a rectangular sampling region drawn as a dashed
// white/black overlay. Sends MSG_SELECTION_CHANGED to the
// target messenger whenever the selection changes.
// -------------------------------------------------------
class ThumbView : public BView {
public:
ThumbView(BRect frame, BMessenger target);
void SetBitmap(BBitmap* bmp); // also clears selection
void ClearSelection();
bool HasSelection() const { return fHasSelection; }
BRect NormalisedSelection() const; // 0..1 in each axis
void Draw(BRect updateRect) override;
void MouseDown(BPoint where) override;
void MouseMoved(BPoint where, uint32 transit,
const BMessage* drag) override;
void MouseUp(BPoint where) override;
private:
void NotifyTarget();
BRect OrderedRect(BPoint a, BPoint b) const;
BBitmap* fBitmap;
BMessenger fTarget;
bool fHasSelection;
bool fDragging;
BPoint fDragStart;
BPoint fDragCurrent;
BRect fSelection;
};
// -------------------------------------------------------
// RoastColorWindow
// -------------------------------------------------------
class RoastColorWindow : public BWindow {
public:
RoastColorWindow();
~RoastColorWindow();
void MessageReceived(BMessage* msg) override;
private:
void LoadImage(const entry_ref& ref);
void Analyse();
float ComputeAgtron(BBitmap* bmp, BRect normSel);
const char* RoastName(float agtron);
void BuildTips(float agtron, char* buf, size_t bufSize);
// File selection
BButton* fOpenBtn;
BStringView* fFileNameView;
BFilePanel* fFilePanel;
// Preview
ThumbView* fThumbView;
BButton* fClearSelBtn;
BStringView* fSelHintView;
BBitmap* fThumbBitmap;
BBitmap* fSourceBitmap;
// Results
RoastGaugeView* fGaugeView;
BStringView* fAgtronView;
BTextView* fTipsView;
BScrollView* fTipsScroll;
};