This source file includes following definitions.
- FillRect
- height_
- DidChangeView
- HandleInputEvent
- HandleMove
- CreateInstance
- CreateModule
#include <algorithm>
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/mouse_cursor.h"
#include "ppapi/cpp/view.h"
void FillRect(pp::ImageData* image, int left, int top, int width, int height,
uint32_t color) {
for (int y = std::max(0, top);
y < std::min(image->size().height() - 1, top + height);
y++) {
for (int x = std::max(0, left);
x < std::min(image->size().width() - 1, left + width);
x++)
*image->GetAddr32(pp::Point(x, y)) = color;
}
}
class MyInstance : public pp::Instance {
public:
MyInstance(PP_Instance instance)
: pp::Instance(instance), width_(0), height_(0) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
}
virtual ~MyInstance() {
}
virtual void DidChangeView(const pp::View& view) {
width_ = view.GetRect().width();
height_ = view.GetRect().height();
}
virtual bool HandleInputEvent(const pp::InputEvent& event) {
switch (event.GetType()) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
return true;
case PP_INPUTEVENT_TYPE_MOUSEMOVE:
HandleMove(pp::MouseInputEvent(event));
return true;
case PP_INPUTEVENT_TYPE_KEYDOWN:
return true;
default:
return false;
}
}
void HandleMove(const pp::MouseInputEvent& event) {
pp::Point point = event.GetPosition();
int segments = 3;
if (point.y() < height_ / segments) {
pp::MouseCursor::SetCursor(this, PP_MOUSECURSOR_TYPE_WAIT);
} else if (point.y() < (height_ / segments) * 2) {
pp::ImageData cursor(this, pp::ImageData::GetNativeImageDataFormat(),
pp::Size(32, 32), true);
FillRect(&cursor, 0, 0, 32, 32, 0x80000080);
pp::MouseCursor::SetCursor(this, PP_MOUSECURSOR_TYPE_CUSTOM, cursor,
pp::Point(16, 16));
} else {
pp::MouseCursor::SetCursor(this, PP_MOUSECURSOR_TYPE_NONE);
}
}
private:
int width_;
int height_;
};
class MyModule : public pp::Module {
public:
MyModule() : pp::Module() {}
virtual ~MyModule() {}
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new MyInstance(instance);
}
};
namespace pp {
Module* CreateModule() {
return new MyModule();
}
}