blob: 1c8f9a37d63e152f4b9f4168efafae3367e0925d [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"
22#include "SkRegion.h"
23#include "SkEvent.h"
24#include "SkKey.h"
25#include "SkTDArray.h"
26
27#ifdef SK_BUILD_FOR_WINCEx
28 #define SHOW_FPS
29#endif
30//#define USE_GX_SCREEN
31
32class SkOSMenu;
33
34class SkWindow : public SkView {
35public:
36 SkWindow();
37 virtual ~SkWindow();
38
39 const SkBitmap& getBitmap() const { return fBitmap; }
40
41 void setConfig(SkBitmap::Config);
42 void resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config);
43 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
44 void eraseRGB(U8CPU r, U8CPU g, U8CPU b);
45
46 bool isDirty() const { return !fDirtyRgn.isEmpty(); }
47 bool update(SkIRect* updateArea);
48 bool handleClick(int x, int y, Click::State);
49 bool handleChar(SkUnichar);
50 bool handleKey(SkKey);
51 bool handleKeyUp(SkKey);
52 bool handleMenu(uint32_t os_cmd);
53
54 void addMenu(SkOSMenu*);
reed@android.com0ae6b242008-12-23 16:49:54 +000055
56 const char* getTitle() const { return fTitle.c_str(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 void setTitle(const char title[]);
58
59protected:
60 virtual bool onEvent(const SkEvent&);
61
62 // called if part of our bitmap is invalidated
63 virtual void onHandleInval(const SkIRect&);
64 virtual bool onHandleChar(SkUnichar);
65 virtual bool onHandleKey(SkKey);
66 virtual bool onHandleKeyUp(SkKey);
67 virtual void onAddMenu(const SkOSMenu*) {}
68 virtual void onSetTitle(const char title[]) {}
69
70 // overrides from SkView
71 virtual bool handleInval(const SkRect&);
72 virtual bool onGetFocusView(SkView** focus) const;
73 virtual bool onSetFocusView(SkView* focus);
74
75private:
76 SkBitmap::Config fConfig;
77 SkBitmap fBitmap;
78 SkRegion fDirtyRgn;
79 Click* fClick; // to track clicks
80
81 SkTDArray<SkOSMenu*> fMenus;
82
83 SkView* fFocusView;
84 bool fWaitingOnInval;
reed@android.com0ae6b242008-12-23 16:49:54 +000085
86 SkString fTitle;
reed@android.com8a1c16f2008-12-17 15:59:43 +000087
88 typedef SkView INHERITED;
89};
90
91///////////////////////////////////////////////////////////
92
reed@android.com671cd652009-05-22 20:44:12 +000093#ifdef SK_USE_WXWIDGETS
94 #include "SkOSWindow_wxwidgets.h"
95#elif defined(SK_BUILD_FOR_MAC)
reed@android.com8a1c16f2008-12-17 15:59:43 +000096 #include "SkOSWindow_Mac.h"
97#elif defined(SK_BUILD_FOR_WIN)
98 #include "SkOSWindow_Win.h"
99#elif defined(SK_BUILD_FOR_UNIXx)
100 #include "SkOSWindow_Unix.h"
reed@android.com671cd652009-05-22 20:44:12 +0000101#elif defined(SK_BUILD_FOR_SDL)
102 #include "SkOSWindow_SDL.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103#endif
104
105#endif
106