GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape) { _GLFWcursor* cursor; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (shape != GLFW_ARROW_CURSOR && shape != GLFW_IBEAM_CURSOR && shape != GLFW_CROSSHAIR_CURSOR && shape != GLFW_HAND_CURSOR && shape != GLFW_HRESIZE_CURSOR && shape != GLFW_VRESIZE_CURSOR) { _glfwInputError(GLFW_INVALID_ENUM, "Invalid standard cursor"); return NULL; } cursor = calloc(1, sizeof(_GLFWcursor)); cursor->next = _glfw.cursorListHead; _glfw.cursorListHead = cursor; if (!_glfwPlatformCreateStandardCursor(cursor, shape)) { glfwDestroyCursor((GLFWcursor*) cursor); return NULL; } return (GLFWcursor*) cursor; }
GLFWAPI void glfwTerminate(void) { int i; if (!_glfwInitialized) return; memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); while (_glfw.windowListHead) glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); while (_glfw.cursorListHead) glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); for (i = 0; i < _glfw.monitorCount; i++) { _GLFWmonitor* monitor = _glfw.monitors[i]; if (monitor->originalRamp.size) _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); } _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount); _glfw.monitors = NULL; _glfw.monitorCount = 0; _glfwPlatformTerminate(); memset(&_glfw, 0, sizeof(_glfw)); _glfwInitialized = GL_FALSE; }
void ImGui_ImplGlfw_Shutdown() { for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_Count_; cursor_n++) { glfwDestroyCursor(g_MouseCursors[cursor_n]); g_MouseCursors[cursor_n] = NULL; } g_ClientApi = GlfwClientApi_Unknown; }
void ImGui_ImplGlfwGL2_Shutdown() { // Destroy GLFW mouse cursors for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++) glfwDestroyCursor(g_MouseCursors[cursor_n]); memset(g_MouseCursors, 0, sizeof(g_MouseCursors)); // Destroy OpenGL objects ImGui_ImplGlfwGL2_InvalidateDeviceObjects(); }
Screen::~Screen() { delete mTheme; __nanogui_screens.erase(mGLFWWindow); for (int i=0; i < (int) Cursor::CursorCount; ++i) if (mCursors[i]) glfwDestroyCursor(mCursors[i]); if (mNVGContext) nvgDeleteGL3(mNVGContext); if (mGLFWWindow) glfwDestroyWindow(mGLFWWindow); }
Screen::~Screen() { __nanogui_screens.erase(mGLFWWindow); for (int i=0; i < (int) Cursor::CursorCount; ++i) { if (mCursors[i]) glfwDestroyCursor(mCursors[i]); } if (mNVGContext) nvgDeleteGL3(mNVGContext); if (mGLFWWindow && mShutdownGLFWOnDestruct) glfwDestroyWindow(mGLFWWindow); }
Gui::~Gui() { while (render_jobs.length()) { RenderJob *rj = render_jobs.pop(); destroy_render_job(rj); } os_mutex_unlock(gui_mutex); glfwDestroyCursor(cursor_default); glfwDestroyCursor(cursor_ibeam); auto it = _font_size_cache.entry_iterator(); for (;;) { auto *entry = it.next(); if (!entry) break; FontSize *font_size_object = entry->value; destroy(font_size_object, 1); } FT_Done_Face(_default_font_face); FT_Done_FreeType(_ft_library); }
void UIManager::Update() { Vector2 mpos = Window::CurrentWindow->GetMouse(); this->LastMousePosition = mpos; int oldshape = this->CursorShape; this->CursorShape = GLFW_ARROW_CURSOR; for (unsigned int i = 0; i < this->Children.size(); i++) { this->Children[i]->_InternalUpdate(); } if (oldshape != this->CursorShape) { if (this->CurrentCursor != null) glfwDestroyCursor(this->CurrentCursor); this->CurrentCursor = glfwCreateStandardCursor(this->CursorShape); } }
GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot) { _GLFWcursor* cursor; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); cursor = calloc(1, sizeof(_GLFWcursor)); cursor->next = _glfw.cursorListHead; _glfw.cursorListHead = cursor; if (!_glfwPlatformCreateCursor(cursor, image, xhot, yhot)) { glfwDestroyCursor((GLFWcursor*) cursor); return NULL; } return (GLFWcursor*) cursor; }
GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape) { _GLFWcursor* cursor; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); cursor = calloc(1, sizeof(_GLFWcursor)); cursor->next = _glfw.cursorListHead; _glfw.cursorListHead = cursor; if (!_glfwPlatformCreateStandardCursor(cursor, shape)) { glfwDestroyCursor((GLFWcursor*) cursor); return NULL; } return (GLFWcursor*) cursor; }
int main(void) { int i; GLFWwindow* window; GLFWcursor* star_cursors[CURSOR_FRAME_COUNT]; glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); for (i = 0; i < CURSOR_FRAME_COUNT; i++) { star_cursors[i] = create_cursor_frame(i / (float) CURSOR_FRAME_COUNT); if (!star_cursors[i]) { glfwTerminate(); exit(EXIT_FAILURE); } } for (i = 0; i < sizeof(standard_cursors) / sizeof(standard_cursors[0]); i++) { const int shapes[] = { GLFW_ARROW_CURSOR, GLFW_IBEAM_CURSOR, GLFW_CROSSHAIR_CURSOR, GLFW_HAND_CURSOR, GLFW_HRESIZE_CURSOR, GLFW_VRESIZE_CURSOR }; standard_cursors[i] = glfwCreateStandardCursor(shapes[i]); if (!standard_cursors[i]) { glfwTerminate(); exit(EXIT_FAILURE); } } window = glfwCreateWindow(640, 480, "Cursor Test", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwGetCursorPos(window, &cursor_x, &cursor_y); printf("Cursor position: %f %f\n", cursor_x, cursor_y); glfwSetCursorPosCallback(window, cursor_position_callback); glfwSetKeyCallback(window, key_callback); while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT); if (track_cursor) { int wnd_width, wnd_height, fb_width, fb_height; float scale; glfwGetWindowSize(window, &wnd_width, &wnd_height); glfwGetFramebufferSize(window, &fb_width, &fb_height); scale = (float) fb_width / (float) wnd_width; glViewport(0, 0, fb_width, fb_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.f, fb_width, 0.f, fb_height, 0.f, 1.f); glBegin(GL_LINES); glVertex2f(0.f, (GLfloat) (fb_height - cursor_y * scale)); glVertex2f((GLfloat) fb_width, (GLfloat) (fb_height - cursor_y * scale)); glVertex2f((GLfloat) cursor_x * scale, 0.f); glVertex2f((GLfloat) cursor_x * scale, (GLfloat) fb_height); glEnd(); } glfwSwapBuffers(window); if (animate_cursor) { const int i = (int) (glfwGetTime() * 30.0) % CURSOR_FRAME_COUNT; glfwSetCursor(window, star_cursors[i]); } if (wait_events) glfwWaitEvents(); else glfwPollEvents(); // Workaround for an issue with msvcrt and mintty fflush(stdout); } glfwDestroyWindow(window); for (i = 0; i < CURSOR_FRAME_COUNT; i++) glfwDestroyCursor(star_cursors[i]); for (i = 0; i < sizeof(standard_cursors) / sizeof(standard_cursors[0]); i++) glfwDestroyCursor(standard_cursors[i]); glfwTerminate(); exit(EXIT_SUCCESS); }
static void command_callback(int key) { switch (key) { case GLFW_KEY_H: { printf("H: show this help\n"); printf("C: call glfwCreateCursor()\n"); printf("D: call glfwDestroyCursor()\n"); printf("S: call glfwSetCursor()\n"); printf("N: call glfwSetCursor() with NULL\n"); printf("1: set GLFW_CURSOR_NORMAL\n"); printf("2: set GLFW_CURSOR_HIDDEN\n"); printf("3: set GLFW_CURSOR_DISABLED\n"); printf("T: enable 3s delay for all previous commands\n"); } break; case GLFW_KEY_C: { int x, y; GLFWimage image; unsigned char* pixels; if (cursor) break; image.width = cursorSize[currentSize].w; image.height = cursorSize[currentSize].h; pixels = malloc(4 * image.width * image.height); image.pixels = pixels; for (y = 0; y < image.height; y++) { for (x = 0; x < image.width; x++) { *pixels++ = 0xff; *pixels++ = 0; *pixels++ = 255 * y / image.height; *pixels++ = 255 * x / image.width; } } cursor = glfwCreateCursor(&image, image.width / 2, image.height / 2); currentSize = (currentSize + 1) % SizeCount; free(image.pixels); break; } case GLFW_KEY_D: { if (cursor != NULL) { glfwDestroyCursor(cursor); cursor = NULL; } break; } case GLFW_KEY_S: { if (cursor != NULL) glfwSetCursor(activeWindow, cursor); else printf("The cursor is not created\n"); break; } case GLFW_KEY_N: glfwSetCursor(activeWindow, NULL); break; case GLFW_KEY_1: glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); break; case GLFW_KEY_2: glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); break; case GLFW_KEY_3: glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); break; } }
int main( void ) { // application time static GLfloat last = 0; GLfloat delta; GLfloat timer = glfwGetTime(); last = timer; // circle position and other attribute GLfloat x = SCREEN_WIDTH / 3; GLfloat y = SCREEN_HEIGHT / 2; GLfloat xStep = 3; GLfloat yStep = 3; GLfloat radius = 65.0; GLfloat lambda = SCREEN_HEIGHT / 4; // time to wait before moving the cirle GLfloat sleep = 0.03; char text[] = "output.txt"; FILE * out = fopen(text, "w"); // temporary position of cursor double xpos; double ypos; // current position of cursor double cX; double cY; GLfloat distance; glfwSetErrorCallback(error); if ( !glfwInit( ) || out == NULL) { return -1; } window = glfwCreateWindow( SCREEN_WIDTH, SCREEN_HEIGHT, "fx", NULL, NULL ); if ( !window ) { glfwTerminate( ); return -1; } glfwMakeContextCurrent( window ); glViewport( 0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR); glfwSetCursor( window, cursor ); // set to null to reset cursor glfwGetCursorPos(window, &cX, &cY); glfwSetKeyCallback(window, key_callback); while ( !glfwWindowShouldClose( window ) ) { glClear( GL_COLOR_BUFFER_BIT ); timer = glfwGetTime(); // whether we should move the circle if (timer - last > sleep) { last = timer; // edge detection if (x + radius > SCREEN_WIDTH || x - radius < 0.0) { xStep *= -1; } if (//y + radius > 3 * SCREEN_HEIGHT / 4 <-- if top/bottom bounds are desired //|| y - radius < SCREEN_HEIGHT / 4 <-- if top/bottom bounds are desired x + radius > SCREEN_WIDTH || x - radius < 0.0) { yStep *= -1; } // change position of circle-center, i.e. we move the circle x += xStep; y += yStep * (2 * sin(2 * M_PI * x / lambda)) * 3; } drawCircle( x, y, 0, radius, 36); //update cursor position glfwGetCursorPos(window, &xpos, &ypos); cX = xpos; cY = SCREEN_HEIGHT - ypos; distance = sqrt((cX - x) * (cX - x) + (cY - y) * (cY - y)); writeData(out, x, y, radius, cX, cY, timer, distance); glfwSwapBuffers( window ); glfwPollEvents( ); } fclose(out); glfwDestroyWindow(window); glfwDestroyCursor(cursor); glfwTerminate( ); return 0; }