From 4ed639f4a2edb7dfeb32426d9f1693b7fe09e16f Mon Sep 17 00:00:00 2001 From: "huiyu.eun" Date: Fri, 2 Dec 2016 11:15:28 +0900 Subject: [PATCH] [Tizen_SDL] Draw indicator without changing vertex and index. -SDL_tizenmouse.c : clean-up code Change-Id: I749fab7b0f400855eda0a8a0a93faac4ff1f34fa Signed-off-by: huiyu.eun --- src/video/tizen/SDL_tizenmouse.c | 62 ++++------- src/video/tizen/SDL_tizenopengles.c | 215 ++++++++++++------------------------ src/video/tizen/SDL_tizenopengles.h | 1 + src/video/tizen/SDL_tizenwindow.c | 5 +- 4 files changed, 95 insertions(+), 188 deletions(-) diff --git a/src/video/tizen/SDL_tizenmouse.c b/src/video/tizen/SDL_tizenmouse.c index 27e5846..f31fe31 100755 --- a/src/video/tizen/SDL_tizenmouse.c +++ b/src/video/tizen/SDL_tizenmouse.c @@ -249,6 +249,21 @@ Tizen_FiniMouse(void) ModelMatrix mMatrix; +SDL_bool isTouchIndicator(SDL_Window *window, int rot, int x, int y) +{ + + if(rot==0 && x > window->x && x < window->x + window->w && y > window->y && y < window->y + 52) + return SDL_TRUE; + + if(rot==90 && x > window->x && x < window->x + 52 && y > window->y && y < window->y + window->h) + return SDL_TRUE; + + if(rot==270 && x > window->x + window->w -52 && x < window->x + window->w && y > window->y && y < window->y + window->h) + return SDL_TRUE; + + return SDL_FALSE; +} + Eina_Bool _tizen_cb_event_mousedown_change(void *data, int type, void *event) { @@ -266,49 +281,12 @@ _tizen_cb_event_mousedown_change(void *data, int type, void *event) wind = window->driverdata; SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "mouse down (%d x %d)",e->x,e->y); - if(wind->rotation == 0) + if(isTouchIndicator(window, wind->rotation, e->x, e->y)) { - if(e->x > window->x && e->x < window->x + window->w && - e->y > window->y && e->y < window->y + 52) - { - ModelMatrixLoadIdentity(&mMatrix); - wind->indicator_show = SDL_TRUE; - wind->last_indicator_showtime = SDL_GetTicks(); - _tizen_indicator_event_filter(); - } - } - else if(wind->rotation == 90) - { - if(e->x > window->x && e->x < window->x + 52 && - e->y > window->y && e->y < window->y + window->h) - { - ModelMatrixLoadIdentity(&mMatrix); - wind->indicator_show = SDL_TRUE; - wind->last_indicator_showtime = SDL_GetTicks(); - _tizen_indicator_event_filter(); - } - }/* - else if(wind->rotation == 180) - { - if(e->x > window->x && e->x < window->x + window->w && - e->y > window->y + window->h -52 && e->y < window->y + window->h) - { - ModelMatrixLoadIdentity(&mMatrix); - wind->indicator_show = SDL_TRUE; - wind->last_indicator_showtime = SDL_GetTicks(); - _tizen_indicator_event_filter(); - } - }*/ - else if(wind->rotation == 270) - { - if(e->x > window->x + window->w -52 && e->x < window->x + window->w && - e->y > window->y && e->y < window->y + window->h) - { - ModelMatrixLoadIdentity(&mMatrix); - wind->indicator_show = SDL_TRUE; - wind->last_indicator_showtime = SDL_GetTicks(); - _tizen_indicator_event_filter(); - } + ModelMatrixTranslateInit(&mMatrix); + wind->indicator_show = SDL_TRUE; + wind->last_indicator_showtime = SDL_GetTicks(); + _tizen_indicator_event_filter(); } SDL_SendMouseMotion(window, 0, 0, e->x, e->y); diff --git a/src/video/tizen/SDL_tizenopengles.c b/src/video/tizen/SDL_tizenopengles.c index c2b6630..853597f 100755 --- a/src/video/tizen/SDL_tizenopengles.c +++ b/src/video/tizen/SDL_tizenopengles.c @@ -263,6 +263,64 @@ static void ModelMatrixTranslate(ModelMatrix* matrix, GLfloat x, GLfloat y, GLfl matrix->m[3][3] += (matrix->m[0][3] * x + matrix->m[1][3] * y + matrix->m[2][3] * z); } +void ModelMatrixTranslateInit(ModelMatrix* matrix) +{ + matrix->m[3][0] = matrix->m[3][1] = matrix->m[3][2] =0; + matrix->m[3][3] = 1; +} + +void multiply_matrix(ModelMatrix *lhs, ModelMatrix *rhs, ModelMatrix *r) +{ + int i, j, k; + float tmp[4][4]; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + tmp[j][i] = 0.0; + + for (k = 0; k < 4; k++) { + tmp[j][i] += lhs->m[k][i] * rhs->m[j][k]; + } + } + } + for (i = 0; i < 4; i++) { + for (j=0; j<4; j++) { + r->m[i][j] = tmp[i][j]; + } + } +} + +void rotate_indicator(ModelMatrix* matrix, const float anglex, const float angley, const float anglez) +{ + const float pi = 3.141592f; + ModelMatrix* temp = (ModelMatrix*)malloc(sizeof(ModelMatrix)); + float rz = 2.0f * pi * anglez / 360.0f; + float rx = 2.0f * pi * anglex / 360.0f; + float ry = 2.0f * pi * angley / 360.0f; + float sy = SDL_sinf(ry); + float cy = SDL_cosf(ry); + float sx = SDL_sinf(rx); + float cx = SDL_cosf(rx); + float sz = SDL_sinf(rz); + float cz = SDL_cosf(rz); + + ModelMatrixLoadIdentity(temp); + + temp->m[0][0] = cy * cz - sx * sy * sz; + temp->m[0][1] = cz * sx * sy + cy * sz; + temp->m[0][2] = -cx * sy; + temp->m[1][0] = -cx * sz; + temp->m[1][1] = cx * cz; + temp->m[1][2] = sx; + + temp->m[2][0] = cz * sy + cy * sx * sz; + temp->m[2][1] = -cy * cz * sx + sy * sz; + temp->m[2][2] = cx * cy; + + multiply_matrix(matrix, temp, matrix); + free(temp); +} + void Tizen_remote_indicator(int res_id) { if(!shared_info.tizen_rs) { @@ -298,21 +356,7 @@ void Tizen_DrawIndicator(SDL_Window *window) if(wdata->last_indicator_showtime + 3000< SDL_GetTicks()) { - switch(wdata->rotation) - { - case 0: - ModelMatrixTranslate(&mMatrix, 0.0f, 0.02f, 0.0f); - break; - case 90: - ModelMatrixTranslate(&mMatrix, -0.02f, 0.0f, 0.0f); - break; - case 180: - ModelMatrixTranslate(&mMatrix, 0.0f, -0.02f, 0.0f); - break; - case 270: - ModelMatrixTranslate(&mMatrix, 0.02f, 0.0f, 0.0f); - break; - } + ModelMatrixTranslate(&mMatrix, 0.0f, 0.02f, 0.0f); } if(wdata->last_indicator_showtime + 3500 last_indicator_showtime = SDL_GetTicks(); ecore_main_loop_iterate(); - if (!wind->support_pre_rotation) - SDL_IndicatorProcessEvent(window, wind->rotation); - else - SDL_IndicatorProcessEvent(window, 0); - + SDL_IndicatorProcessEvent(window, wind->rotation); _tizen_indicator_event_filter(); return 1; @@ -577,136 +617,27 @@ SDL_IndicatorProcessEvent(SDL_Window *window, int rot) LoadContext(&Mainctx); SDL_WindowData *wind = window->driverdata; - if( rot == 0) - { - SDL_Log("===rotate 0 degree!\n"); - vVertices[0] = 1.0f; - vVertices[1] = 1.0f; - vVertices[3] = -1.0f; - vVertices[4] = 0.92f; - vVertices[6] = 1.0f; - vVertices[7] = 0.92f; - vVertices[9] = 1.0f; - vVertices[10] = 1.0f; - vVertices[12] = -1.0f; - vVertices[13] = 1.0f; - vVertices[15] = -1.0f; - vVertices[16] = 0.92f; - - vCoord[0] = 1.0f; - vCoord[1] = 0.0f; - vCoord[2] = 0.0f; - vCoord[3] = 1.0f; - vCoord[4] = 1.0f; - vCoord[5] = 1.0f; - vCoord[6] = 1.0f; - vCoord[7] = 0.0f; - vCoord[8] = 0.0f; - vCoord[9] = 0.0f; - vCoord[10] = 0.0f; - vCoord[11] = 1.0f; - } - else if(rot == 90) - { - SDL_Log("===rotate 90 degree!\n"); - vVertices[0] = -0.86f; - vVertices[1] = 1.0f; - vVertices[3] = -0.86f; - vVertices[4] = -1.0f; - vVertices[6] = -1.0f; - vVertices[7] = 1.0f; - vVertices[9] = -1.0f; - vVertices[10] = -1.0f; - vVertices[12] = -0.86f; - vVertices[13] = -1.0f; - vVertices[15] = -1.0f; - vVertices[16] = 1.0f; - - vCoord[0] = 1.0f; - vCoord[1] = 1.0f; - vCoord[2] = 0.0f; - vCoord[3] = 1.0f; - vCoord[4] = 1.0f; - vCoord[5] = 0.0f; - vCoord[6] = 0.0f; - vCoord[7] = 0.0f; - vCoord[8] = 0.0f; - vCoord[9] = 1.0f; - vCoord[10] = 1.0f; - vCoord[11] = 0.0f; - } - else if(rot == 180) - { - SDL_Log("===rotate 180 degree!\n"); - vVertices[0] = -1.0f; - vVertices[1] = -1.0f; - vVertices[3] = -1.0f; - vVertices[4] = -0.92f; - vVertices[6] = 1.0f; - vVertices[7] = -1.0f; - vVertices[9] = 1.0f; - vVertices[10] = -0.92f; - vVertices[12] = -1.0f; - vVertices[13] = -0.92f; - vVertices[15] = 1.0f; - vVertices[16] = -1.0f; - - vCoord[0] = 1.0f; - vCoord[1] = 0.0f; - vCoord[2] = 1.0f; - vCoord[3] = 1.0f; - vCoord[4] = 0.0f; - vCoord[5] = 0.0f; - vCoord[6] = 0.0f; - vCoord[7] = 1.0f; - vCoord[8] = 1.0f; - vCoord[9] = 1.0f; - vCoord[10] = 0.0f; - vCoord[11] = 0.0f; - } - else if(rot == 270) - { - SDL_Log("===rotate 270 degree!\n"); - vVertices[0] = 1.0f; - vVertices[1] = 1.0f; - vVertices[3] = 0.86f; - vVertices[4] = 1.0f; - vVertices[6] = 1.0f; - vVertices[7] = -1.0f; - vVertices[9] = 0.86f; - vVertices[10] = -1.0f; - vVertices[12] = 0.86f; - vVertices[13] = 1.0f; - vVertices[15] = 1.0f; - vVertices[16] = -1.0f; - - vCoord[0] = 0.0f; - vCoord[1] = 0.0f; - vCoord[2] = 0.0f; - vCoord[3] = 1.0f; - vCoord[4] = 1.0f; - vCoord[5] = 0.0f; - vCoord[6] = 1.0f; - vCoord[7] = 1.0f; - vCoord[8] = 0.0f; - vCoord[9] = 1.0f; - vCoord[10] = 1.0f; - vCoord[11] = 0.0f; - - //Invisible Indicator - wind->indicator_show = SDL_FALSE; - _tizen_indicator_event_filter(); - } - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[wind->rotation/90]); + double ratio = 0.92f; + if( rot == 90 || rot ==270) + ratio = 0.86f; + + vVertices[4] = vVertices[7] = vVertices[16] = ratio; + + Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo); Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW); - Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[wind->rotation/90]); + Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo); Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW); ModelMatrixLoadIdentity(&mMatrix); + + if (!wind->support_pre_rotation) + rotate_indicator(&mMatrix, 0, 0, rot); + wind->indicator_show = SDL_TRUE; wind->last_indicator_showtime = SDL_GetTicks(); + _tizen_indicator_event_filter(); } diff --git a/src/video/tizen/SDL_tizenopengles.h b/src/video/tizen/SDL_tizenopengles.h index be66998..1025662 100755 --- a/src/video/tizen/SDL_tizenopengles.h +++ b/src/video/tizen/SDL_tizenopengles.h @@ -59,6 +59,7 @@ typedef struct }ModelMatrix; extern void ModelMatrixLoadIdentity(ModelMatrix* matrix); +extern void ModelMatrixTranslateInit(ModelMatrix* matrix); #endif #endif /* _SDL_tizenopengles_h */ diff --git a/src/video/tizen/SDL_tizenwindow.c b/src/video/tizen/SDL_tizenwindow.c index 1dbdabd..f7a87fd 100755 --- a/src/video/tizen/SDL_tizenwindow.c +++ b/src/video/tizen/SDL_tizenwindow.c @@ -509,10 +509,7 @@ _tizen_cb_event_window_rotate(void *data, int type EINA_UNUSED, void *event) { if(*hint != '\0') { - if (!wind->support_pre_rotation) - SDL_IndicatorProcessEvent(_this->current_glwin, wind->rotation); - else - SDL_IndicatorProcessEvent(_this->current_glwin, 0); + SDL_IndicatorProcessEvent(_this->current_glwin, wind->rotation); } } -- 2.7.4