• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "SkMatrix.h"
23 #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 
33 class SkCanvas;
34 
35 class SkOSMenu;
36 
37 class SkWindow : public SkView {
38 public:
39             SkWindow();
40     virtual ~SkWindow();
41 
getBitmap()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 
isDirty()49     bool    isDirty() const { return !fDirtyRgn.isEmpty(); }
50     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
getDirtyBounds()55     const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
56 
57     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*);
64 
getTitle()65     const char* getTitle() const { return fTitle.c_str(); }
66     void    setTitle(const char title[]);
67 
getMatrix()68     const SkMatrix& getMatrix() const { return fMatrix; }
69     void    setMatrix(const SkMatrix&);
70     void    preConcat(const SkMatrix&);
71     void    postConcat(const SkMatrix&);
72 
73 protected:
74     virtual bool onEvent(const SkEvent&);
75     virtual bool onDispatchClick(int x, int y, Click::State);
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);
onAddMenu(const SkOSMenu *)81     virtual void onAddMenu(const SkOSMenu*) {}
onSetTitle(const char title[])82     virtual void onSetTitle(const char title[]) {}
83 
84     // overrides from SkView
85     virtual bool handleInval(const SkRect*);
86     virtual bool onGetFocusView(SkView** focus) const;
87     virtual bool onSetFocusView(SkView* focus);
88 
89 private:
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;
99 
100     SkString    fTitle;
101     SkMatrix    fMatrix;
102 
103     typedef SkView INHERITED;
104 };
105 
106 ///////////////////////////////////////////////////////////
107 
108 #ifdef SK_USE_WXWIDGETS
109     #include "SkOSWindow_wxwidgets.h"
110 #elif defined(SK_BUILD_FOR_MAC)
111     #include "SkOSWindow_Mac.h"
112 #elif defined(SK_BUILD_FOR_WIN)
113     #include "SkOSWindow_Win.h"
114 #elif defined(ANDROID)
115     #include "SkOSWindow_Android.h"
116 #elif defined(SK_BUILD_FOR_UNIX)
117   #include "SkOSWindow_Unix.h"
118 #elif defined(SK_BUILD_FOR_SDL)
119     #include "SkOSWindow_SDL.h"
120 #elif defined(SK_BUILD_FOR_IOS)
121     #include "SkOSWindow_iOS.h"
122 #endif
123 
124 #endif
125 
126