1#include "SkCanvas.h" 2#include "SkDevice.h" 3#include "SkGraphics.h" 4#include "SkPaint.h" 5#include "SkPicture.h" 6#include "SkStream.h" 7#include "SkWindow.h" 8 9////////////////////////////////////////////////////////////////////////////// 10 11class SimpleWindow : public SkOSWindow { 12public: 13 SimpleWindow(void* hwnd); 14 15protected: 16 virtual void onDraw(SkCanvas* canvas); 17 virtual bool onHandleKey(SkKey key); 18 virtual bool onHandleChar(SkUnichar); 19 virtual void onSizeChange(); 20 21 virtual SkCanvas* beforeChildren(SkCanvas*); 22 virtual void afterChildren(SkCanvas*); 23 24 virtual bool onEvent(const SkEvent& evt); 25 26private: 27 typedef SkOSWindow INHERITED; 28}; 29 30SimpleWindow::SimpleWindow(void* hwnd) : INHERITED(hwnd) { 31// this->setConfig(SkBitmap::kRGB_565_Config); 32 this->setConfig(SkBitmap::kARGB_8888_Config); 33 this->setVisibleP(true); 34 this->setTitle("Simple"); 35} 36 37void SimpleWindow::onDraw(SkCanvas* canvas) { 38 canvas->drawColor(SK_ColorWHITE); 39 40 const SkScalar w = this->width(); 41 const SkScalar h = this->height(); 42 43 SkPaint paint; 44 paint.setAntiAlias(true); 45 paint.setTextSize(SkIntToScalar(40)); 46 paint.setTextAlign(SkPaint::kCenter_Align); 47 48 canvas->drawText("Hello world", 11, w/2, h/2, paint); 49} 50 51SkCanvas* SimpleWindow::beforeChildren(SkCanvas* canvas) { 52 // can wack the canvas here, which will affect child views 53 // and can be "undone" in afterChildren() 54 // 55 // e.g. return a picture-canvas, or wack the clip or matrix, etc. 56 57 return canvas; 58} 59 60void SimpleWindow::afterChildren(SkCanvas* orig) { 61} 62 63bool SimpleWindow::onEvent(const SkEvent& evt) { 64 return this->INHERITED::onEvent(evt); 65} 66 67bool SimpleWindow::onHandleChar(SkUnichar uni) { 68 return this->INHERITED::onHandleChar(uni); 69} 70 71bool SimpleWindow::onHandleKey(SkKey key) { 72 return this->INHERITED::onHandleKey(key); 73} 74 75void SimpleWindow::onSizeChange() { 76 this->INHERITED::onSizeChange(); 77} 78 79/////////////////////////////////////////////////////////////////////////////// 80 81SkOSWindow* create_sk_window(void* hwnd) { 82 return new SimpleWindow(hwnd); 83} 84 85void get_preferred_size(int* x, int* y, int* width, int* height) { 86 *x = 10; 87 *y = 50; 88 *width = 640; 89 *height = 480; 90} 91 92void application_init() { 93// setenv("ANDROID_ROOT", "../../../data", 0); 94 setenv("ANDROID_ROOT", "/android/device/data", 0); 95 SkGraphics::Init(true); 96 SkEvent::Init(); 97} 98 99void application_term() { 100 SkEvent::Term(); 101 SkGraphics::Term(); 102} 103