xref: /haiku/src/preferences/backgrounds/BackgroundImage.h (revision adb0d19d561947362090081e81d90dde59142026)
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 #include "String.h"
42 #include "ObjectList.h"
43 
44 #include <GraphicsDefs.h>
45 #include <Node.h>
46 #include <Path.h>
47 
48 
49 class BView;
50 class BBitmap;
51 
52 class BackgroundImage;
53 class Image;
54 class BackgroundsView;
55 
56 extern const char *kBackgroundImageInfo;
57 extern const char *kBackgroundImageInfoOffset;
58 extern const char *kBackgroundImageInfoEraseText;
59 extern const char *kBackgroundImageInfoMode;
60 extern const char *kBackgroundImageInfoWorkspaces;
61 extern const char *kBackgroundImageInfoPath;
62 extern const char *kBackgroundImageInfoSet;
63 extern const char *kBackgroundImageInfoSetPeriod;
64 
65 const uint32 kRestoreBackgroundImage = 'Tbgr';
66 const uint32 kChangeBackgroundImage = 'Cbgr';
67 
68 class BackgroundImage {
69 	// This class knows everything about which bitmap to use for a given
70 	// view and how.
71 	// Unlike other windows, the Desktop window can have different backgrounds
72 	// for each workspace
73 public:
74 
75 	enum Mode {
76 		kAtOffset,
77 		kCentered,			// only works on Desktop
78 		kScaledToFit,		// only works on Desktop
79 		kTiled
80 	};
81 
82 	class BackgroundImageInfo {
83 		// element of the per-workspace list
84 	public:
85 		BackgroundImageInfo(uint32 workspace, int32 imageIndex, Mode mode,
86 			BPoint offset, bool textWidgetLabelOutline, uint32 imageSet,
87 			uint32 cacheMode);
88 		~BackgroundImageInfo();
89 
90 		void LoadBitmap();
91 		void UnloadBitmap(uint32 globalCacheMode);
92 
93 		uint32 fWorkspace;
94 		int32 fImageIndex;
95 		Mode fMode;
96 		BPoint fOffset;
97 		bool fTextWidgetLabelOutline;
98 		uint32 fImageSet;
99 		uint32 fCacheMode;		// image cache strategy (0 cache , 1 no cache)
100 	};
101 
102 	static BackgroundImage *GetBackgroundImage(const BNode *node,
103 		bool isDesktop, BackgroundsView* view);
104 		// create a BackgroundImage object by reading it from a node
105 
106 	virtual ~BackgroundImage();
107 
108 	void Show(BView *view, int32 workspace);
109 		// display the right background for a given workspace
110 	void Remove();
111 		// remove the background from it's current view
112 
113 	void WorkspaceActivated(BView *view, int32 workspace, bool state);
114 		// respond to a workspace change
115 	void ScreenChanged(BRect rect, color_space space);
116 		// respond to a screen size change
117 	/*static BackgroundImage *Refresh(BackgroundImage *oldBackgroundImage,
118 		const BNode *fromNode, bool desktop, BPoseView *poseView);
119 		// respond to a background image setting change
120 	void ChangeImageSet(BPoseView *poseView);
121 		// change to the next imageSet if any, no refresh*/
122 	BackgroundImageInfo *ImageInfoForWorkspace(int32) const;
123 
124 	bool IsDesktop() { return fIsDesktop;}
125 
126 	status_t SetBackgroundImage(BNode *node);
127 
128 	void Show(BackgroundImageInfo *, BView *view);
129 
130 	uint32 GetShowingImageSet() { return fShowingImageSet; }
131 
132 	void Add(BackgroundImageInfo *);
133 	void Remove(BackgroundImageInfo *);
134 	void RemoveAll();
135 
136 private:
137 	BackgroundImage(const BNode *node, bool isDesktop, BackgroundsView* view);
138 		// no public constructor, GetBackgroundImage factory function is
139 		// used instead
140 
141 	bool fIsDesktop;
142 	BNode fDefinedByNode;
143 	BView *fView;
144 	BackgroundsView* fBackgroundsView;
145 	BackgroundImageInfo *fShowingBitmap;
146 
147 	BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
148 
149 	uint32 fImageSetPeriod;		// period between imagesets, 0 if none
150 	uint32 fShowingImageSet;	// current imageset
151 	uint32 fImageSetCount;		// imageset count
152 	uint32 fCacheMode;// image cache strategy (0 all, 1 none, 2 own strategy)
153 	bool fRandomChange; 		// random or sequential change
154 };
155 
156 class Image {
157 	// element for each image
158 public:
159 	Image(BPath path);
160 	~Image();
161 
162 	void UnloadBitmap();
163 	const char* GetName() {return name.String();}
164 	BBitmap* GetBitmap();
165 	BPath GetPath() {return fPath;}
166 private:
167 	BBitmap *fBitmap;
168 	BPath fPath;
169 	BString name;
170 };
171 
172 #endif
173