blob: ffba275ab5dfbe1e4b0cae504ab67a478baf89da [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
reed@android.com8a1c16f2008-12-17 15:59:43 +000073protected:
74 virtual bool onEvent(const SkEvent&);
75
76 // called if part of our bitmap is invalidated
77 virtual void onHandleInval(const SkIRect&);
78 virtual bool onHandleChar(SkUnichar);
79 virtual bool onHandleKey(SkKey);
80 virtual bool onHandleKeyUp(SkKey);
81 virtual void onAddMenu(const SkOSMenu*) {}
82 virtual void onSetTitle(const char title[]) {}
83
84 // overrides from SkView
reed@android.comf2b98d62010-12-20 18:26:13 +000085 virtual bool handleInval(const SkRect*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000086 virtual bool onGetFocusView(SkView** focus) const;
87 virtual bool onSetFocusView(SkView* focus);
88
89private:
90 SkBitmap::Config fConfig;
91 SkBitmap fBitmap;
92 SkRegion fDirtyRgn;
93 Click* fClick; // to track clicks
94
95 SkTDArray<SkOSMenu*> fMenus;
96
97 SkView* fFocusView;
98 bool fWaitingOnInval;
reed@android.com0ae6b242008-12-23 16:49:54 +000099
100 SkString fTitle;
reed@android.comf2b98d62010-12-20 18:26:13 +0000101 SkMatrix fMatrix;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102
103 typedef SkView INHERITED;
104};
105
106///////////////////////////////////////////////////////////
107
reed@android.com671cd652009-05-22 20:44:12 +0000108#ifdef SK_USE_WXWIDGETS
109 #include "SkOSWindow_wxwidgets.h"
110#elif defined(SK_BUILD_FOR_MAC)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111 #include "SkOSWindow_Mac.h"
112#elif defined(SK_BUILD_FOR_WIN)
113 #include "SkOSWindow_Win.h"
scroggob7e9aee2011-03-15 15:15:15 +0000114#elif defined(SK_BUILD_FOR_UNIX)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115 #include "SkOSWindow_Unix.h"
reed@android.com671cd652009-05-22 20:44:12 +0000116#elif defined(SK_BUILD_FOR_SDL)
117 #include "SkOSWindow_SDL.h"
reed@android.comf2b98d62010-12-20 18:26:13 +0000118#elif defined(SK_BUILD_FOR_IOS)
119 #include "SkOSWindow_iOS.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000120#endif
121
122#endif
123