xref: /haiku/src/preferences/backgrounds/BackgroundImage.h (revision 3be9edf8da228afd9fec0390f408c964766122aa)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 //  Classes used for setting up and managing background images
36 //
37 
38 #ifndef __BACKGROUND_IMAGE__
39 #define __BACKGROUND_IMAGE__
40 
41 
42 #include <GraphicsDefs.h>
43 #include <Node.h>
44 #include <Path.h>
45 
46 #include "ObjectList.h"
47 #include "String.h"
48 
49 
50 class BView;
51 class BBitmap;
52 
53 class BackgroundImage;
54 class Image;
55 class BackgroundsView;
56 
57 extern const char* kBackgroundImageInfo;
58 extern const char* kBackgroundImageInfoOffset;
59 extern const char* kBackgroundImageInfoEraseText;
60 extern const char* kBackgroundImageInfoMode;
61 extern const char* kBackgroundImageInfoWorkspaces;
62 extern const char* kBackgroundImageInfoPath;
63 extern const char* kBackgroundImageInfoSet;
64 extern const char* kBackgroundImageInfoSetPeriod;
65 
66 const uint32 kRestoreBackgroundImage = 'Tbgr';
67 const uint32 kChangeBackgroundImage = 'Cbgr';
68 
69 class BackgroundImage {
70 	// This class knows everything about which bitmap to use for a given
71 	// view and how.
72 	// Unlike other windows, the Desktop window can have different backgrounds
73 	// for each workspace
74 public:
75 
76 	enum Mode {
77 		kAtOffset,
78 		kCentered,			// only works on Desktop
79 		kScaledToFit,		// only works on Desktop
80 		kTiled
81 	};
82 
83 	class BackgroundImageInfo {
84 		// element of the per-workspace list
85 	public:
86 		BackgroundImageInfo(uint32 workspace, int32 imageIndex, Mode mode,
87 			BPoint offset, bool textWidgetLabelOutline, uint32 imageSet,
88 			uint32 cacheMode);
89 		~BackgroundImageInfo();
90 
91 		void LoadBitmap();
92 		void UnloadBitmap(uint32 globalCacheMode);
93 
94 		uint32 fWorkspace;
95 		int32 fImageIndex;
96 		Mode fMode;
97 		BPoint fOffset;
98 		bool fTextWidgetLabelOutline;
99 		uint32 fImageSet;
100 		uint32 fCacheMode;		// image cache strategy (0 cache , 1 no cache)
101 	};
102 
103 	static BackgroundImage* GetBackgroundImage(const BNode* node,
104 		bool isDesktop, BackgroundsView* view);
105 		// create a BackgroundImage object by reading it from a node
106 
107 	virtual ~BackgroundImage();
108 
109 	void Show(BView* view, int32 workspace);
110 		// display the right background for a given workspace
111 	void Remove();
112 		// remove the background from it's current view
113 
114 	void WorkspaceActivated(BView* view, int32 workspace, bool state);
115 		// respond to a workspace change
116 	void ScreenChanged(BRect rect, color_space space);
117 		// respond to a screen size change
118 	/*static BackgroundImage* Refresh(BackgroundImage* oldBackgroundImage,
119 		const BNode* fromNode, bool desktop, BPoseView* poseView);
120 		// respond to a background image setting change
121 	void ChangeImageSet(BPoseView* poseView);
122 		// change to the next imageSet if any, no refresh*/
123 	BackgroundImageInfo* ImageInfoForWorkspace(int32) const;
124 
125 	bool IsDesktop() { return fIsDesktop;}
126 
127 	status_t SetBackgroundImage(BNode* node);
128 
129 	void Show(BackgroundImageInfo*, BView* view);
130 
131 	uint32 GetShowingImageSet() { return fShowingImageSet; }
132 
133 	void Add(BackgroundImageInfo*);
134 	void Remove(BackgroundImageInfo*);
135 	void RemoveAll();
136 
137 private:
138 	BackgroundImage(const BNode* node, bool isDesktop, BackgroundsView* view);
139 		// no public constructor, GetBackgroundImage factory function is
140 		// used instead
141 
142 	bool fIsDesktop;
143 	BNode fDefinedByNode;
144 	BView* fView;
145 	BackgroundsView* fBackgroundsView;
146 	BackgroundImageInfo* fShowingBitmap;
147 
148 	BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
149 
150 	uint32 fImageSetPeriod;		// period between imagesets, 0 if none
151 	uint32 fShowingImageSet;	// current imageset
152 	uint32 fImageSetCount;		// imageset count
153 	uint32 fCacheMode;// image cache strategy (0 all, 1 none, 2 own strategy)
154 	bool fRandomChange; 		// random or sequential change
155 };
156 
157 class Image {
158 	// element for each image
159 public:
160 	Image(BPath path);
161 	~Image();
162 
163 	void UnloadBitmap();
164 	const char* GetName() {return name.String();}
165 	BBitmap* GetBitmap();
166 	BPath GetPath() {return fPath;}
167 private:
168 	BBitmap* fBitmap;
169 	BPath fPath;
170 	BString name;
171 };
172 
173 #endif
174 
175