SkWindow.h revision 0ae6b245f2b79bc04f0801b08fcf05abcf98fd6c
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 "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*);
55
56    const char* getTitle() const { return fTitle.c_str(); }
57    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;
85
86    SkString    fTitle;
87
88    typedef SkView INHERITED;
89};
90
91///////////////////////////////////////////////////////////
92
93#ifndef SK_USE_WXWIDGETS
94#ifdef SK_BUILD_FOR_MAC
95    #include "SkOSWindow_Mac.h"
96#elif defined(SK_BUILD_FOR_WIN)
97    #include "SkOSWindow_Win.h"
98#elif defined(SK_BUILD_FOR_UNIXx)
99  #include "SkOSWindow_Unix.h"
100#endif
101#else
102  #include "SkOSWindow_wxwidgets.h"
103#endif
104
105#endif
106
107