Add full-screen option to the sample paint plugin.
This commit is contained in:
@@ -37,6 +37,7 @@ extern ANPPathInterfaceV0 gPathI;
|
|||||||
extern ANPSurfaceInterfaceV0 gSurfaceI;
|
extern ANPSurfaceInterfaceV0 gSurfaceI;
|
||||||
extern ANPSystemInterfaceV0 gSystemI;
|
extern ANPSystemInterfaceV0 gSystemI;
|
||||||
extern ANPTypefaceInterfaceV0 gTypefaceI;
|
extern ANPTypefaceInterfaceV0 gTypefaceI;
|
||||||
|
extern ANPWindowInterfaceV0 gWindowI;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ PaintPlugin::PaintPlugin(NPP inst) : SurfaceSubPlugin(inst) {
|
|||||||
memset(&m_drawingSurface, 0, sizeof(m_drawingSurface));
|
memset(&m_drawingSurface, 0, sizeof(m_drawingSurface));
|
||||||
memset(&m_inputToggle, 0, sizeof(m_inputToggle));
|
memset(&m_inputToggle, 0, sizeof(m_inputToggle));
|
||||||
memset(&m_colorToggle, 0, sizeof(m_colorToggle));
|
memset(&m_colorToggle, 0, sizeof(m_colorToggle));
|
||||||
|
memset(&m_fullScreenToggle, 0, sizeof(m_fullScreenToggle));
|
||||||
memset(&m_clearSurface, 0, sizeof(m_clearSurface));
|
memset(&m_clearSurface, 0, sizeof(m_clearSurface));
|
||||||
|
|
||||||
// initialize the drawing surface
|
// initialize the drawing surface
|
||||||
@@ -170,7 +172,7 @@ void PaintPlugin::drawCleanPlugin(ANPCanvas* canvas) {
|
|||||||
m_inputToggle.top - fontMetrics.fTop, m_paintSurface);
|
m_inputToggle.top - fontMetrics.fTop, m_paintSurface);
|
||||||
|
|
||||||
// draw the color selector button
|
// draw the color selector button
|
||||||
m_colorToggle.left = (W/2) - (buttonWidth/2);
|
m_colorToggle.left = (W/3) - (buttonWidth/2);
|
||||||
m_colorToggle.top = H - buttonHeight - 5;
|
m_colorToggle.top = H - buttonHeight - 5;
|
||||||
m_colorToggle.right = m_colorToggle.left + buttonWidth;
|
m_colorToggle.right = m_colorToggle.left + buttonWidth;
|
||||||
m_colorToggle.bottom = m_colorToggle.top + buttonHeight;
|
m_colorToggle.bottom = m_colorToggle.top + buttonHeight;
|
||||||
@@ -179,6 +181,17 @@ void PaintPlugin::drawCleanPlugin(ANPCanvas* canvas) {
|
|||||||
gCanvasI.drawText(canvas, colorText, strlen(colorText), m_colorToggle.left + 5,
|
gCanvasI.drawText(canvas, colorText, strlen(colorText), m_colorToggle.left + 5,
|
||||||
m_colorToggle.top - fontMetrics.fTop, m_paintSurface);
|
m_colorToggle.top - fontMetrics.fTop, m_paintSurface);
|
||||||
|
|
||||||
|
// draw the full-screen toggle button
|
||||||
|
m_fullScreenToggle.left = ((W*2)/3) - (buttonWidth/2);
|
||||||
|
m_fullScreenToggle.top = H - buttonHeight - 5;
|
||||||
|
m_fullScreenToggle.right = m_fullScreenToggle.left + buttonWidth;
|
||||||
|
m_fullScreenToggle.bottom = m_fullScreenToggle.top + buttonHeight;
|
||||||
|
gCanvasI.drawRect(canvas, &m_fullScreenToggle, m_paintButton);
|
||||||
|
const char* fullScreenText = "Full";
|
||||||
|
gCanvasI.drawText(canvas, fullScreenText, strlen(fullScreenText),
|
||||||
|
m_fullScreenToggle.left + 5,
|
||||||
|
m_fullScreenToggle.top - fontMetrics.fTop, m_paintSurface);
|
||||||
|
|
||||||
// draw the clear canvas button
|
// draw the clear canvas button
|
||||||
m_clearSurface.left = W - buttonWidth - 5;
|
m_clearSurface.left = W - buttonWidth - 5;
|
||||||
m_clearSurface.top = H - buttonHeight - 5;
|
m_clearSurface.top = H - buttonHeight - 5;
|
||||||
@@ -306,6 +319,8 @@ int16 PaintPlugin::handleEvent(const ANPEvent* evt) {
|
|||||||
toggleInputMethod();
|
toggleInputMethod();
|
||||||
else if (rect == &m_colorToggle)
|
else if (rect == &m_colorToggle)
|
||||||
togglePaintColor();
|
togglePaintColor();
|
||||||
|
else if (rect == &m_fullScreenToggle)
|
||||||
|
gWindowI.requestFullScreen(inst());
|
||||||
else if (rect == &m_clearSurface)
|
else if (rect == &m_clearSurface)
|
||||||
drawCleanPlugin();
|
drawCleanPlugin();
|
||||||
}
|
}
|
||||||
@@ -316,6 +331,12 @@ int16 PaintPlugin::handleEvent(const ANPEvent* evt) {
|
|||||||
switch (evt->data.other[0]) {
|
switch (evt->data.other[0]) {
|
||||||
case kSurfaceCreated_CustomEvent:
|
case kSurfaceCreated_CustomEvent:
|
||||||
gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceCreated");
|
gLogI.log(kDebug_ANPLogType, " ---- customEvent: surfaceCreated");
|
||||||
|
/* The second draw call is added to cover up a problem in this
|
||||||
|
plugin and is not a recommended usage pattern. This plugin
|
||||||
|
does not correctly make partial updates to the double
|
||||||
|
buffered surface and this second call hides that problem.
|
||||||
|
*/
|
||||||
|
drawCleanPlugin();
|
||||||
drawCleanPlugin();
|
drawCleanPlugin();
|
||||||
break;
|
break;
|
||||||
case kSurfaceChanged_CustomEvent: {
|
case kSurfaceChanged_CustomEvent: {
|
||||||
@@ -358,6 +379,8 @@ ANPRectF* PaintPlugin::validTouch(int x, int y) {
|
|||||||
return &m_inputToggle;
|
return &m_inputToggle;
|
||||||
else if (fx > m_colorToggle.left && fx < m_colorToggle.right && fy > m_colorToggle.top && fy < m_colorToggle.bottom)
|
else if (fx > m_colorToggle.left && fx < m_colorToggle.right && fy > m_colorToggle.top && fy < m_colorToggle.bottom)
|
||||||
return &m_colorToggle;
|
return &m_colorToggle;
|
||||||
|
else if (fx > m_fullScreenToggle.left && fx < m_fullScreenToggle.right && fy > m_fullScreenToggle.top && fy < m_fullScreenToggle.bottom)
|
||||||
|
return &m_fullScreenToggle;
|
||||||
else if (fx > m_clearSurface.left && fx < m_clearSurface.right && fy > m_clearSurface.top && fy < m_clearSurface.bottom)
|
else if (fx > m_clearSurface.left && fx < m_clearSurface.right && fy > m_clearSurface.top && fy < m_clearSurface.bottom)
|
||||||
return &m_clearSurface;
|
return &m_clearSurface;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ private:
|
|||||||
ANPRectF m_drawingSurface;
|
ANPRectF m_drawingSurface;
|
||||||
ANPRectF m_inputToggle;
|
ANPRectF m_inputToggle;
|
||||||
ANPRectF m_colorToggle;
|
ANPRectF m_colorToggle;
|
||||||
|
ANPRectF m_fullScreenToggle;
|
||||||
ANPRectF m_clearSurface;
|
ANPRectF m_clearSurface;
|
||||||
|
|
||||||
ANPPaint* m_paintSurface;
|
ANPPaint* m_paintSurface;
|
||||||
|
|||||||
Reference in New Issue
Block a user