diff --git a/intern/ghost/test/gears/GHOST_C-Test.c b/intern/ghost/test/gears/GHOST_C-Test.c index b26d8e09430..4086fbba730 100644 --- a/intern/ghost/test/gears/GHOST_C-Test.c +++ b/intern/ghost/test/gears/GHOST_C-Test.c @@ -46,22 +46,22 @@ #include "GHOST_C-api.h" #if defined(WIN32) || defined(__APPLE__) - #ifdef WIN32 - #include - #include - #else /* WIN32 */ - /* __APPLE__ is defined */ - #include - #endif /* WIN32 */ +# ifdef WIN32 +# include +# include +# else /* WIN32 */ + /* __APPLE__ is defined */ +# include +# endif /* WIN32 */ #else /* defined(WIN32) || defined(__APPLE__) */ - #include +# include #endif /* defined(WIN32) || defined(__APPLE__) */ static void gearsTimerProc(GHOST_TimerTaskHandle task, GHOST_TUns64 time); int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData); -static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0; +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; static GLfloat fAngle = 0.0; static int sExitRequested = 0; static GHOST_SystemHandle shSystem = NULL; @@ -87,34 +87,34 @@ static void gearGL(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GL const double pi = 3.14159264; r0 = inner_radius; - r1 = (float)(outer_radius - tooth_depth/2.0); - r2 = (float)(outer_radius + tooth_depth/2.0); + r1 = (float)(outer_radius - tooth_depth / 2.0); + r2 = (float)(outer_radius + tooth_depth / 2.0); - da = (float)(2.0*pi / teeth / 4.0); + da = (float)(2.0 * pi / teeth / 4.0); glShadeModel(GL_FLAT); glNormal3f(0.0, 0.0, 1.0); /* draw front face */ glBegin(GL_QUAD_STRIP); - for (i=0;i<=teeth;i++) { - angle = (float)(i * 2.0*pi / teeth); - glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5)); - glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5)); - glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5)); - glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5)); + for (i = 0; i <= teeth; i++) { + angle = (float)(i * 2.0 * pi / teeth); + glVertex3f((float)(r0 * cos(angle)), (float)(r0 * sin(angle)), (float)(width * 0.5)); + glVertex3f((float)(r1 * cos(angle)), (float)(r1 * sin(angle)), (float)(width * 0.5)); + glVertex3f((float)(r0 * cos(angle)), (float)(r0 * sin(angle)), (float)(width * 0.5)); + glVertex3f((float)(r1 * cos(angle + 3 * da)), (float)(r1 * sin(angle + 3 * da)), (float)(width * 0.5)); } glEnd(); /* draw front sides of teeth */ glBegin(GL_QUADS); - da = (float)(2.0*pi / teeth / 4.0); - for (i=0;iz > 0) - { - view_rotz += 5.f; - } - else - { - view_rotz -= 5.f; - } + wheelData = (GHOST_TEventWheelData *)GHOST_GetEventData(hEvent); + if (wheelData->z > 0) + { + view_rotz += 5.f; + } + else { + view_rotz -= 5.f; + } } break; - case GHOST_kEventKeyUp: - break; + case GHOST_kEventKeyUp: + break; - case GHOST_kEventKeyDown: + case GHOST_kEventKeyDown: { - keyData = (GHOST_TEventKeyData*)GHOST_GetEventData(hEvent); + keyData = (GHOST_TEventKeyData *)GHOST_GetEventData(hEvent); switch (keyData->key) { - case GHOST_kKeyC: + case GHOST_kKeyC: { cursor = sCursor; cursor++; @@ -336,62 +335,60 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) GHOST_SetCursorShape(window, sCursor); } break; - case GHOST_kKeyF: - if (!GHOST_GetFullScreen(shSystem)) - { - /* Begin fullscreen mode */ - setting.bpp = 24; - setting.frequency = 85; - setting.xPixels = 640; - setting.yPixels = 480; - - /* - setting.bpp = 16; - setting.frequency = 75; - setting.xPixels = 640; - setting.yPixels = 480; - */ + case GHOST_kKeyF: + if (!GHOST_GetFullScreen(shSystem)) + { + /* Begin fullscreen mode */ + setting.bpp = 24; + setting.frequency = 85; + setting.xPixels = 640; + setting.yPixels = 480; - sFullScreenWindow = GHOST_BeginFullScreen(shSystem, &setting, + /* + setting.bpp = 16; + setting.frequency = 75; + setting.xPixels = 640; + setting.yPixels = 480; + */ - FALSE /* stereo flag */); - } - else - { - GHOST_EndFullScreen(shSystem); - sFullScreenWindow = 0; - } - break; - case GHOST_kKeyH: + sFullScreenWindow = GHOST_BeginFullScreen(shSystem, &setting, + + FALSE /* stereo flag */); + } + else { + GHOST_EndFullScreen(shSystem); + sFullScreenWindow = 0; + } + break; + case GHOST_kKeyH: { visibility = GHOST_GetCursorVisibility(window); GHOST_SetCursorVisibility(window, !visibility); } break; - case GHOST_kKeyQ: - if (GHOST_GetFullScreen(shSystem)) - { - GHOST_EndFullScreen(shSystem); - sFullScreenWindow = 0; - } - sExitRequested = 1; - case GHOST_kKeyT: - if (!sTestTimer) - { - sTestTimer = GHOST_InstallTimer(shSystem, 0, 1000, testTimerProc, NULL); - } - else - { - GHOST_RemoveTimer(shSystem, sTestTimer); - sTestTimer = 0; - } - break; - case GHOST_kKeyW: + case GHOST_kKeyQ: + if (GHOST_GetFullScreen(shSystem)) + { + GHOST_EndFullScreen(shSystem); + sFullScreenWindow = 0; + } + sExitRequested = 1; + case GHOST_kKeyT: + if (!sTestTimer) + { + sTestTimer = GHOST_InstallTimer(shSystem, 0, 1000, testTimerProc, NULL); + } + else { + GHOST_RemoveTimer(shSystem, sTestTimer); + sTestTimer = 0; + } + break; + case GHOST_kKeyW: { if (sMainWindow) { char *title = GHOST_GetTitle(sMainWindow); - char *ntitle = malloc(strlen(title)+2); + char *ntitle = malloc(strlen(title) + 2); sprintf(ntitle, "%s-", title); GHOST_SetTitle(sMainWindow, ntitle); @@ -401,21 +398,20 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } } break; - default: - break; + default: + break; } } break; - case GHOST_kEventWindowClose: + case GHOST_kEventWindowClose: { GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent); if (window2 == sMainWindow) { sExitRequested = 1; } - else - { + else { if (sGearsTimer) { GHOST_RemoveTimer(shSystem, sGearsTimer); @@ -426,13 +422,13 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } break; - case GHOST_kEventWindowActivate: - handled = 0; - break; - case GHOST_kEventWindowDeactivate: - handled = 0; - break; - case GHOST_kEventWindowUpdate: + case GHOST_kEventWindowActivate: + handled = 0; + break; + case GHOST_kEventWindowDeactivate: + handled = 0; + break; + case GHOST_kEventWindowUpdate: { GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent); if (!GHOST_ValidWindow(shSystem, window2)) @@ -443,18 +439,18 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } break; - default: - handled = 0; - break; + default: + handled = 0; + break; } return handled; } -int main(int argc, char** argv) +int main(int argc, char **argv) { - char* title1 = "gears - main window"; - char* title2 = "gears - secondary window"; + char *title1 = "gears - main window"; + char *title2 = "gears - secondary window"; GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(processEvent, NULL); /* Create the system */ @@ -465,15 +461,15 @@ int main(int argc, char** argv) { /* Create the main window */ sMainWindow = GHOST_CreateWindow(shSystem, - title1, - 10, - 64, - 320, - 200, - GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, - FALSE, - FALSE); + title1, + 10, + 64, + 320, + 200, + GHOST_kWindowStateNormal, + GHOST_kDrawingContextTypeOpenGL, + FALSE, + FALSE); if (!sMainWindow) { printf("could not create main window\n"); @@ -482,15 +478,15 @@ int main(int argc, char** argv) /* Create a secondary window */ sSecondaryWindow = GHOST_CreateWindow(shSystem, - title2, - 340, - 64, - 320, - 200, - GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, - FALSE, - FALSE); + title2, + 340, + 64, + 320, + 200, + GHOST_kWindowStateNormal, + GHOST_kDrawingContextTypeOpenGL, + FALSE, + FALSE); if (!sSecondaryWindow) { printf("could not create secondary window\n"); @@ -498,11 +494,11 @@ int main(int argc, char** argv) } /* Install a timer to have the gears running */ - sGearsTimer = GHOST_InstallTimer(shSystem, - 0, - 10, - gearsTimerProc, - sMainWindow); + sGearsTimer = GHOST_InstallTimer(shSystem, + 0, + 10, + gearsTimerProc, + sMainWindow); /* Enter main loop */ while (!sExitRequested) @@ -547,8 +543,7 @@ static void gearsTimerProc(GHOST_TimerTaskHandle hTask, GHOST_TUns64 time) /* Running full screen */ GHOST_InvalidateWindow(sFullScreenWindow); } - else - { + else { if (GHOST_ValidWindow(shSystem, hWindow)) { GHOST_InvalidateWindow(hWindow); diff --git a/intern/ghost/test/gears/GHOST_Test.cpp b/intern/ghost/test/gears/GHOST_Test.cpp index 2e8a9e88fd1..c51b72ad271 100644 --- a/intern/ghost/test/gears/GHOST_Test.cpp +++ b/intern/ghost/test/gears/GHOST_Test.cpp @@ -40,17 +40,17 @@ #include #if defined(WIN32) || defined(__APPLE__) - #ifdef WIN32 - #include - #include +# ifdef WIN32 +# include +# include - #include - #else // WIN32 +# include +# else // WIN32 // __APPLE__ is defined - #include - #endif // WIN32 +# include +# endif // WIN32 #else // defined(WIN32) || defined(__APPLE__) - #include +# include #endif // defined(WIN32) || defined(__APPLE__) #include "STR_String.h" diff --git a/intern/ghost/test/multitest/Basic.c b/intern/ghost/test/multitest/Basic.c index 4453a074484..74b9f806872 100644 --- a/intern/ghost/test/multitest/Basic.c +++ b/intern/ghost/test/multitest/Basic.c @@ -27,37 +27,47 @@ #include "Basic.h" -int min_i(int a, int b) { - return (altidx)?dkf:ltf; - int lx= rect[1][0]-i-1; - int ly= rect[0][1]+i; - - glColor3f(col[0]*stf, col[1]*stf, col[2]*stf); - for (corner=0; corner<4; corner++) { - int x= (corner==0 || corner==1)?(rect[0][0]+i):(rect[1][0]-i-1); - int y= (corner==0 || corner==3)?(rect[0][1]+i):(rect[1][1]-i-1); + for (i = 0; i < width; i++) { + float ltf = pow(lt[i], 1.0 / 2.2), dkf = pow(dk[i], 1.0 / 2.2); + float stf = (dkidx > ltidx) ? dkf : ltf; + int lx = rect[1][0] - i - 1; + int ly = rect[0][1] + i; - if (ltidx==corner) - glColor3f(col[0]*ltf, col[1]*ltf, col[2]*ltf); - if (dkidx==corner) - glColor3f(col[0]*dkf, col[1]*dkf, col[2]*dkf); + glColor3f(col[0] * stf, col[1] * stf, col[2] * stf); + for (corner = 0; corner < 4; corner++) { + int x = (corner == 0 || corner == 1) ? (rect[0][0] + i) : (rect[1][0] - i - 1); + int y = (corner == 0 || corner == 3) ? (rect[0][1] + i) : (rect[1][1] - i - 1); + + if (ltidx == corner) + glColor3f(col[0] * ltf, col[1] * ltf, col[2] * ltf); + if (dkidx == corner) + glColor3f(col[0] * dkf, col[1] * dkf, col[2] * dkf); glVertex2i(lx, ly); - glVertex2i(lx= x, ly= y); + glVertex2i(lx = x, ly = y); } } glEnd(); glColor3fv(col); - glRecti(rect[0][0]+width, rect[0][1]+width, rect[1][0]-width, rect[1][1]-width); + glRecti(rect[0][0] + width, rect[0][1] + width, rect[1][0] - width, rect[1][1] - width); } void rect_bevel_smooth(int rect[2][2], int width) { - float *lt= malloc(sizeof(*lt)*width); - float *dk= malloc(sizeof(*dk)*width); + float *lt = malloc(sizeof(*lt) * width); + float *dk = malloc(sizeof(*dk) * width); float col[4]; int i; - for (i=0; ilmbut[0]) { glClearColor(0.5, 0.5, 0.5, 1); - } else { + } + else { glClearColor(1, 1, 1, 1); } glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.5, 0.6, 0.8); - glRecti(mw->tmouse[0]-5, mw->tmouse[1]-5, mw->tmouse[0]+5, mw->tmouse[1]+5); + glRecti(mw->tmouse[0] - 5, mw->tmouse[1] - 5, mw->tmouse[0] + 5, mw->tmouse[1] + 5); GHOST_SwapWindowBuffers(mw->win); } static void mainwindow_do_reshape(MainWindow *mw) { - GHOST_RectangleHandle bounds= GHOST_GetClientBounds(mw->win); + GHOST_RectangleHandle bounds = GHOST_GetClientBounds(mw->win); GHOST_ActivateWindowDrawingContext(mw->win); - mw->size[0]= GHOST_GetWidthRectangle(bounds); - mw->size[1]= GHOST_GetHeightRectangle(bounds); + mw->size[0] = GHOST_GetWidthRectangle(bounds); + mw->size[1] = GHOST_GetHeightRectangle(bounds); glViewport(0, 0, mw->size[0], mw->size[1]); @@ -183,176 +184,179 @@ static void mainwindow_do_reshape(MainWindow *mw) { } static void mainwindow_do_key(MainWindow *mw, GHOST_TKey key, int press) { - switch(key) { - case GHOST_kKeyC: - if (press) - GHOST_SetCursorShape(mw->win, (GHOST_TStandardCursor) (rand()%(GHOST_kStandardCursorNumCursors))); - break; - case GHOST_kKeyLeftBracket: - if (press) - GHOST_SetCursorVisibility(mw->win, 0); - break; - case GHOST_kKeyRightBracket: - if (press) - GHOST_SetCursorVisibility(mw->win, 1); - break; - case GHOST_kKeyE: - if (press) - multitestapp_toggle_extra_window(mw->app); - break; - case GHOST_kKeyQ: - if (press) - multitestapp_exit(mw->app); - break; - case GHOST_kKeyT: - if (press) - mainwindow_log(mw, "TextTest~|`hello`\"world\",<>/"); - break; - case GHOST_kKeyR: - if (press) { - int i; - - mainwindow_log(mw, "Invalidating window 10 times"); - for (i=0; i<10; i++) - GHOST_InvalidateWindow(mw->win); - } - break; - case GHOST_kKeyF11: - if (press) { - GHOST_SetWindowOrder(mw->win, GHOST_kWindowOrderBottom); - } - break; + switch (key) { + case GHOST_kKeyC: + if (press) + GHOST_SetCursorShape(mw->win, (GHOST_TStandardCursor) (rand() % (GHOST_kStandardCursorNumCursors))); + break; + case GHOST_kKeyLeftBracket: + if (press) + GHOST_SetCursorVisibility(mw->win, 0); + break; + case GHOST_kKeyRightBracket: + if (press) + GHOST_SetCursorVisibility(mw->win, 1); + break; + case GHOST_kKeyE: + if (press) + multitestapp_toggle_extra_window(mw->app); + break; + case GHOST_kKeyQ: + if (press) + multitestapp_exit(mw->app); + break; + case GHOST_kKeyT: + if (press) + mainwindow_log(mw, "TextTest~|`hello`\"world\",<>/"); + break; + case GHOST_kKeyR: + if (press) { + int i; + + mainwindow_log(mw, "Invalidating window 10 times"); + for (i = 0; i < 10; i++) + GHOST_InvalidateWindow(mw->win); + } + break; + case GHOST_kKeyF11: + if (press) { + GHOST_SetWindowOrder(mw->win, GHOST_kWindowOrderBottom); + } + break; } } static void mainwindow_do_move(MainWindow *mw, int x, int y) { - mw->lmouse[0]= x, mw->lmouse[1]= y; + mw->lmouse[0] = x, mw->lmouse[1] = y; if (mw->lmbut[0]) { - mw->tmouse[0]= x, mw->tmouse[1]= y; + mw->tmouse[0] = x, mw->tmouse[1] = y; GHOST_InvalidateWindow(mw->win); } } static void mainwindow_do_button(MainWindow *mw, int which, int press) { - if (which==GHOST_kButtonMaskLeft) { - mw->lmbut[0]= press; - mw->tmouse[0]= mw->lmouse[0], mw->tmouse[1]= mw->lmouse[1]; + if (which == GHOST_kButtonMaskLeft) { + mw->lmbut[0] = press; + mw->tmouse[0] = mw->lmouse[0], mw->tmouse[1] = mw->lmouse[1]; GHOST_InvalidateWindow(mw->win); - } else if (which==GHOST_kButtonMaskLeft) { - mw->lmbut[1]= press; - } else if (which==GHOST_kButtonMaskLeft) { - mw->lmbut[2]= press; + } + else if (which == GHOST_kButtonMaskLeft) { + mw->lmbut[1] = press; + } + else if (which == GHOST_kButtonMaskLeft) { + mw->lmbut[2] = press; } } static void mainwindow_handle(void *priv, GHOST_EventHandle evt) { - MainWindow *mw= priv; - GHOST_TEventType type= GHOST_GetEventType(evt); + MainWindow *mw = priv; + GHOST_TEventType type = GHOST_GetEventType(evt); char buf[256]; event_to_buf(evt, buf); mainwindow_log(mw, buf); switch (type) { - case GHOST_kEventCursorMove: { - GHOST_TEventCursorData *cd= GHOST_GetEventData(evt); - int x, y; - GHOST_ScreenToClient(mw->win, cd->x, cd->y, &x, &y); - mainwindow_do_move(mw, x, mw->size[1]-y-1); - break; - } - case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { - GHOST_TEventButtonData *bd= GHOST_GetEventData(evt); - mainwindow_do_button(mw, bd->button, (type == GHOST_kEventButtonDown)); - break; - } - case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { - GHOST_TEventKeyData *kd= GHOST_GetEventData(evt); - mainwindow_do_key(mw, kd->key, (type == GHOST_kEventKeyDown)); - break; - } + case GHOST_kEventCursorMove: { + GHOST_TEventCursorData *cd = GHOST_GetEventData(evt); + int x, y; + GHOST_ScreenToClient(mw->win, cd->x, cd->y, &x, &y); + mainwindow_do_move(mw, x, mw->size[1] - y - 1); + break; + } + case GHOST_kEventButtonDown: + case GHOST_kEventButtonUp: { + GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); + mainwindow_do_button(mw, bd->button, (type == GHOST_kEventButtonDown)); + break; + } + case GHOST_kEventKeyDown: + case GHOST_kEventKeyUp: { + GHOST_TEventKeyData *kd = GHOST_GetEventData(evt); + mainwindow_do_key(mw, kd->key, (type == GHOST_kEventKeyDown)); + break; + } - case GHOST_kEventWindowUpdate: - mainwindow_do_draw(mw); - break; - case GHOST_kEventWindowSize: - mainwindow_do_reshape(mw); - break; + case GHOST_kEventWindowUpdate: + mainwindow_do_draw(mw); + break; + case GHOST_kEventWindowSize: + mainwindow_do_reshape(mw); + break; } } /**/ static void mainwindow_timer_proc(GHOST_TimerTaskHandle task, GHOST_TUns64 time) { - MainWindow *mw= GHOST_GetTimerTaskUserData(task); + MainWindow *mw = GHOST_GetTimerTaskUserData(task); char buf[64]; - sprintf(buf, "timer: %6.2f", (double) ((GHOST_TInt64) time)/1000); + sprintf(buf, "timer: %6.2f", (double) ((GHOST_TInt64) time) / 1000); mainwindow_log(mw, buf); } MainWindow *mainwindow_new(MultiTestApp *app) { - GHOST_SystemHandle sys= multitestapp_get_system(app); + GHOST_SystemHandle sys = multitestapp_get_system(app); GHOST_WindowHandle win; - win= GHOST_CreateWindow(sys, "MultiTest:Main", 40, 40, 400, 400, - GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, - FALSE, FALSE); + win = GHOST_CreateWindow(sys, "MultiTest:Main", 40, 40, 400, 400, + GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, + FALSE, FALSE); if (win) { - MainWindow *mw= MEM_callocN(sizeof(*mw), "mainwindow_new"); - mw->app= app; - mw->win= win; + MainWindow *mw = MEM_callocN(sizeof(*mw), "mainwindow_new"); + mw->app = app; + mw->win = win; GHOST_SetWindowUserData(mw->win, windowdata_new(mw, mainwindow_handle)); GHOST_InstallTimer(sys, 1000, 10000, mainwindow_timer_proc, mw); return mw; - } else { + } + else { return NULL; } } void mainwindow_free(MainWindow *mw) { - GHOST_SystemHandle sys= multitestapp_get_system(mw->app); + GHOST_SystemHandle sys = multitestapp_get_system(mw->app); windowdata_free(GHOST_GetWindowUserData(mw->win)); GHOST_DisposeWindow(sys, mw->win); MEM_freeN(mw); } - /* - * LoggerWindow - */ +/* + * LoggerWindow + */ struct _LoggerWindow { - MultiTestApp *app; + MultiTestApp *app; - GHOST_WindowHandle win; + GHOST_WindowHandle win; #ifdef USE_BMF - BMF_Font *font; + BMF_Font *font; #else - int font; + int font; #endif - int fonttexid; - int fontheight; + int fonttexid; + int fontheight; - int size[2]; + int size[2]; - int ndisplines; - int textarea[2][2]; - ScrollBar *scroll; + int ndisplines; + int textarea[2][2]; + ScrollBar *scroll; - char **loglines; - int nloglines, logsize; + char **loglines; + int nloglines, logsize; - int lmbut[3]; - int lmouse[2]; + int lmbut[3]; + int lmouse[2]; }; #define SCROLLBAR_PAD 2 @@ -361,19 +365,19 @@ struct _LoggerWindow { static void loggerwindow_recalc_regions(LoggerWindow *lw) { int nscroll[2][2]; - nscroll[0][0]= SCROLLBAR_PAD; - nscroll[0][1]= SCROLLBAR_PAD; - nscroll[1][0]= nscroll[0][0] + SCROLLBAR_WIDTH; - nscroll[1][1]= lw->size[1] - SCROLLBAR_PAD - 1; + nscroll[0][0] = SCROLLBAR_PAD; + nscroll[0][1] = SCROLLBAR_PAD; + nscroll[1][0] = nscroll[0][0] + SCROLLBAR_WIDTH; + nscroll[1][1] = lw->size[1] - SCROLLBAR_PAD - 1; - lw->textarea[0][0]= nscroll[1][0] + TEXTAREA_PAD; - lw->textarea[0][1]= TEXTAREA_PAD; - lw->textarea[1][0]= lw->size[0] - TEXTAREA_PAD - 1; - lw->textarea[1][1]= lw->size[1] - TEXTAREA_PAD - 1; + lw->textarea[0][0] = nscroll[1][0] + TEXTAREA_PAD; + lw->textarea[0][1] = TEXTAREA_PAD; + lw->textarea[1][0] = lw->size[0] - TEXTAREA_PAD - 1; + lw->textarea[1][1] = lw->size[1] - TEXTAREA_PAD - 1; - lw->ndisplines= (lw->textarea[1][1]-lw->textarea[0][1])/lw->fontheight; + lw->ndisplines = (lw->textarea[1][1] - lw->textarea[0][1]) / lw->fontheight; - scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines/lw->nloglines); + scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines / lw->nloglines); scrollbar_set_rect(lw->scroll, nscroll); } @@ -390,12 +394,12 @@ static void loggerwindow_setup_window_gl(LoggerWindow *lw) { } static void loggerwindow_do_reshape(LoggerWindow *lw) { - GHOST_RectangleHandle bounds= GHOST_GetClientBounds(lw->win); + GHOST_RectangleHandle bounds = GHOST_GetClientBounds(lw->win); GHOST_ActivateWindowDrawingContext(lw->win); - lw->size[0]= GHOST_GetWidthRectangle(bounds); - lw->size[1]= GHOST_GetHeightRectangle(bounds); + lw->size[0] = GHOST_GetWidthRectangle(bounds); + lw->size[1] = GHOST_GetHeightRectangle(bounds); loggerwindow_recalc_regions(lw); loggerwindow_setup_window_gl(lw); @@ -421,15 +425,16 @@ static void loggerwindow_do_draw(LoggerWindow *lw) { if (scrollbar_is_scrolling(lw->scroll)) { glColor3f(0.6, 0.7, 0.5); - } else { + } + else { glColor3f(0.9, 0.9, 0.92); } rect_bevel_smooth(sb_thumb, 1); - startline= scrollbar_get_thumbpos(lw->scroll)*(lw->nloglines-1); - ndisplines= min_i(lw->ndisplines, lw->nloglines-startline); + startline = scrollbar_get_thumbpos(lw->scroll) * (lw->nloglines - 1); + ndisplines = min_i(lw->ndisplines, lw->nloglines - startline); - if (lw->fonttexid!=-1) { + if (lw->fonttexid != -1) { glBindTexture(GL_TEXTURE_2D, lw->fonttexid); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -437,17 +442,18 @@ static void loggerwindow_do_draw(LoggerWindow *lw) { glEnable(GL_TEXTURE_2D); } glColor3f(0, 0, 0); - for (i=0; iloglines[(lw->nloglines-1)-(i+startline)]; - int x_pos= lw->textarea[0][0] + 4; - int y_pos= lw->textarea[0][1] + 4 + i*lw->fontheight; + for (i = 0; i < ndisplines; i++) { + /* stored in reverse order */ + char *line = lw->loglines[(lw->nloglines - 1) - (i + startline)]; + int x_pos = lw->textarea[0][0] + 4; + int y_pos = lw->textarea[0][1] + 4 + i * lw->fontheight; #ifdef USE_BMF - if (lw->fonttexid==-1) { + if (lw->fonttexid == -1) { glRasterPos2i(x_pos, y_pos); BMF_DrawString(lw->font, line); - } else { + } + else { BMF_DrawStringTexture(lw->font, line, x_pos, y_pos, 0.0); } #else @@ -457,7 +463,7 @@ static void loggerwindow_do_draw(LoggerWindow *lw) { } #ifdef USE_BMF - if (lw->fonttexid!=-1) { + if (lw->fonttexid != -1) { glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); } @@ -467,7 +473,7 @@ static void loggerwindow_do_draw(LoggerWindow *lw) { } static void loggerwindow_do_move(LoggerWindow *lw, int x, int y) { - lw->lmouse[0]= x, lw->lmouse[1]= y; + lw->lmouse[0] = x, lw->lmouse[1] = y; if (scrollbar_is_scrolling(lw->scroll)) { scrollbar_keep_scrolling(lw->scroll, y); @@ -476,8 +482,8 @@ static void loggerwindow_do_move(LoggerWindow *lw, int x, int y) { } static void loggerwindow_do_button(LoggerWindow *lw, int which, int press) { - if (which==GHOST_kButtonMaskLeft) { - lw->lmbut[0]= press; + if (which == GHOST_kButtonMaskLeft) { + lw->lmbut[0] = press; if (press) { if (scrollbar_contains_pt(lw->scroll, lw->lmouse)) { @@ -485,124 +491,128 @@ static void loggerwindow_do_button(LoggerWindow *lw, int which, int press) { GHOST_SetCursorShape(lw->win, GHOST_kStandardCursorUpDown); GHOST_InvalidateWindow(lw->win); } - } else { + } + else { if (scrollbar_is_scrolling(lw->scroll)) { scrollbar_stop_scrolling(lw->scroll); GHOST_SetCursorShape(lw->win, GHOST_kStandardCursorDefault); GHOST_InvalidateWindow(lw->win); } } - } else if (which==GHOST_kButtonMaskMiddle) { - lw->lmbut[1]= press; - } else if (which==GHOST_kButtonMaskRight) { - lw->lmbut[2]= press; + } + else if (which == GHOST_kButtonMaskMiddle) { + lw->lmbut[1] = press; + } + else if (which == GHOST_kButtonMaskRight) { + lw->lmbut[2] = press; } } static void loggerwindow_do_key(LoggerWindow *lw, GHOST_TKey key, int press) { switch (key) { - case GHOST_kKeyQ: - if (press) - multitestapp_exit(lw->app); - break; + case GHOST_kKeyQ: + if (press) + multitestapp_exit(lw->app); + break; } } static void loggerwindow_handle(void *priv, GHOST_EventHandle evt) { - LoggerWindow *lw= priv; - GHOST_TEventType type= GHOST_GetEventType(evt); + LoggerWindow *lw = priv; + GHOST_TEventType type = GHOST_GetEventType(evt); - switch(type) { - case GHOST_kEventCursorMove: { - GHOST_TEventCursorData *cd= GHOST_GetEventData(evt); - int x, y; - GHOST_ScreenToClient(lw->win, cd->x, cd->y, &x, &y); - loggerwindow_do_move(lw, x, lw->size[1]-y-1); - break; - } - case GHOST_kEventButtonDown: - case GHOST_kEventButtonUp: { - GHOST_TEventButtonData *bd= GHOST_GetEventData(evt); - loggerwindow_do_button(lw, bd->button, (type == GHOST_kEventButtonDown)); - break; - } - case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { - GHOST_TEventKeyData *kd= GHOST_GetEventData(evt); - loggerwindow_do_key(lw, kd->key, (type == GHOST_kEventKeyDown)); - break; - } - - case GHOST_kEventWindowUpdate: - loggerwindow_do_draw(lw); - break; - case GHOST_kEventWindowSize: - loggerwindow_do_reshape(lw); - break; + switch (type) { + case GHOST_kEventCursorMove: { + GHOST_TEventCursorData *cd = GHOST_GetEventData(evt); + int x, y; + GHOST_ScreenToClient(lw->win, cd->x, cd->y, &x, &y); + loggerwindow_do_move(lw, x, lw->size[1] - y - 1); + break; + } + case GHOST_kEventButtonDown: + case GHOST_kEventButtonUp: { + GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); + loggerwindow_do_button(lw, bd->button, (type == GHOST_kEventButtonDown)); + break; + } + case GHOST_kEventKeyDown: + case GHOST_kEventKeyUp: { + GHOST_TEventKeyData *kd = GHOST_GetEventData(evt); + loggerwindow_do_key(lw, kd->key, (type == GHOST_kEventKeyDown)); + break; + } + + case GHOST_kEventWindowUpdate: + loggerwindow_do_draw(lw); + break; + case GHOST_kEventWindowSize: + loggerwindow_do_reshape(lw); + break; } } /**/ LoggerWindow *loggerwindow_new(MultiTestApp *app) { - GHOST_SystemHandle sys= multitestapp_get_system(app); + GHOST_SystemHandle sys = multitestapp_get_system(app); GHOST_TUns32 screensize[2]; GHOST_WindowHandle win; GHOST_GetMainDisplayDimensions(sys, &screensize[0], &screensize[1]); - win= GHOST_CreateWindow(sys, "MultiTest:Logger", 40, screensize[1]-432, - 800, 300, GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, FALSE, FALSE); + win = GHOST_CreateWindow(sys, "MultiTest:Logger", 40, screensize[1] - 432, + 800, 300, GHOST_kWindowStateNormal, + GHOST_kDrawingContextTypeOpenGL, FALSE, FALSE); if (win) { - LoggerWindow *lw= MEM_callocN(sizeof(*lw), "loggerwindow_new"); + LoggerWindow *lw = MEM_callocN(sizeof(*lw), "loggerwindow_new"); int bbox[2][2]; - lw->app= app; - lw->win= win; + lw->app = app; + lw->win = win; #ifdef USE_BMF - lw->font= BMF_GetFont(BMF_kScreen12); - lw->fonttexid= BMF_GetFontTexture(lw->font); + lw->font = BMF_GetFont(BMF_kScreen12); + lw->fonttexid = BMF_GetFontTexture(lw->font); BMF_GetBoundingBox(lw->font, &bbox[0][0], &bbox[0][1], &bbox[1][0], &bbox[1][1]); - lw->fontheight= rect_height(bbox); + lw->fontheight = rect_height(bbox); #else - lw->font= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); + lw->font = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); BLF_size(lw->font, 11, 72); - lw->fontheight= BLF_height(lw->font, "A_"); + lw->fontheight = BLF_height(lw->font, "A_"); #endif - lw->nloglines= lw->logsize= 0; - lw->loglines= MEM_mallocN(sizeof(*lw->loglines)*lw->nloglines, "loglines"); + lw->nloglines = lw->logsize = 0; + lw->loglines = MEM_mallocN(sizeof(*lw->loglines) * lw->nloglines, "loglines"); - lw->scroll= scrollbar_new(2, 40); + lw->scroll = scrollbar_new(2, 40); GHOST_SetWindowUserData(lw->win, windowdata_new(lw, loggerwindow_handle)); loggerwindow_do_reshape(lw); return lw; - } else { + } + else { return NULL; } } void loggerwindow_log(LoggerWindow *lw, char *line) { - if (lw->nloglines==lw->logsize) { - lw->loglines= memdbl(lw->loglines, &lw->logsize, sizeof(*lw->loglines)); + if (lw->nloglines == lw->logsize) { + lw->loglines = memdbl(lw->loglines, &lw->logsize, sizeof(*lw->loglines)); } - lw->loglines[lw->nloglines++]= string_dup(line); - scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines/lw->nloglines); + lw->loglines[lw->nloglines++] = string_dup(line); + scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines / lw->nloglines); GHOST_InvalidateWindow(lw->win); } void loggerwindow_free(LoggerWindow *lw) { - GHOST_SystemHandle sys= multitestapp_get_system(lw->app); + GHOST_SystemHandle sys = multitestapp_get_system(lw->app); int i; - for (i=0; inloglines; i++) { + for (i = 0; i < lw->nloglines; i++) { MEM_freeN(lw->loglines[i]); } MEM_freeN(lw->loglines); @@ -612,17 +622,17 @@ void loggerwindow_free(LoggerWindow *lw) { MEM_freeN(lw); } - /* - * ExtraWindow - */ +/* + * ExtraWindow + */ typedef struct { - MultiTestApp *app; + MultiTestApp *app; - GHOST_WindowHandle win; + GHOST_WindowHandle win; - int size[2]; + int size[2]; } ExtraWindow; static void extrawindow_do_draw(ExtraWindow *ew) { @@ -632,18 +642,18 @@ static void extrawindow_do_draw(ExtraWindow *ew) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8, 0.8, 0.8); - glRecti(10, 10, ew->size[0]-10, ew->size[1]-10); + glRecti(10, 10, ew->size[0] - 10, ew->size[1] - 10); GHOST_SwapWindowBuffers(ew->win); } static void extrawindow_do_reshape(ExtraWindow *ew) { - GHOST_RectangleHandle bounds= GHOST_GetClientBounds(ew->win); + GHOST_RectangleHandle bounds = GHOST_GetClientBounds(ew->win); GHOST_ActivateWindowDrawingContext(ew->win); - ew->size[0]= GHOST_GetWidthRectangle(bounds); - ew->size[1]= GHOST_GetHeightRectangle(bounds); + ew->size[0] = GHOST_GetWidthRectangle(bounds); + ew->size[1] = GHOST_GetHeightRectangle(bounds); glViewport(0, 0, ew->size[0], ew->size[1]); @@ -658,18 +668,18 @@ static void extrawindow_do_reshape(ExtraWindow *ew) { static void extrawindow_do_key(ExtraWindow *ew, GHOST_TKey key, int press) { switch (key) { - case GHOST_kKeyE: - if (press) - multitestapp_toggle_extra_window(ew->app); - break; + case GHOST_kKeyE: + if (press) + multitestapp_toggle_extra_window(ew->app); + break; } } static void extrawindow_spin_cursor(ExtraWindow *ew, GHOST_TUns64 time) { GHOST_TUns8 bitmap[16][2]; GHOST_TUns8 mask[16][2]; - double ftime= (double) ((GHOST_TInt64) time)/1000; - float angle= fmod(ftime, 1.0) * 3.1415*2; + double ftime = (double) ((GHOST_TInt64) time) / 1000; + float angle = fmod(ftime, 1.0) * 3.1415 * 2; int i; memset(&bitmap, 0, sizeof(bitmap)); @@ -680,128 +690,130 @@ static void extrawindow_spin_cursor(ExtraWindow *ew, GHOST_TUns64 time) { bitmap[2][0] |= mask[2][0] |= 0xF; bitmap[3][0] |= mask[3][0] |= 0xF; - for (i=0; i<7; i++) { - int x = 7 + cos(angle)*i; - int y = 7 + sin(angle)*i; - - mask[y][x/8] |= (1 << (x%8)); + for (i = 0; i < 7; i++) { + int x = 7 + cos(angle) * i; + int y = 7 + sin(angle) * i; + + mask[y][x / 8] |= (1 << (x % 8)); } - for (i=0; i<64; i++) { - float v= (i/63.0) * 3.1415*2; - int x = 7 + cos(v)*7; - int y = 7 + sin(v)*7; + for (i = 0; i < 64; i++) { + float v = (i / 63.0) * 3.1415 * 2; + int x = 7 + cos(v) * 7; + int y = 7 + sin(v) * 7; - mask[y][x/8] |= (1 << (x%8)); + mask[y][x / 8] |= (1 << (x % 8)); } GHOST_SetCustomCursorShape(ew->win, bitmap, mask, 0, 0); } static void extrawindow_handle(void *priv, GHOST_EventHandle evt) { - ExtraWindow *ew= priv; - GHOST_TEventType type= GHOST_GetEventType(evt); + ExtraWindow *ew = priv; + GHOST_TEventType type = GHOST_GetEventType(evt); char buf[256]; event_to_buf(evt, buf); loggerwindow_log(multitestapp_get_logger(ew->app), buf); switch (type) { - case GHOST_kEventKeyDown: - case GHOST_kEventKeyUp: { - GHOST_TEventKeyData *kd= GHOST_GetEventData(evt); - extrawindow_do_key(ew, kd->key, (type == GHOST_kEventKeyDown)); - break; - } + case GHOST_kEventKeyDown: + case GHOST_kEventKeyUp: { + GHOST_TEventKeyData *kd = GHOST_GetEventData(evt); + extrawindow_do_key(ew, kd->key, (type == GHOST_kEventKeyDown)); + break; + } - case GHOST_kEventCursorMove: { - extrawindow_spin_cursor(ew, GHOST_GetEventTime(evt)); - break; - } - - case GHOST_kEventWindowClose: - multitestapp_free_extrawindow(ew->app); - break; - case GHOST_kEventWindowUpdate: - extrawindow_do_draw(ew); - break; - case GHOST_kEventWindowSize: - extrawindow_do_reshape(ew); - break; + case GHOST_kEventCursorMove: { + extrawindow_spin_cursor(ew, GHOST_GetEventTime(evt)); + break; + } + + case GHOST_kEventWindowClose: + multitestapp_free_extrawindow(ew->app); + break; + case GHOST_kEventWindowUpdate: + extrawindow_do_draw(ew); + break; + case GHOST_kEventWindowSize: + extrawindow_do_reshape(ew); + break; } } /**/ ExtraWindow *extrawindow_new(MultiTestApp *app) { - GHOST_SystemHandle sys= multitestapp_get_system(app); + GHOST_SystemHandle sys = multitestapp_get_system(app); GHOST_WindowHandle win; - win= GHOST_CreateWindow(sys, "MultiTest:Extra", 500, 40, 400, 400, - GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, - FALSE, FALSE); + win = GHOST_CreateWindow(sys, "MultiTest:Extra", 500, 40, 400, 400, + GHOST_kWindowStateNormal, GHOST_kDrawingContextTypeOpenGL, + FALSE, FALSE); if (win) { - ExtraWindow *ew= MEM_callocN(sizeof(*ew), "mainwindow_new"); - ew->app= app; - ew->win= win; + ExtraWindow *ew = MEM_callocN(sizeof(*ew), "mainwindow_new"); + ew->app = app; + ew->win = win; GHOST_SetWindowUserData(ew->win, windowdata_new(ew, extrawindow_handle)); return ew; - } else { + } + else { return NULL; } } void extrawindow_free(ExtraWindow *ew) { - GHOST_SystemHandle sys= multitestapp_get_system(ew->app); + GHOST_SystemHandle sys = multitestapp_get_system(ew->app); windowdata_free(GHOST_GetWindowUserData(ew->win)); GHOST_DisposeWindow(sys, ew->win); MEM_freeN(ew); } - /* - * MultiTestApp - */ +/* + * MultiTestApp + */ struct _MultiTestApp { - GHOST_SystemHandle sys; - MainWindow *main; - LoggerWindow *logger; - ExtraWindow *extra; + GHOST_SystemHandle sys; + MainWindow *main; + LoggerWindow *logger; + ExtraWindow *extra; - int exit; + int exit; }; static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr data) { - MultiTestApp *app= data; + MultiTestApp *app = data; GHOST_WindowHandle win; - win= GHOST_GetEventWindow(evt); + win = GHOST_GetEventWindow(evt); if (win && !GHOST_ValidWindow(app->sys, win)) { loggerwindow_log(app->logger, "WARNING: bad event, non-valid window\n"); return 1; } if (win) { - WindowData *wb= GHOST_GetWindowUserData(win); + WindowData *wb = GHOST_GetWindowUserData(win); windowdata_handle(wb, evt); - } else { - GHOST_TEventType type= GHOST_GetEventType(evt); - - /* GHOST_kEventQuit are the only 'system' events, - * that is, events without a window. - */ - switch(type) { - case GHOST_kEventQuit: - app->exit= 1; - break; + } + else { + GHOST_TEventType type = GHOST_GetEventType(evt); - default: - fatal("Unhandled system event: %d (%s)\n", type, eventtype_to_string(type)); - break; + /* GHOST_kEventQuit are the only 'system' events, + * that is, events without a window. + */ + switch (type) { + case GHOST_kEventQuit: + app->exit = 1; + break; + + default: + fatal("Unhandled system event: %d (%s)\n", type, eventtype_to_string(type)); + break; } } @@ -811,26 +823,26 @@ static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr dat /**/ MultiTestApp *multitestapp_new(void) { - MultiTestApp *app= MEM_mallocN(sizeof(*app), "multitestapp_new"); - GHOST_EventConsumerHandle consumer= GHOST_CreateEventConsumer(multitest_event_handler, app); + MultiTestApp *app = MEM_mallocN(sizeof(*app), "multitestapp_new"); + GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(multitest_event_handler, app); - app->sys= GHOST_CreateSystem(); + app->sys = GHOST_CreateSystem(); if (!app->sys) fatal("Unable to create ghost system"); if (!GHOST_AddEventConsumer(app->sys, consumer)) fatal("Unable to add multitest event consumer "); - app->main= mainwindow_new(app); + app->main = mainwindow_new(app); if (!app->main) fatal("Unable to create main window"); - app->logger= loggerwindow_new(app); + app->logger = loggerwindow_new(app); if (!app->logger) fatal("Unable to create logger window"); - app->extra= NULL; - app->exit= 0; + app->extra = NULL; + app->exit = 0; return app; } @@ -845,19 +857,20 @@ GHOST_SystemHandle multitestapp_get_system(MultiTestApp *app) { void multitestapp_free_extrawindow(MultiTestApp *app) { extrawindow_free(app->extra); - app->extra= NULL; + app->extra = NULL; } void multitestapp_toggle_extra_window(MultiTestApp *app) { if (app->extra) { multitestapp_free_extrawindow(app); - } else { - app->extra= extrawindow_new(app); + } + else { + app->extra = extrawindow_new(app); } } void multitestapp_exit(MultiTestApp *app) { - app->exit= 1; + app->exit = 1; } void multitestapp_run(MultiTestApp *app) { @@ -874,14 +887,14 @@ void multitestapp_free(MultiTestApp *app) { MEM_freeN(app); } - /***/ +/***/ int main(int argc, char **argv) { #ifndef USE_BMF BLF_init(11, 72); #endif - MultiTestApp *app= multitestapp_new(); + MultiTestApp *app = multitestapp_new(); multitestapp_run(app); multitestapp_free(app); diff --git a/intern/ghost/test/multitest/ScrollBar.c b/intern/ghost/test/multitest/ScrollBar.c index 25a34dd8e70..a57300c38f0 100644 --- a/intern/ghost/test/multitest/ScrollBar.c +++ b/intern/ghost/test/multitest/ScrollBar.c @@ -35,107 +35,124 @@ #include "ScrollBar.h" struct _ScrollBar { - int rect[2][2]; - float thumbpos, thumbpct; + int rect[2][2]; + float thumbpos, thumbpct; - int inset; - int minthumb; + int inset; + int minthumb; - int scrolling; - float scrolloffs; + int scrolling; + float scrolloffs; }; -static int scrollbar_get_thumbH(ScrollBar *sb) { - int scrollable_h= rect_height(sb->rect) - 2*sb->inset; +static int scrollbar_get_thumbH(ScrollBar *sb) +{ + int scrollable_h = rect_height(sb->rect) - 2 * sb->inset; - return clamp_i(sb->thumbpct*scrollable_h, sb->minthumb, scrollable_h); + return clamp_i(sb->thumbpct * scrollable_h, sb->minthumb, scrollable_h); } -static int scrollbar_get_thumbableH(ScrollBar *sb) { - int scrollable_h= rect_height(sb->rect) - 2*sb->inset; - int thumb_h= scrollbar_get_thumbH(sb); + +static int scrollbar_get_thumbableH(ScrollBar *sb) +{ + int scrollable_h = rect_height(sb->rect) - 2 * sb->inset; + int thumb_h = scrollbar_get_thumbH(sb); return scrollable_h - thumb_h; } -static float scrollbar_co_to_pos(ScrollBar *sb, int yco) { - int thumb_h= scrollbar_get_thumbH(sb); - int thumbable_h= scrollbar_get_thumbableH(sb); - int thumbable_y= (sb->rect[0][1]+sb->inset) + thumb_h/2; +static float scrollbar_co_to_pos(ScrollBar *sb, int yco) +{ + int thumb_h = scrollbar_get_thumbH(sb); + int thumbable_h = scrollbar_get_thumbableH(sb); + int thumbable_y = (sb->rect[0][1] + sb->inset) + thumb_h / 2; - return (float) (yco-thumbable_y)/thumbable_h; + return (float) (yco - thumbable_y) / thumbable_h; } /**/ -ScrollBar *scrollbar_new(int inset, int minthumb) { - ScrollBar *sb= MEM_callocN(sizeof(*sb), "scrollbar_new"); - sb->inset= inset; - sb->minthumb= minthumb; +ScrollBar *scrollbar_new(int inset, int minthumb) +{ + ScrollBar *sb = MEM_callocN(sizeof(*sb), "scrollbar_new"); + sb->inset = inset; + sb->minthumb = minthumb; return sb; } -void scrollbar_get_thumb(ScrollBar *sb, int thumb_r[2][2]) { - int thumb_h= scrollbar_get_thumbH(sb); - int thumbable_h= scrollbar_get_thumbableH(sb); +void scrollbar_get_thumb(ScrollBar *sb, int thumb_r[2][2]) +{ + int thumb_h = scrollbar_get_thumbH(sb); + int thumbable_h = scrollbar_get_thumbableH(sb); - thumb_r[0][0]= sb->rect[0][0]+sb->inset; - thumb_r[1][0]= sb->rect[1][0]-sb->inset; + thumb_r[0][0] = sb->rect[0][0] + sb->inset; + thumb_r[1][0] = sb->rect[1][0] - sb->inset; - thumb_r[0][1]= sb->rect[0][1]+sb->inset + sb->thumbpos*thumbable_h; - thumb_r[1][1]= thumb_r[0][1] + thumb_h; + thumb_r[0][1] = sb->rect[0][1] + sb->inset + sb->thumbpos * thumbable_h; + thumb_r[1][1] = thumb_r[0][1] + thumb_h; } -int scrollbar_is_scrolling(ScrollBar *sb) { +int scrollbar_is_scrolling(ScrollBar *sb) +{ return sb->scrolling; } int scrollbar_contains_pt(ScrollBar *sb, int pt[2]) { return rect_contains_pt(sb->rect, pt); } -void scrollbar_start_scrolling(ScrollBar *sb, int yco) { - int thumb_h_2= scrollbar_get_thumbH(sb)/2; - int thumbable_h= scrollbar_get_thumbableH(sb); - float npos= scrollbar_co_to_pos(sb, yco); +void scrollbar_start_scrolling(ScrollBar *sb, int yco) +{ + int thumb_h_2 = scrollbar_get_thumbH(sb) / 2; + int thumbable_h = scrollbar_get_thumbableH(sb); + float npos = scrollbar_co_to_pos(sb, yco); - sb->scrolloffs= sb->thumbpos - npos; - if (fabs(sb->scrolloffs) >= (float) thumb_h_2/thumbable_h) { - sb->scrolloffs= 0.0; + sb->scrolloffs = sb->thumbpos - npos; + if (fabs(sb->scrolloffs) >= (float) thumb_h_2 / thumbable_h) { + sb->scrolloffs = 0.0; } - sb->scrolling= 1; - sb->thumbpos= clamp_f(npos + sb->scrolloffs, 0.0, 1.0); + sb->scrolling = 1; + sb->thumbpos = clamp_f(npos + sb->scrolloffs, 0.0, 1.0); } -void scrollbar_keep_scrolling(ScrollBar *sb, int yco) { - float npos= scrollbar_co_to_pos(sb, yco); +void scrollbar_keep_scrolling(ScrollBar *sb, int yco) +{ + float npos = scrollbar_co_to_pos(sb, yco); - sb->thumbpos= clamp_f(npos + sb->scrolloffs, 0.0, 1.0); + sb->thumbpos = clamp_f(npos + sb->scrolloffs, 0.0, 1.0); } -void scrollbar_stop_scrolling(ScrollBar *sb) { - sb->scrolling= 0; - sb->scrolloffs= 0.0; +void scrollbar_stop_scrolling(ScrollBar *sb) +{ + sb->scrolling = 0; + sb->scrolloffs = 0.0; } -void scrollbar_set_thumbpct(ScrollBar *sb, float pct) { - sb->thumbpct= pct; +void scrollbar_set_thumbpct(ScrollBar *sb, float pct) +{ + sb->thumbpct = pct; } -void scrollbar_set_thumbpos(ScrollBar *sb, float pos) { - sb->thumbpos= clamp_f(pos, 0.0, 1.0); +void scrollbar_set_thumbpos(ScrollBar *sb, float pos) +{ + sb->thumbpos = clamp_f(pos, 0.0, 1.0); } -void scrollbar_set_rect(ScrollBar *sb, int rect[2][2]) { +void scrollbar_set_rect(ScrollBar *sb, int rect[2][2]) +{ rect_copy(sb->rect, rect); } -float scrollbar_get_thumbpct(ScrollBar *sb) { +float scrollbar_get_thumbpct(ScrollBar *sb) +{ return sb->thumbpct; } -float scrollbar_get_thumbpos(ScrollBar *sb) { +float scrollbar_get_thumbpos(ScrollBar *sb) +{ return sb->thumbpos; } -void scrollbar_get_rect(ScrollBar *sb, int rect_r[2][2]) { +void scrollbar_get_rect(ScrollBar *sb, int rect_r[2][2]) +{ rect_copy(rect_r, sb->rect); } -void scrollbar_free(ScrollBar *sb) { +void scrollbar_free(ScrollBar *sb) +{ MEM_freeN(sb); } diff --git a/intern/ghost/test/multitest/Util.c b/intern/ghost/test/multitest/Util.c index dfef6e347b0..bacd0a313d4 100644 --- a/intern/ghost/test/multitest/Util.c +++ b/intern/ghost/test/multitest/Util.c @@ -35,28 +35,31 @@ #include "Util.h" -void* memdbl(void *mem, int *size_pr, int item_size) { - int cur_size= *size_pr; - int new_size= cur_size?(cur_size*2):1; - void *nmem= MEM_mallocN(new_size*item_size, "memdbl"); +void *memdbl(void *mem, int *size_pr, int item_size) +{ + int cur_size = *size_pr; + int new_size = cur_size ? (cur_size * 2) : 1; + void *nmem = MEM_mallocN(new_size * item_size, "memdbl"); - memcpy(nmem, mem, cur_size*item_size); + memcpy(nmem, mem, cur_size * item_size); MEM_freeN(mem); - *size_pr= new_size; + *size_pr = new_size; return nmem; } -char* string_dup(char *str) { - int len= strlen(str); - char *nstr= MEM_mallocN(len + 1, "string_dup"); +char *string_dup(char *str) +{ + int len = strlen(str); + char *nstr = MEM_mallocN(len + 1, "string_dup"); - memcpy(nstr, str, len+1); + memcpy(nstr, str, len + 1); return nstr; } -void fatal(char *fmt, ...) { +void fatal(char *fmt, ...) +{ va_list ap; fprintf(stderr, "FATAL: "); diff --git a/intern/ghost/test/multitest/WindowData.c b/intern/ghost/test/multitest/WindowData.c index 1eac99635c5..de4992ab2a0 100644 --- a/intern/ghost/test/multitest/WindowData.c +++ b/intern/ghost/test/multitest/WindowData.c @@ -34,22 +34,25 @@ #include "WindowData.h" struct _WindowData { - void *data; - WindowDataHandler handler; + void *data; + WindowDataHandler handler; }; -WindowData *windowdata_new(void *data, WindowDataHandler handler) { - WindowData *wb= MEM_mallocN(sizeof(*wb), "windowdata_new"); - wb->data= data; - wb->handler= handler; +WindowData *windowdata_new(void *data, WindowDataHandler handler) +{ + WindowData *wb = MEM_mallocN(sizeof(*wb), "windowdata_new"); + wb->data = data; + wb->handler = handler; return wb; } -void windowdata_handle(WindowData *wb, GHOST_EventHandle evt) { +void windowdata_handle(WindowData *wb, GHOST_EventHandle evt) +{ wb->handler(wb->data, evt); } -void windowdata_free(WindowData *wb) { +void windowdata_free(WindowData *wb) +{ MEM_freeN(wb); } diff --git a/release/plugins/sequence/blur.c b/release/plugins/sequence/blur.c index b59d7fbd005..d33feb0bb68 100644 --- a/release/plugins/sequence/blur.c +++ b/release/plugins/sequence/blur.c @@ -32,19 +32,19 @@ /* ******************** GLOBAL VARIABLES ***************** */ -char name[24]= "Blur"; +char name[24] = "Blur"; /* structure for buttons, * butcode name default min max 0 */ -VarStruct varstr[]= { - LABEL, "Input: 1 strip", 0.0, 0.0, 0.0, "", - NUMSLI|FLO, "Blur", 0.5, 0.0, 10.0, "Maximum filtersize", - NUMSLI|FLO, "Gamma", 1.0, 0.4, 2.0, "Gamma correction", - TOG|INT, "Animated", 0.0, 0.0, 1.0, "For (Ipo) animated blur", - NUM|INT, "debug", 0.0, 0.0, 2.0, - "0:off 1: show primary blur buffer 2: show 2nd blur buffer", +VarStruct varstr[] = { + LABEL, "Input: 1 strip", 0.0, 0.0, 0.0, "", + NUMSLI | FLO, "Blur", 0.5, 0.0, 10.0, "Maximum filtersize", + NUMSLI | FLO, "Gamma", 1.0, 0.4, 2.0, "Gamma correction", + TOG | INT, "Animated", 0.0, 0.0, 1.0, "For (Ipo) animated blur", + NUM | INT, "debug", 0.0, 0.0, 2.0, + "0:off 1: show primary blur buffer 2: show 2nd blur buffer", }; @@ -52,7 +52,7 @@ VarStruct varstr[]= { Varstr and Cast must have the same variables in the same order */ typedef struct Cast { - int dummy; /* because of the 'label' button */ + int dummy; /* because of the 'label' button */ float blur; float gamma; float use_ipo; @@ -83,15 +83,15 @@ void plugin_init(void) void plugin_getinfo(PluginInfo *info) { - info->name= name; - info->nvars= sizeof(varstr)/sizeof(VarStruct); - info->cfra= &cfra; + info->name = name; + info->nvars = sizeof(varstr) / sizeof(VarStruct); + info->cfra = &cfra; - info->varstr= varstr; + info->varstr = varstr; - info->init= plugin_init; - info->seq_doit= (SeqDoit) plugin_seq_doit; - info->callback= plugin_but_changed; + info->init = plugin_init; + info->seq_doit = (SeqDoit) plugin_seq_doit; + info->callback = plugin_but_changed; } @@ -102,24 +102,24 @@ void blurbuf(struct ImBuf *ibuf, int nr, Cast *cast) struct ImBuf *tbuf, *ttbuf; int i, x4; - tbuf= dupImBuf(ibuf); - x4= ibuf->x/4; + tbuf = dupImBuf(ibuf); + x4 = ibuf->x / 4; /* This doesn't seem to work... paprmh */ if (cast->gamma != 1.0) gamwarp(tbuf, cast->gamma); /* reduce */ - for (i=0; ix<4 || tbuf->y<4) break; + if (tbuf->x < 4 || tbuf->y < 4) break; } /* enlarge */ - for (i=0; igamma != 1.0) gamwarp(tbuf, 1.0 / cast->gamma); - if (ibuf->rect)memcpy(ibuf->rect, tbuf->rect, 4*ibuf->x*ibuf->y); + if (ibuf->rect) memcpy(ibuf->rect, tbuf->rect, 4 * ibuf->x * ibuf->y); if (ibuf->rect_float) - memcpy(ibuf->rect_float, tbuf->rect_float, 4*ibuf->x*ibuf->y*sizeof(float)); + memcpy(ibuf->rect_float, tbuf->rect_float, 4 * ibuf->x * ibuf->y * sizeof(float)); freeImBuf(tbuf); @@ -161,79 +161,79 @@ void doblur(struct ImBuf *mbuf, float fac, Cast *cast) /* which buffers ? */ - if (fac>7.0) fac= 7.0; - if (fac<=1.0) return; + if (fac > 7.0) fac = 7.0; + if (fac <= 1.0) return; - pfac= 2.0; - pbuf= dupImBuf(mbuf); - n= 1; + pfac = 2.0; + pbuf = dupImBuf(mbuf); + n = 1; while (pfac < fac) { blurbuf(pbuf, n, cast); blurbuf(pbuf, n, cast); n++; - pfac+= 1.0; + pfac += 1.0; } - ifac= pfac; - pfac-= 1.0; + ifac = pfac; + pfac -= 1.0; - ibuf= dupImBuf(pbuf); + ibuf = dupImBuf(pbuf); blurbuf(ibuf, n, cast); blurbuf(ibuf, n, cast); - fac= (fac-pfac)/(ifac-pfac); - n= mbuf->x*mbuf->y; + fac = (fac - pfac) / (ifac - pfac); + n = mbuf->x * mbuf->y; - if (cast->show) fac=cast->show-1; + if (cast->show) fac = cast->show - 1; - if (mbuf->rect_float){ - if (fac>=1) { - memcpy(mbuf->rect_float, ibuf->rect_float, 4*n*sizeof(float)); + if (mbuf->rect_float) { + if (fac >= 1) { + memcpy(mbuf->rect_float, ibuf->rect_float, 4 * n * sizeof(float)); } - else if(fac<=0) { - memcpy(mbuf->rect_float, pbuf->rect_float, 4*n*sizeof(float)); + else if (fac <= 0) { + memcpy(mbuf->rect_float, pbuf->rect_float, 4 * n * sizeof(float)); } - else { /* interpolate */ - infac= 1-fac; + else { /* interpolate */ + infac = 1 - fac; - irectf= (float *)ibuf->rect_float; - prectf= (float *)pbuf->rect_float; - mrectf= (float *)mbuf->rect_float; + irectf = (float *)ibuf->rect_float; + prectf = (float *)pbuf->rect_float; + mrectf = (float *)mbuf->rect_float; while (n--) { - mrectf[0]= irectf[0]*fac+ prectf[0]*infac; - mrectf[1]= irectf[1]*fac+ prectf[1]*infac; - mrectf[2]= irectf[2]*fac+ prectf[2]*infac; - mrectf[3]= irectf[3]*fac+ prectf[3]*infac; - mrectf+= 4; - irectf+= 4; - prectf+= 4; + mrectf[0] = irectf[0] * fac + prectf[0] * infac; + mrectf[1] = irectf[1] * fac + prectf[1] * infac; + mrectf[2] = irectf[2] * fac + prectf[2] * infac; + mrectf[3] = irectf[3] * fac + prectf[3] * infac; + mrectf += 4; + irectf += 4; + prectf += 4; } } } - else if(mbuf->rect){ - b1= (int)fac*255.0; - if (b1>255) b1= 255; - b2= 255-b1; - - if (b1==255) { - memcpy(mbuf->rect, ibuf->rect, 4*n); + else if (mbuf->rect) { + b1 = (int)fac * 255.0; + if (b1 > 255) b1 = 255; + b2 = 255 - b1; + + if (b1 == 255) { + memcpy(mbuf->rect, ibuf->rect, 4 * n); } - else if(b1==0) { - memcpy(mbuf->rect, pbuf->rect, 4*n); + else if (b1 == 0) { + memcpy(mbuf->rect, pbuf->rect, 4 * n); } - else { /* interpolate */ - irect= (char *)ibuf->rect; - prect= (char *)pbuf->rect; - mrect= (char *)mbuf->rect; + else { /* interpolate */ + irect = (char *)ibuf->rect; + prect = (char *)pbuf->rect; + mrect = (char *)mbuf->rect; while (n--) { - mrect[0]= (irect[0]*b1+ prect[0]*b2)>>8; - mrect[1]= (irect[1]*b1+ prect[1]*b2)>>8; - mrect[2]= (irect[2]*b1+ prect[2]*b2)>>8; - mrect[3]= (irect[3]*b1+ prect[3]*b2)>>8; - mrect+= 4; - irect+= 4; - prect+= 4; + mrect[0] = (irect[0] * b1 + prect[0] * b2) >> 8; + mrect[1] = (irect[1] * b1 + prect[1] * b2) >> 8; + mrect[2] = (irect[2] * b1 + prect[2] * b2) >> 8; + mrect[3] = (irect[3] * b1 + prect[3] * b2) >> 8; + mrect += 4; + irect += 4; + prect += 4; } } } @@ -245,18 +245,18 @@ void doblur(struct ImBuf *mbuf, float fac, Cast *cast) void plugin_seq_doit(Cast *cast, float facf0, float facf1, int x, int y, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use) { - float bfacf0, bfacf1; + float bfacf0, bfacf1; - if (cast->use_ipo==0) { - bfacf0= bfacf1= cast->blur+1.0; + if (cast->use_ipo == 0) { + bfacf0 = bfacf1 = cast->blur + 1.0; } else { bfacf0 = (facf0 * 6.0) + 1.0; bfacf1 = (facf1 * 6.0) + 1.0; } - if (out->rect) memcpy(out->rect, ibuf1->rect, 4*out->x*out->y); - if (out->rect_float) memcpy(out->rect_float, ibuf1->rect_float, 4*out->x*out->y*sizeof(float)); + if (out->rect) memcpy(out->rect, ibuf1->rect, 4 * out->x * out->y); + if (out->rect_float) memcpy(out->rect_float, ibuf1->rect_float, 4 * out->x * out->y * sizeof(float)); /****************I can't get this field code to work... works ok without...paprmh****************/ @@ -270,15 +270,15 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int x, int y, ImBuf * doblur(out, bfacf0, cast); /*fieldA*/ /* if (out->rect)out->rect += out->x * out->y; - if (out->rect_float)out->rect_float += out->x * out->y; + if (out->rect_float)out->rect_float += out->x * out->y; - doblur(out, bfacf1, cast);*/ /*fieldB*/ + doblur(out, bfacf1, cast);*/ /*fieldB*/ /* if (out->rect)out->rect -= out->x * out->y; - if (out->rect_float)out->rect_float -= out->x * out->y; - out->flags |= IB_fields; + if (out->rect_float)out->rect_float -= out->x * out->y; + out->flags |= IB_fields; - interlace(out);*/ + interlace(out);*/ } diff --git a/release/plugins/sequence/scatter.c b/release/plugins/sequence/scatter.c index 73e97e165ca..a480f194bea 100644 --- a/release/plugins/sequence/scatter.c +++ b/release/plugins/sequence/scatter.c @@ -31,25 +31,25 @@ /* ******************** GLOBAL VARIABLES ***************** */ -char name[24]= "scatter"; +char name[24] = "scatter"; /* structure for buttons, * butcode name default min max 0 */ -VarStruct varstr[]= { - LABEL, "Input: 1 strip", 0.0, 0.0, 0.0, "", - NUM|INT, "seed: ", 1.0, 0.0, 10.0, "Offset in random table", - NUMSLI|FLO, "swing: ", 1.0, 0.0, 3.0, "The amplitude, width of the effect", - TOG|INT, "wrap", 0.0, 0.0, 1.0, "Cyclic wrap around the left/right edges", - NUM|INT, "type: ", 1.0, 0.0, 1.0, "Type 1 is random for each frame", +VarStruct varstr[] = { + LABEL, "Input: 1 strip", 0.0, 0.0, 0.0, "", + NUM | INT, "seed: ", 1.0, 0.0, 10.0, "Offset in random table", + NUMSLI | FLO, "swing: ", 1.0, 0.0, 3.0, "The amplitude, width of the effect", + TOG | INT, "wrap", 0.0, 0.0, 1.0, "Cyclic wrap around the left/right edges", + NUM | INT, "type: ", 1.0, 0.0, 1.0, "Type 1 is random for each frame", }; /* The cast struct is for input in the main doit function Varstr and Cast must have the same variables in the same order */ typedef struct Cast { - int dummy; /* because of the 'label' button */ + int dummy; /* because of the 'label' button */ int seed; float swing; int wrap; @@ -80,57 +80,57 @@ void plugin_init() void plugin_getinfo(PluginInfo *info) { - info->name= name; - info->nvars= sizeof(varstr)/sizeof(VarStruct); - info->cfra= &cfra; + info->name = name; + info->nvars = sizeof(varstr) / sizeof(VarStruct); + info->cfra = &cfra; - info->varstr= varstr; + info->varstr = varstr; - info->init= plugin_init; - info->seq_doit= (SeqDoit) plugin_seq_doit; - info->callback= plugin_but_changed; + info->init = plugin_init; + info->seq_doit = (SeqDoit) plugin_seq_doit; + info->callback = plugin_but_changed; } /* ************************************************************ - Scatter + Scatter - ************************************************************ */ +************************************************************ */ static void rectcpy(ImBuf *dbuf, ImBuf *sbuf, - int destx, int desty, - int srcx, int srcy, int width, int height) + int destx, int desty, + int srcx, int srcy, int width, int height) { - uint *drect,*srect; + uint *drect, *srect; float *dfrect, *sfrect; int tmp; if (dbuf == 0) return; - if (destx < 0){ - srcx -= destx ; - width += destx ; + if (destx < 0) { + srcx -= destx; + width += destx; destx = 0; } - if (srcx < 0){ - destx -= srcx ; - width += destx ; + if (srcx < 0) { + destx -= srcx; + width += destx; srcx = 0; } - if (desty < 0){ - srcy -= desty ; - height += desty ; + if (desty < 0) { + srcy -= desty; + height += desty; desty = 0; } - if (srcy < 0){ - desty -= srcy ; - height += desty ; + if (srcy < 0) { + desty -= srcy; + height += desty; srcy = 0; } if (width > dbuf->x - destx) width = dbuf->x - destx; if (height > dbuf->y - desty) height = dbuf->y - desty; - if (sbuf){ + if (sbuf) { if (width > sbuf->x - srcx) width = sbuf->x - srcx; if (height > sbuf->y - srcy) height = sbuf->y - srcy; srect = sbuf->rect; @@ -151,23 +151,25 @@ static void rectcpy(ImBuf *dbuf, ImBuf *sbuf, destx = dbuf->x; if (sbuf) { - tmp = (srcy * sbuf->x + srcx ); + tmp = (srcy * sbuf->x + srcx); if (dbuf->rect_float) sfrect += 4 * tmp; else srect += tmp; srcx = sbuf->x; - } else{ + } + else { if (dbuf->rect_float) sfrect = dfrect; else srect = drect; srcx = destx; } - for (;height > 0; height--){ + for (; height > 0; height--) { if (dbuf->rect_float) { - memcpy(dfrect,sfrect, 4 * width * sizeof(float)); + memcpy(dfrect, sfrect, 4 * width * sizeof(float)); dfrect += destx; sfrect += srcx; - } else { - memcpy(drect,srect, width * sizeof(int)); + } + else { + memcpy(drect, srect, width * sizeof(int)); drect += destx; srect += srcx; } @@ -176,21 +178,22 @@ static void rectcpy(ImBuf *dbuf, ImBuf *sbuf, static void fill_out(ImBuf *out, float r, float g, float b, float a) { - int tot,x; + int tot, x; float *rectf = out->rect_float; unsigned char *rect = (unsigned char *)out->rect; tot = out->x * out->y; if (out->rect_float) { - for (x = 0;x < tot; x++) { + for (x = 0; x < tot; x++) { rectf[0] = r; rectf[1] = g; rectf[2] = b; rectf[3] = a; rectf += 4; } - } else { - for (x=0;x < tot;x++) { + } + else { + for (x = 0; x < tot; x++) { rect[0] = (int)(r * 255); rect[1] = (int)(g * 255); rect[2] = (int)(b * 255); @@ -207,7 +210,7 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int sx, int sy, ImBuf int x, y, lr; /* fill imbuf 'out' with black */ - fill_out(out, 0,0,0,0); + fill_out(out, 0, 0, 0, 0); switch (cast->type) { @@ -228,9 +231,10 @@ void plugin_seq_doit(Cast *cast, float facf0, float facf1, int sx, int sy, ImBuf f1 = cast->swing * f1; f2 = cast->swing * f2; if (cast->wrap) f2 += 1.0; - lr = drand48()>0.5; + lr = drand48() > 0.5; t1 = facf0; - } else t1 = facf1; + } + else t1 = facf1; t2 = 1.0 - t1; t3 = 3.0 * (f1 * t1 * t1 * t2 + f2 * t1 * t2 * t2);