Home | History | Annotate | Download | only in Simple
      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 
     11 class SimpleWindow : public SkOSWindow {
     12 public:
     13 	SimpleWindow(void* hwnd);
     14 
     15 protected:
     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 
     26 private:
     27     typedef SkOSWindow INHERITED;
     28 };
     29 
     30 SimpleWindow::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 
     37 void 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 
     51 SkCanvas* 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 
     60 void SimpleWindow::afterChildren(SkCanvas* orig) {
     61 }
     62 
     63 bool SimpleWindow::onEvent(const SkEvent& evt) {
     64     return this->INHERITED::onEvent(evt);
     65 }
     66 
     67 bool SimpleWindow::onHandleChar(SkUnichar uni) {
     68     return this->INHERITED::onHandleChar(uni);
     69 }
     70 
     71 bool SimpleWindow::onHandleKey(SkKey key) {
     72     return this->INHERITED::onHandleKey(key);
     73 }
     74 
     75 void SimpleWindow::onSizeChange() {
     76     this->INHERITED::onSizeChange();
     77 }
     78 
     79 ///////////////////////////////////////////////////////////////////////////////
     80 
     81 SkOSWindow* create_sk_window(void* hwnd) {
     82 	return new SimpleWindow(hwnd);
     83 }
     84 
     85 void 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 
     92 void 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 
     99 void application_term() {
    100 	SkEvent::Term();
    101 	SkGraphics::Term();
    102 }
    103