forked from RedGl0w/atomic
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathatomic_cell.cpp
64 lines (51 loc) · 1.48 KB
/
atomic_cell.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
#include "atomic_cell.h"
#include <assert.h>
#include <escher/palette.h>
namespace Atomic {
AtomicCell::AtomicCell() :
HighlightCell(),
m_visible(true)
{
}
KDColor AtomicCell::colorForType(AtomType type) const {
return Palette::AtomColor[type];
}
void AtomicCell::drawRect(KDContext * ctx, KDRect rect) const {
if (m_visible) {
KDColor color = colorForType(m_atom.type);
ctx->fillRect(rect, color);
// Get text size in pixels
KDSize textSize = KDFont::SmallFont->stringSize(m_atom.symbol);
// Center text in cell
KDPoint textPosition(bounds().topLeft().x() + (bounds().width() - textSize.width()) / 2, bounds().topLeft().y() + (bounds().height() - textSize.height()) / 2);
ctx->drawString(m_atom.symbol, textPosition, KDFont::SmallFont, Palette::PrimaryText, color);
if (isHighlighted()) {
KDColor highlightColor = KDColor::blend(color, Palette::AtomHighlight, 0x7F);
ctx->strokeRect(bounds(), highlightColor);
}
} else {
ctx->fillRect(rect, Palette::BackgroundApps);
}
}
int AtomicCell::numberOfSubviews() const {
return 0;
}
View * AtomicCell::subviewAtIndex(int index) {
return nullptr;
}
void AtomicCell::layoutSubviews(bool force) {
}
void AtomicCell::setVisible(bool visible) {
if (m_visible != visible) {
m_visible = visible;
markRectAsDirty(bounds());
}
}
void AtomicCell::setAtom(AtomDef atom) {
m_atom = atom;
markRectAsDirty(bounds());
}
void AtomicCell::reloadCell() {
markRectAsDirty(bounds());
}
}