forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_flags.cpp
118 lines (89 loc) · 2.43 KB
/
context_flags.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/context_flags.h"
#include "app/context.h"
#include "app/doc.h"
#include "app/modules/editors.h"
#include "app/site.h"
#include "app/ui/editor/editor.h"
#include "doc/cel.h"
#include "doc/layer.h"
#include "doc/sprite.h"
namespace app {
ContextFlags::ContextFlags()
{
m_flags = 0;
}
void ContextFlags::update(Context* context)
{
Site site = context->activeSite();
Doc* document = site.document();
m_flags = 0;
if (document) {
m_flags |= HasActiveDocument;
if (document->readLock(0)) {
m_flags |= ActiveDocumentIsReadable;
if (document->isMaskVisible())
m_flags |= HasVisibleMask;
updateFlagsFromSite(site);
if (document->canWriteLockFromRead())
m_flags |= ActiveDocumentIsWritable;
document->unlock();
}
#ifdef ENABLE_UI
// TODO this is a hack, try to find a better design to handle this
// "moving pixels" state.
if (current_editor &&
current_editor->document() == document &&
current_editor->isMovingPixels()) {
// Flags enabled when we are in MovingPixelsState
m_flags |=
HasVisibleMask |
ActiveDocumentIsReadable |
ActiveDocumentIsWritable;
updateFlagsFromSite(current_editor->getSite());
}
#endif // ENABLE_UI
}
}
void ContextFlags::updateFlagsFromSite(const Site& site)
{
const Sprite* sprite = site.sprite();
if (!sprite)
return;
m_flags |= HasActiveSprite;
if (sprite->backgroundLayer())
m_flags |= HasBackgroundLayer;
const Layer* layer = site.layer();
frame_t frame = site.frame();
if (!layer)
return;
m_flags |= HasActiveLayer;
if (layer->isBackground())
m_flags |= ActiveLayerIsBackground;
if (layer->isVisibleHierarchy())
m_flags |= ActiveLayerIsVisible;
if (layer->isEditableHierarchy())
m_flags |= ActiveLayerIsEditable;
if (layer->isReference())
m_flags |= ActiveLayerIsReference;
if (layer->isImage()) {
m_flags |= ActiveLayerIsImage;
Cel* cel = layer->cel(frame);
if (cel) {
m_flags |= HasActiveCel;
if (cel->image())
m_flags |= HasActiveImage;
}
}
if (site.selectedColors().picks() > 0)
m_flags |= HasSelectedColors;
}
} // namespace app