| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | // Aseprite
 | 
					
						
							| 
									
										
										
										
											2020-02-06 03:38:04 +08:00
										 |  |  | // Copyright (C) 2019-2020  Igara Studio S.A.
 | 
					
						
							| 
									
										
										
										
											2018-05-07 11:11:50 +08:00
										 |  |  | // Copyright (C) 2001-2018  David Capello
 | 
					
						
							| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-08-27 04:02:58 +08:00
										 |  |  | // This program is distributed under the terms of
 | 
					
						
							|  |  |  | // the End-User License Agreement for Aseprite.
 | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/context_flags.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/context.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-07 22:54:44 +08:00
										 |  |  | #include "app/doc.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  | #include "app/modules/editors.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-07 13:47:42 +08:00
										 |  |  | #include "app/site.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  | #include "app/ui/editor/editor.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-21 09:21:31 +08:00
										 |  |  | #include "doc/cel.h"
 | 
					
						
							|  |  |  | #include "doc/layer.h"
 | 
					
						
							|  |  |  | #include "doc/sprite.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | namespace app { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | ContextFlags::ContextFlags() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   m_flags = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ContextFlags::update(Context* context) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-04-21 03:27:09 +08:00
										 |  |  |   Site site = context->activeSite(); | 
					
						
							| 
									
										
										
										
											2018-07-07 22:54:44 +08:00
										 |  |  |   Doc* document = site.document(); | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   m_flags = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (document) { | 
					
						
							|  |  |  |     m_flags |= HasActiveDocument; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-07 22:54:44 +08:00
										 |  |  |     if (document->lock(Doc::ReadLock, 0)) { | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  |       m_flags |= ActiveDocumentIsReadable; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (document->isMaskVisible()) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         m_flags |= HasVisibleMask; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |       updateFlagsFromSite(site); | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 03:38:04 +08:00
										 |  |  |       if (document->canWriteLockFromRead()) | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |         m_flags |= ActiveDocumentIsWritable; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |       document->unlock(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 11:11:50 +08:00
										 |  |  | #ifdef ENABLE_UI
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |     // 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()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-07 11:11:50 +08:00
										 |  |  | #endif // ENABLE_UI
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  | void ContextFlags::updateFlagsFromSite(const Site& site) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const Sprite* sprite = site.sprite(); | 
					
						
							|  |  |  |   if (!sprite) | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   m_flags |= HasActiveSprite; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   if (sprite->backgroundLayer()) | 
					
						
							|  |  |  |     m_flags |= HasBackgroundLayer; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   const Layer* layer = site.layer(); | 
					
						
							|  |  |  |   frame_t frame = site.frame(); | 
					
						
							|  |  |  |   if (!layer) | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   m_flags |= HasActiveLayer; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   if (layer->isBackground()) | 
					
						
							|  |  |  |     m_flags |= ActiveLayerIsBackground; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 02:27:38 +08:00
										 |  |  |   if (layer->isVisibleHierarchy()) | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |     m_flags |= ActiveLayerIsVisible; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 02:27:38 +08:00
										 |  |  |   if (layer->isEditableHierarchy()) | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |     m_flags |= ActiveLayerIsEditable; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-18 00:48:52 +08:00
										 |  |  |   if (layer->isReference()) | 
					
						
							|  |  |  |     m_flags |= ActiveLayerIsReference; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-07 02:01:22 +08:00
										 |  |  |   if (layer->isTilemap()) | 
					
						
							|  |  |  |     m_flags |= ActiveLayerIsTilemap; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 04:25:39 +08:00
										 |  |  |   if (layer->isImage()) { | 
					
						
							|  |  |  |     m_flags |= ActiveLayerIsImage; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Cel* cel = layer->cel(frame); | 
					
						
							|  |  |  |     if (cel) { | 
					
						
							|  |  |  |       m_flags |= HasActiveCel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (cel->image()) | 
					
						
							|  |  |  |         m_flags |= HasActiveImage; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-08-11 01:37:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (site.selectedColors().picks() > 0) | 
					
						
							|  |  |  |     m_flags |= HasSelectedColors; | 
					
						
							| 
									
										
										
										
											2019-11-16 23:09:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (site.selectedTiles().picks() > 0) | 
					
						
							|  |  |  |     m_flags |= HasSelectedTiles; | 
					
						
							| 
									
										
										
										
											2011-03-28 01:51:02 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace app
 |