blob: bd709386ec389b5b96d15c8132a71d700621b105 [file] [log] [blame]
caryclark936b7342014-07-11 12:14:51 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "iOSShell.h"
9
10#include "Resources.h"
11#include "SkCanvas.h"
12#include "SkCommandLineFlags.h"
13#include "SkGraphics.h"
14#include "SkWindow.h"
15#include "sk_tool_utils.h"
16
17//////////////////////////////////////////////////////////////////////////////
18
19static SkView* curr_view(SkWindow* wind) {
20 SkView::F2BIter iter(wind);
21 return iter.next();
22}
23
24ShellWindow::ShellWindow(void* hwnd, int argc, char** argv)
25 : INHERITED(hwnd) {
26 SkCommandLineFlags::Parse(argc, argv);
27}
28
29ShellWindow::~ShellWindow() {
30}
31
32///////////////////////////////////////////////////////////////////////////////
33
34bool ShellWindow::onDispatchClick(int x, int y, Click::State state,
35 void* owner, unsigned modi) {
36 int w = SkScalarRoundToInt(this->width());
37 int h = SkScalarRoundToInt(this->height());
38
39 // check for the resize-box
40 if (w - x < 16 && h - y < 16) {
41 return false; // let the OS handle the click
42 } else {
43 return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
44 }
45}
46
47void ShellWindow::onSizeChange() {
48 this->INHERITED::onSizeChange();
49
50 SkView::F2BIter iter(this);
51 SkView* view = iter.next();
52 view->setSize(this->width(), this->height());
53}
54
55void tool_main(int argc, char *argv[]);
56
57bool set_cmd_line_args(int argc, char *argv[], const char* resourceDir) {
58 for (int index = 0; index < argc; ++index) {
59 if (!strcmp("--test", argv[index])) {
60 SetResourcePath(resourceDir);
61 tool_main(argc - 1, argv);
62 return true;
63 }
64 }
65 return false;
66}
67
68// FIXME: this should be in a header
69SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
70SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
71 return new ShellWindow(hwnd, argc, argv);
72}
73
74// FIXME: this should be in a header
75void get_preferred_size(int* x, int* y, int* width, int* height);
76void get_preferred_size(int* x, int* y, int* width, int* height) {
77 *x = 10;
78 *y = 50;
79 *width = 640;
80 *height = 480;
81}
82
83// FIXME: this should be in a header
84void application_init();
85void application_init() {
86 SkGraphics::Init();
87 SkEvent::Init();
88}
89
90// FIXME: this should be in a header
91void application_term();
92void application_term() {
93 SkEvent::Term();
94 SkGraphics::Term();
95}