static void setViewPortGL(GHOST_WindowHandle hWindow) { GHOST_RectangleHandle hRect = NULL; GLfloat w, h; GHOST_ActivateWindowDrawingContext(hWindow); hRect = GHOST_GetClientBounds(hWindow); w = (float)GHOST_GetWidthRectangle(hRect) / (float)GHOST_GetHeightRectangle(hRect); h = 1.0; glViewport(0, 0, GHOST_GetWidthRectangle(hRect), GHOST_GetHeightRectangle(hRect)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-w, w, -h, h, 5.0, 60.0); /* glOrtho(0, bnds.getWidth(), 0, bnds.getHeight(), -10, 10); */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -40.0); glClearColor(.2f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); GHOST_DisposeRectangle(hRect); }
static void loggerwindow_do_draw(LoggerWindow *lw) { int i, ndisplines, startline; int sb_rect[2][2], sb_thumb[2][2]; GHOST_ActivateWindowDrawingContext(lw->win); glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8, 0.8, 0.8); rect_bevel_smooth(lw->textarea, 4); scrollbar_get_rect(lw->scroll, sb_rect); scrollbar_get_thumb(lw->scroll, sb_thumb); glColor3f(0.6, 0.6, 0.6); rect_bevel_smooth(sb_rect, 1); if (scrollbar_is_scrolling(lw->scroll)) { glColor3f(0.6, 0.7, 0.5); } 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); if (lw->fonttexid!=-1) { glBindTexture(GL_TEXTURE_2D, lw->fonttexid); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); } glColor3f(0, 0, 0); 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; if (lw->fonttexid==-1) { glRasterPos2i(x_pos, y_pos); BMF_DrawString(lw->font, line); } else { BMF_DrawStringTexture(lw->font, line, x_pos, y_pos, 0.0); } } if (lw->fonttexid!=-1) { glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); } GHOST_SwapWindowBuffers(lw->win); }
static void extrawindow_do_draw(ExtraWindow *ew) { GHOST_ActivateWindowDrawingContext(ew->win); glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8, 0.8, 0.8); glRecti(10, 10, ew->size[0]-10, ew->size[1]-10); GHOST_SwapWindowBuffers(ew->win); }
static void loggerwindow_do_reshape(LoggerWindow *lw) { GHOST_RectangleHandle bounds= GHOST_GetClientBounds(lw->win); GHOST_ActivateWindowDrawingContext(lw->win); lw->size[0]= GHOST_GetWidthRectangle(bounds); lw->size[1]= GHOST_GetHeightRectangle(bounds); loggerwindow_recalc_regions(lw); loggerwindow_setup_window_gl(lw); }
void wm_window_make_drawable(bContext *C, wmWindow *win) { wmWindowManager *wm = CTX_wm_manager(C); if (win != wm->windrawable && win->ghostwin) { // win->lmbut = 0; /* keeps hanging when mousepressed while other window opened */ wm->windrawable = win; if (G.debug & G_DEBUG_EVENTS) { printf("%s: set drawable %d\n", __func__, win->winid); } GHOST_ActivateWindowDrawingContext(win->ghostwin); } }
static void mainwindow_do_draw(MainWindow *mw) { GHOST_ActivateWindowDrawingContext(mw->win); if (mw->lmbut[0]) { glClearColor(0.5, 0.5, 0.5, 1); } 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); GHOST_SwapWindowBuffers(mw->win); }
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win) { if (win != wm->windrawable && win->ghostwin) { // win->lmbut = 0; /* keeps hanging when mousepressed while other window opened */ wm->windrawable = win; if (G.debug & G_DEBUG_EVENTS) { printf("%s: set drawable %d\n", __func__, win->winid); } GHOST_ActivateWindowDrawingContext(win->ghostwin); /* this can change per window */ U.pixelsize = wm_window_pixelsize(win); BKE_userdef_state(); } }
static void extrawindow_do_reshape(ExtraWindow *ew) { GHOST_RectangleHandle bounds= GHOST_GetClientBounds(ew->win); GHOST_ActivateWindowDrawingContext(ew->win); ew->size[0]= GHOST_GetWidthRectangle(bounds); ew->size[1]= GHOST_GetHeightRectangle(bounds); glViewport(0, 0, ew->size[0], ew->size[1]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, ew->size[0], 0, ew->size[1], -1, 1); glTranslatef(0.375, 0.375, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) { PlayState *ps = (PlayState *)ps_void; GHOST_TEventType type = GHOST_GetEventType(evt); int val; // print_ps(ps); playanim_event_qual_update(); /* convert ghost event into value keyboard or mouse */ val = ELEM(type, GHOST_kEventKeyDown, GHOST_kEventButtonDown); if (ps->wait2 && ps->stopped) { ps->stopped = FALSE; } if (ps->wait2) { pupdate_time(); ptottime = 0; } switch (type) { case GHOST_kEventKeyDown: case GHOST_kEventKeyUp: { GHOST_TEventKeyData *key_data; key_data = (GHOST_TEventKeyData *)GHOST_GetEventData(evt); switch (key_data->key) { case GHOST_kKeyA: if (val) ps->noskip = !ps->noskip; break; case GHOST_kKeyP: if (val) ps->pingpong = !ps->pingpong; break; case GHOST_kKey1: case GHOST_kKeyNumpad1: if (val) swaptime = ps->fstep / 60.0; break; case GHOST_kKey2: case GHOST_kKeyNumpad2: if (val) swaptime = ps->fstep / 50.0; break; case GHOST_kKey3: case GHOST_kKeyNumpad3: if (val) swaptime = ps->fstep / 30.0; break; case GHOST_kKey4: case GHOST_kKeyNumpad4: if (g_WS.qual & WS_QUAL_SHIFT) swaptime = ps->fstep / 24.0; else swaptime = ps->fstep / 25.0; break; case GHOST_kKey5: case GHOST_kKeyNumpad5: if (val) swaptime = ps->fstep / 20.0; break; case GHOST_kKey6: case GHOST_kKeyNumpad6: if (val) swaptime = ps->fstep / 15.0; break; case GHOST_kKey7: case GHOST_kKeyNumpad7: if (val) swaptime = ps->fstep / 12.0; break; case GHOST_kKey8: case GHOST_kKeyNumpad8: if (val) swaptime = ps->fstep / 10.0; break; case GHOST_kKey9: case GHOST_kKeyNumpad9: if (val) swaptime = ps->fstep / 6.0; break; case GHOST_kKeyLeftArrow: if (val) { ps->sstep = TRUE; ps->wait2 = FALSE; if (g_WS.qual & WS_QUAL_SHIFT) { ps->picture = picsbase.first; ps->next_frame = 0; } else { ps->next_frame = -1; } } break; case GHOST_kKeyDownArrow: if (val) { ps->wait2 = FALSE; if (g_WS.qual & WS_QUAL_SHIFT) { ps->next_frame = ps->direction = -1; } else { ps->next_frame = -10; ps->sstep = TRUE; } } break; case GHOST_kKeyRightArrow: if (val) { ps->sstep = TRUE; ps->wait2 = FALSE; if (g_WS.qual & WS_QUAL_SHIFT) { ps->picture = picsbase.last; ps->next_frame = 0; } else { ps->next_frame = 1; } } break; case GHOST_kKeyUpArrow: if (val) { ps->wait2 = FALSE; if (g_WS.qual & WS_QUAL_SHIFT) { ps->next_frame = ps->direction = 1; } else { ps->next_frame = 10; ps->sstep = TRUE; } } break; case GHOST_kKeySlash: case GHOST_kKeyNumpadSlash: if (val) { if (g_WS.qual & WS_QUAL_SHIFT) { if (ps->curframe_ibuf) printf(" Name: %s | Speed: %.2f frames/s\n", ps->curframe_ibuf->name, ps->fstep / swaptime); } else { swaptime = ps->fstep / 5.0; } } break; case GHOST_kKey0: case GHOST_kKeyNumpad0: if (val) { if (ps->once) { ps->once = ps->wait2 = FALSE; } else { ps->picture = NULL; ps->once = TRUE; ps->wait2 = FALSE; } } break; case GHOST_kKeyEnter: case GHOST_kKeyNumpadEnter: if (val) { ps->wait2 = ps->sstep = FALSE; } break; case GHOST_kKeyPeriod: case GHOST_kKeyNumpadPeriod: if (val) { if (ps->sstep) { ps->wait2 = FALSE; } else { ps->sstep = TRUE; ps->wait2 = !ps->wait2; } } break; case GHOST_kKeyEqual: case GHOST_kKeyNumpadPlus: { if (val == 0) break; if (g_WS.qual & WS_QUAL_CTRL) { playanim_window_zoom(ps, 1.0f); } else { swaptime /= 1.1; } break; } case GHOST_kKeyMinus: case GHOST_kKeyNumpadMinus: { if (val == 0) break; if (g_WS.qual & WS_QUAL_CTRL) { playanim_window_zoom(ps, -1.0f); } else { swaptime *= 1.1; } break; } case GHOST_kKeyEsc: ps->go = FALSE; break; default: break; } break; } case GHOST_kEventButtonDown: case GHOST_kEventButtonUp: { GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); int cx, cy, sizex, sizey, inside_window; GHOST_GetCursorPosition(g_WS.ghost_system, &cx, &cy); GHOST_ScreenToClient(g_WS.ghost_window, cx, cy, &cx, &cy); playanim_window_get_size(&sizex, &sizey); inside_window = (cx >= 0 && cx < sizex && cy >= 0 && cy <= sizey); if (bd->button == GHOST_kButtonMaskLeft) { if (type == GHOST_kEventButtonDown) { if (inside_window) g_WS.qual |= WS_QUAL_LMOUSE; } else g_WS.qual &= ~WS_QUAL_LMOUSE; } else if (bd->button == GHOST_kButtonMaskMiddle) { if (type == GHOST_kEventButtonDown) { if (inside_window) g_WS.qual |= WS_QUAL_MMOUSE; } else g_WS.qual &= ~WS_QUAL_MMOUSE; } else if (bd->button == GHOST_kButtonMaskRight) { if (type == GHOST_kEventButtonDown) { if (inside_window) g_WS.qual |= WS_QUAL_RMOUSE; } else g_WS.qual &= ~WS_QUAL_RMOUSE; } break; } case GHOST_kEventCursorMove: { if (g_WS.qual & WS_QUAL_LMOUSE) { int sizex, sizey; int i; GHOST_TEventCursorData *cd = GHOST_GetEventData(evt); int cx, cy; GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy); playanim_window_get_size(&sizex, &sizey); ps->picture = picsbase.first; /* TODO - store in ps direct? */ i = 0; while (ps->picture) { i++; ps->picture = ps->picture->next; } i = (i * cx) / sizex; ps->picture = picsbase.first; for (; i > 0; i--) { if (ps->picture->next == NULL) break; ps->picture = ps->picture->next; } ps->sstep = TRUE; ps->wait2 = FALSE; ps->next_frame = 0; } break; } case GHOST_kEventWindowActivate: case GHOST_kEventWindowDeactivate: { g_WS.qual &= ~WS_QUAL_MOUSE; break; } case GHOST_kEventWindowSize: case GHOST_kEventWindowMove: { float zoomx, zoomy; playanim_window_get_size(&ps->win_x, &ps->win_y); GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); zoomx = (float) ps->win_x / ps->ibufx; zoomy = (float) ps->win_y / ps->ibufy; /* zoom always show entire image */ ps->zoom = MIN2(zoomx, zoomy); /* zoom steps of 2 for speed */ ps->zoom = floor(ps->zoom + 0.5f); if (ps->zoom < 1.0f) ps->zoom = 1.0f; glViewport(0, 0, ps->win_x, ps->win_y); glScissor(0, 0, ps->win_x, ps->win_y); /* unified matrix, note it affects offset for drawing */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glPixelZoom(ps->zoom, ps->zoom); ptottime = 0.0; playanim_toscreen(ps, ps->picture, ps->curframe_ibuf, ps->fontid, ps->fstep); break; } case GHOST_kEventQuit: case GHOST_kEventWindowClose: { ps->go = FALSE; break; } case GHOST_kEventDraggingDropDone: { GHOST_TEventDragnDropData *ddd = GHOST_GetEventData(evt); if (ddd->dataType == GHOST_kDragnDropTypeFilenames) { GHOST_TStringArray *stra = ddd->data; int a; for (a = 0; a < stra->count; a++) { BLI_strncpy(ps->dropped_file, (char *)stra->strings[a], sizeof(ps->dropped_file)); ps->go = FALSE; printf("drop file %s\n", stra->strings[a]); break; /* only one drop element supported now */ } } break; } default: /* quiet warnings */ break; } return 1; }
static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf *ibuf, int fontid, int fstep) { float offsx, offsy; if (ibuf == NULL) { printf("%s: no ibuf for picture '%s'\n", __func__, picture ? picture->name : "<NIL>"); return; } if (ibuf->rect == NULL && ibuf->rect_float) { IMB_rect_from_float(ibuf); imb_freerectfloatImBuf(ibuf); } if (ibuf->rect == NULL) return; GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); /* offset within window */ offsx = 0.5f * (((float)ps->win_x - ps->zoom * ibuf->x) / (float)ps->win_x); offsy = 0.5f * (((float)ps->win_y - ps->zoom * ibuf->y) / (float)ps->win_y); CLAMP(offsx, 0.0f, 1.0f); CLAMP(offsy, 0.0f, 1.0f); glRasterPos2f(offsx, offsy); glClearColor(0.1, 0.1, 0.1, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* checkerboard for case alpha */ if (ibuf->planes == 32) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); fdrawcheckerboard(offsx, offsy, offsx + (ps->zoom * ibuf->x) / (float)ps->win_x, offsy + (ps->zoom * ibuf->y) / (float)ps->win_y); } glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); glDisable(GL_BLEND); pupdate_time(); if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) { int sizex, sizey; float fsizex_inv, fsizey_inv; char str[32 + FILE_MAX]; cpack(-1); BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime); playanim_window_get_size(&sizex, &sizey); fsizex_inv = 1.0f / sizex; fsizey_inv = 1.0f / sizey; BLF_enable(fontid, BLF_ASPECT); BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f); BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f); BLF_draw(fontid, str, sizeof(str)); } GHOST_SwapWindowBuffers(g_WS.ghost_window); }