Adding support for recording the visible rect and auto-scrolling.

This commit is contained in:
Derek Sollenberger
2009-06-22 11:39:40 -04:00
parent 6cd7c86a8e
commit 5b011e35fb
3 changed files with 66 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ extern ANPCanvasInterfaceV0 gCanvasI;
extern ANPPaintInterfaceV0 gPaintI; extern ANPPaintInterfaceV0 gPaintI;
extern ANPPathInterfaceV0 gPathI; extern ANPPathInterfaceV0 gPathI;
extern ANPTypefaceInterfaceV0 gTypefaceI; extern ANPTypefaceInterfaceV0 gTypefaceI;
extern ANPWindowInterfaceV0 gWindowI;
static void inval(NPP instance) { static void inval(NPP instance) {
browser->invalidaterect(instance, NULL); browser->invalidaterect(instance, NULL);
@@ -101,7 +102,7 @@ BallAnimation::BallAnimation(NPP inst) : SubPlugin(inst) {
gTypefaceI.unref(tf); gTypefaceI.unref(tf);
//register for key and touch events //register for key and touch events
ANPEventFlags flags = kKey_ANPEventFlag | kTouch_ANPEventFlag; ANPEventFlags flags = kKey_ANPEventFlag | kTouch_ANPEventFlag | kVisibleRect_ANPEventFlag;
NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags);
if (err != NPERR_NO_ERROR) { if (err != NPERR_NO_ERROR) {
gLogI.log(inst, kError_ANPLogType, "Error selecting input events."); gLogI.log(inst, kError_ANPLogType, "Error selecting input events.");
@@ -186,6 +187,39 @@ void BallAnimation::draw(ANPCanvas* canvas) {
} }
} }
void BallAnimation::centerPluginOnScreen() {
NPP instance = this->inst();
PluginObject *obj = (PluginObject*) instance->pdata;
NPWindow *window = obj->window;
//find global (x,y) coordinates for center of the plugin
int pluginCenterX = window->x + (window->width / 2);
int pluginCenterY = window->y + (window->height / 2);
gLogI.log(instance, kDebug_ANPLogType, "---- %p Plugin Center: %d,%d : %d,%d",
instance, pluginCenterX, pluginCenterY, window->x, window->y);
//find global (x,y) coordinates for center of the visible screen
int screenCenterX = m_scrollX + (m_screenW / 2);
int screenCenterY = m_scrollY + (m_screenH / 2);
gLogI.log(instance, kDebug_ANPLogType, "---- %p Screen Center: %d,%d : %d,%d",
instance, screenCenterX, screenCenterY, m_scrollX, m_scrollY);
//compute the delta of the two coordinates
int deltaX = pluginCenterX - screenCenterX;
int deltaY = pluginCenterY - screenCenterY;
gLogI.log(instance, kDebug_ANPLogType, "---- %p Centering: %d,%d : %d,%d",
instance, deltaX, deltaY, m_scrollX + deltaX, m_scrollY + deltaY);
//move the visible screen
//webviewCore...
// (m_scrollX + deltaX, m_scrollY + deltaY)
gWindowI.scrollTo(instance, m_scrollX + deltaX, m_scrollY + deltaY);
}
int16 BallAnimation::handleEvent(const ANPEvent* evt) { int16 BallAnimation::handleEvent(const ANPEvent* evt) {
NPP instance = this->inst(); NPP instance = this->inst();
@@ -206,7 +240,18 @@ int16 BallAnimation::handleEvent(const ANPEvent* evt) {
browser->invalidaterect(instance, NULL); browser->invalidaterect(instance, NULL);
} }
return 1; return 1;
case kTouch_ANPEventType:
if (kDown_ANPTouchAction == evt->data.touch.action) {
centerPluginOnScreen();
}
return 1;
case kVisibleRect_ANPEventType:
m_scrollX = evt->data.visibleRect.x;
m_scrollY = evt->data.visibleRect.y;
m_screenW = evt->data.visibleRect.width;
m_screenH = evt->data.visibleRect.height;
return 1;
default: default:
break; break;
} }

View File

@@ -47,6 +47,12 @@ private:
ANPPaint* m_paint; ANPPaint* m_paint;
static const float SCALE = 0.1; static const float SCALE = 0.1;
void centerPluginOnScreen();
int m_scrollX;
int m_scrollY;
int m_screenH;
int m_screenW;
}; };
uint32_t getMSecs(); uint32_t getMSecs();

View File

@@ -67,8 +67,10 @@ ANPLogInterfaceV0 gLogI;
ANPPaintInterfaceV0 gPaintI; ANPPaintInterfaceV0 gPaintI;
ANPPathInterfaceV0 gPathI; ANPPathInterfaceV0 gPathI;
ANPTypefaceInterfaceV0 gTypefaceI; ANPTypefaceInterfaceV0 gTypefaceI;
ANPWindowInterfaceV0 gWindowI;
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
#define DEBUG_PLUGIN_EVENTS 0
NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context) NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context)
{ {
@@ -110,6 +112,7 @@ NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs,
{ kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI }, { kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI },
{ kTypefaceInterfaceV0_ANPGetValue, sizeof(gPaintI), &gTypefaceI }, { kTypefaceInterfaceV0_ANPGetValue, sizeof(gPaintI), &gTypefaceI },
{ kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI }, { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI },
{ kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI },
}; };
for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) { for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) {
gPairs[i].i->inSize = gPairs[i].size; gPairs[i].i->inSize = gPairs[i].size;
@@ -299,6 +302,7 @@ int16 NPP_HandleEvent(NPP instance, void* event)
PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata);
const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event); const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event);
#if DEBUG_PLUGIN_EVENTS
switch (evt->eventType) { switch (evt->eventType) {
case kDraw_ANPEventType: case kDraw_ANPEventType:
@@ -352,11 +356,20 @@ int16 NPP_HandleEvent(NPP instance, void* event)
} }
} }
} }
return 1; break;
case kVisibleRect_ANPEventType:
gLogI.log(instance, kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]",
instance, evt->data.visibleRect.x, evt->data.visibleRect.y,
evt->data.visibleRect.width, evt->data.visibleRect.height);
break;
default: default:
gLogI.log(instance, kError_ANPLogType, "---- %p Unknown Event [%d]",
instance, evt->eventType);
break; break;
} }
#endif
if(!obj->activePlugin) { if(!obj->activePlugin) {
gLogI.log(instance, kError_ANPLogType, "the active plugin is null."); gLogI.log(instance, kError_ANPLogType, "the active plugin is null.");