blob: 1477ec6060f5fdc8ee785bdd3e475a1c53d8c8e4 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkWindow_DEFINED
18#define SkWindow_DEFINED
19
20#include "SkView.h"
21#include "SkBitmap.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000022#include "SkMatrix.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023#include "SkRegion.h"
24#include "SkEvent.h"
25#include "SkKey.h"
26#include "SkTDArray.h"
27
28#ifdef SK_BUILD_FOR_WINCEx
29 #define SHOW_FPS
30#endif
31//#define USE_GX_SCREEN
32
reed@android.comf2b98d62010-12-20 18:26:13 +000033class SkCanvas;
34
reed@android.com8a1c16f2008-12-17 15:59:43 +000035class SkOSMenu;
36
37class SkWindow : public SkView {
38public:
39 SkWindow();
40 virtual ~SkWindow();
41
42 const SkBitmap& getBitmap() const { return fBitmap; }
43
44 void setConfig(SkBitmap::Config);
45 void resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config);
46 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
47 void eraseRGB(U8CPU r, U8CPU g, U8CPU b);
48
49 bool isDirty() const { return !fDirtyRgn.isEmpty(); }
reed@android.comf2b98d62010-12-20 18:26:13 +000050 bool update(SkIRect* updateArea, SkCanvas* = NULL);
51 // does not call through to onHandleInval(), but does force the fDirtyRgn
52 // to be wide open. Call before update() to ensure we redraw everything.
53 void forceInvalAll();
54 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
55 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
56
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 bool handleClick(int x, int y, Click::State);
58 bool handleChar(SkUnichar);
59 bool handleKey(SkKey);
60 bool handleKeyUp(SkKey);
61 bool handleMenu(uint32_t os_cmd);
62
63 void addMenu(SkOSMenu*);
reed@android.com0ae6b242008-12-23 16:49:54 +000064
65 const char* getTitle() const { return fTitle.c_str(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 void setTitle(const char title[]);
67
reed@android.comf2b98d62010-12-20 18:26:13 +000068 const SkMatrix& getMatrix() const { return fMatrix; }
69 void setMatrix(const SkMatrix&);
70 void preConcat(const SkMatrix&);
71 void postConcat(const SkMatrix&);
72
Scroggo8ac0d542011-06-21 14:44:57 +000073 virtual void onPDFSaved(const char title[], const char desc[],
74 const char path[]) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000075protected:
76 virtual bool onEvent(const SkEvent&);
mike@reedtribe.orgdd0cd342011-03-21 00:53:39 +000077 virtual bool onDispatchClick(int x, int y, Click::State);
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 // called if part of our bitmap is invalidated
79 virtual void onHandleInval(const SkIRect&);
80 virtual bool onHandleChar(SkUnichar);
81 virtual bool onHandleKey(SkKey);
82 virtual bool onHandleKeyUp(SkKey);
83 virtual void onAddMenu(const SkOSMenu*) {}
84 virtual void onSetTitle(const char title[]) {}
85
86 // overrides from SkView
reed@android.comf2b98d62010-12-20 18:26:13 +000087 virtual bool handleInval(const SkRect*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000088 virtual bool onGetFocusView(SkView** focus) const;
89 virtual bool onSetFocusView(SkView* focus);
90
91private:
92 SkBitmap::Config fConfig;
93 SkBitmap fBitmap;
94 SkRegion fDirtyRgn;
95 Click* fClick; // to track clicks
96
97 SkTDArray<SkOSMenu*> fMenus;
98
99 SkView* fFocusView;
100 bool fWaitingOnInval;
reed@android.com0ae6b242008-12-23 16:49:54 +0000101
102 SkString fTitle;
reed@android.comf2b98d62010-12-20 18:26:13 +0000103 SkMatrix fMatrix;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000104
105 typedef SkView INHERITED;
106};
107
108///////////////////////////////////////////////////////////
109
reed@android.com671cd652009-05-22 20:44:12 +0000110#ifdef SK_USE_WXWIDGETS
111 #include "SkOSWindow_wxwidgets.h"
112#elif defined(SK_BUILD_FOR_MAC)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000113 #include "SkOSWindow_Mac.h"
114#elif defined(SK_BUILD_FOR_WIN)
115 #include "SkOSWindow_Win.h"
Scroggof33d1532011-05-31 17:10:21 +0000116#elif defined(ANDROID)
117 #include "SkOSWindow_Android.h"
scroggob7e9aee2011-03-15 15:15:15 +0000118#elif defined(SK_BUILD_FOR_UNIX)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119 #include "SkOSWindow_Unix.h"
reed@android.com671cd652009-05-22 20:44:12 +0000120#elif defined(SK_BUILD_FOR_SDL)
121 #include "SkOSWindow_SDL.h"
reed@android.comf2b98d62010-12-20 18:26:13 +0000122#elif defined(SK_BUILD_FOR_IOS)
123 #include "SkOSWindow_iOS.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124#endif
125
126#endif
127