blob: ca68e75760c850afe42cda3d3ac7ee573e9e2347 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkWindow_DEFINED
9#define SkWindow_DEFINED
10
11#include "SkView.h"
12#include "SkBitmap.h"
reed@android.comf2b98d62010-12-20 18:26:13 +000013#include "SkMatrix.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkRegion.h"
15#include "SkEvent.h"
16#include "SkKey.h"
17#include "SkTDArray.h"
18
19#ifdef SK_BUILD_FOR_WINCEx
20 #define SHOW_FPS
21#endif
22//#define USE_GX_SCREEN
23
reed@android.comf2b98d62010-12-20 18:26:13 +000024class SkCanvas;
25
reed@android.com8a1c16f2008-12-17 15:59:43 +000026class SkOSMenu;
27
28class SkWindow : public SkView {
29public:
30 SkWindow();
31 virtual ~SkWindow();
32
33 const SkBitmap& getBitmap() const { return fBitmap; }
34
35 void setConfig(SkBitmap::Config);
36 void resize(int width, int height, SkBitmap::Config config = SkBitmap::kNo_Config);
37 void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
38 void eraseRGB(U8CPU r, U8CPU g, U8CPU b);
39
40 bool isDirty() const { return !fDirtyRgn.isEmpty(); }
reed@google.comaa400ee2012-09-27 21:03:49 +000041 bool update(SkIRect* updateArea);
reed@android.comf2b98d62010-12-20 18:26:13 +000042 // does not call through to onHandleInval(), but does force the fDirtyRgn
43 // to be wide open. Call before update() to ensure we redraw everything.
44 void forceInvalAll();
45 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
46 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
47
reed@google.com4d5c26d2013-01-08 16:17:50 +000048 bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 bool handleChar(SkUnichar);
50 bool handleKey(SkKey);
51 bool handleKeyUp(SkKey);
reed@android.com8a1c16f2008-12-17 15:59:43 +000052
53 void addMenu(SkOSMenu*);
yangsu@google.com654d72f2011-08-01 17:27:33 +000054 const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
reed@android.com0ae6b242008-12-23 16:49:54 +000056 const char* getTitle() const { return fTitle.c_str(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 void setTitle(const char title[]);
58
reed@android.comf2b98d62010-12-20 18:26:13 +000059 const SkMatrix& getMatrix() const { return fMatrix; }
60 void setMatrix(const SkMatrix&);
61 void preConcat(const SkMatrix&);
62 void postConcat(const SkMatrix&);
63
reed@google.com5957f472012-10-01 20:31:56 +000064 virtual SkCanvas* createCanvas();
65
Scroggo8ac0d542011-06-21 14:44:57 +000066 virtual void onPDFSaved(const char title[], const char desc[],
67 const char path[]) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000068protected:
69 virtual bool onEvent(const SkEvent&);
reed@google.com4d5c26d2013-01-08 16:17:50 +000070 virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi);
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 // called if part of our bitmap is invalidated
72 virtual void onHandleInval(const SkIRect&);
73 virtual bool onHandleChar(SkUnichar);
74 virtual bool onHandleKey(SkKey);
75 virtual bool onHandleKeyUp(SkKey);
yangsu@google.com654d72f2011-08-01 17:27:33 +000076 virtual void onAddMenu(const SkOSMenu*) {};
77 virtual void onUpdateMenu(const SkOSMenu*) {};
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 virtual void onSetTitle(const char title[]) {}
79
80 // overrides from SkView
reed@android.comf2b98d62010-12-20 18:26:13 +000081 virtual bool handleInval(const SkRect*);
reed@android.com8a1c16f2008-12-17 15:59:43 +000082 virtual bool onGetFocusView(SkView** focus) const;
83 virtual bool onSetFocusView(SkView* focus);
84
85private:
86 SkBitmap::Config fConfig;
87 SkBitmap fBitmap;
88 SkRegion fDirtyRgn;
Scroggod3aed392011-06-22 13:26:56 +000089
90 SkTDArray<Click*> fClicks; // to track clicks
reed@android.com8a1c16f2008-12-17 15:59:43 +000091
92 SkTDArray<SkOSMenu*> fMenus;
93
94 SkView* fFocusView;
95 bool fWaitingOnInval;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000096
reed@android.com0ae6b242008-12-23 16:49:54 +000097 SkString fTitle;
reed@android.comf2b98d62010-12-20 18:26:13 +000098 SkMatrix fMatrix;
reed@android.com8a1c16f2008-12-17 15:59:43 +000099
100 typedef SkView INHERITED;
101};
102
tfarina@chromium.orge229e922012-09-27 13:44:57 +0000103////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000104
borenet@google.com7158e6a2012-11-01 17:43:44 +0000105#if defined(SK_BUILD_FOR_NACL)
106 #include "SkOSWindow_NaCl.h"
107#elif defined(SK_BUILD_FOR_MAC)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000108 #include "SkOSWindow_Mac.h"
109#elif defined(SK_BUILD_FOR_WIN)
110 #include "SkOSWindow_Win.h"
djsollen@google.com56c69772011-11-08 19:00:26 +0000111#elif defined(SK_BUILD_FOR_ANDROID)
Scroggof33d1532011-05-31 17:10:21 +0000112 #include "SkOSWindow_Android.h"
scroggob7e9aee2011-03-15 15:15:15 +0000113#elif defined(SK_BUILD_FOR_UNIX)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000114 #include "SkOSWindow_Unix.h"
reed@android.com671cd652009-05-22 20:44:12 +0000115#elif defined(SK_BUILD_FOR_SDL)
116 #include "SkOSWindow_SDL.h"
reed@android.comf2b98d62010-12-20 18:26:13 +0000117#elif defined(SK_BUILD_FOR_IOS)
118 #include "SkOSWindow_iOS.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119#endif
120
121#endif