summaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-11-29 15:16:42 -0600
committersanine-a <sanine.not@pm.me>2020-11-29 15:16:42 -0600
commit140666204191b218b72274d8d14921c89a6631fd (patch)
tree8436c81dda007e934f6b5cadd41789c677306b44 /src/window
parent146d708c67172a05a62f944b16fdcb0dccc4713d (diff)
refactor: eliminate src subdirectories for honey files
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c268
-rw-r--r--src/window/window.h86
2 files changed, 0 insertions, 354 deletions
diff --git a/src/window/window.c b/src/window/window.c
deleted file mode 100644
index 6a1fe6f..0000000
--- a/src/window/window.c
+++ /dev/null
@@ -1,268 +0,0 @@
-#include "window.h"
-
-int honey_window_info_ref = LUA_NOREF;
-int honey_window_resize_callback_ref = LUA_NOREF;
-int honey_window_resize_callback_data_ref = LUA_NOREF;
-int honey_window_focus_callback_ref = LUA_NOREF;
-int honey_window_focus_callback_data_ref = LUA_NOREF;
-
-static void honey_glfw_window_resize_callback(honey_window window,
- int width, int height)
-{
- lua_State* L = glfwGetWindowUserPointer(window);
-
- int callback = honey_window_resize_callback_ref;
- int data = honey_window_resize_callback_data_ref;
-
- if (callback == LUA_NOREF)
- return;
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
-
- lua_pushinteger(L, width);
- lua_pushinteger(L, height);
-
- if (data == LUA_NOREF || data == LUA_REFNIL)
- lua_pushnil(L);
- else
- lua_rawgeti(L, LUA_REGISTRYINDEX, data);
-
- honey_lua_pcall(L, 3, 0);
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-static void honey_glfw_window_focus_callback(honey_window window,
- int focused)
-{
- lua_State* L = glfwGetWindowUserPointer(window);
-
- int callback = honey_window_focus_callback_ref;
- int data = honey_window_focus_callback_data_ref;
-
- if (callback == LUA_NOREF)
- return;
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
-
- lua_pushboolean(L, focused);
-
- if (data == LUA_NOREF || data == LUA_REFNIL)
- lua_pushnil(L);
- else
- lua_rawgeti(L, LUA_REGISTRYINDEX, data);
-
- honey_lua_pcall(L, 2, 0);
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-bool honey_setup_window(lua_State* L)
-{
- honey_window_information* info = lua_newuserdata(L, sizeof(honey_window_information));
- honey_window_info_ref = luaL_ref(L, LUA_REGISTRYINDEX);
-
- glfwInit();
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
-
- info->window = glfwCreateWindow(HONEY_WINDOW_DEFAULT_WIDTH,
- HONEY_WINDOW_DEFAULT_HEIGHT,
- "honey", NULL, NULL);
-
- info->width = HONEY_WINDOW_DEFAULT_WIDTH;
- info->height = HONEY_WINDOW_DEFAULT_WIDTH;
- info->fullscreen = false;
-
- if (info->window == NULL) {
- fprintf(stderr, "[honey] ERROR: failed to create window!\n");
- glfwTerminate();
- return false;
- }
- /* store lua state in window, so it's accessible from GLFW callbacks */
- glfwSetWindowUserPointer(info->window, L);
- glfwMakeContextCurrent(info->window);
-
- if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
- fprintf(stderr, "[honey] ERROR: failed to initialize GLAD!\n");
- glfwTerminate();
- return false;
- }
-
- // Enable blending
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- // Enable depth testing
- glEnable(GL_DEPTH_TEST);
-
- // Enable face culling
- glEnable(GL_CULL_FACE);
-
- glfwSetWindowSizeCallback(info->window, honey_glfw_window_resize_callback);
- glfwSetWindowFocusCallback(info->window, honey_glfw_window_focus_callback);
-
-
- honey_lua_element window_elements[] = {
- { "set_fullscreen", HONEY_FUNCTION, { .function = honey_window_set_fullscreen } },
- { "set_title", HONEY_FUNCTION, { .function = honey_window_set_title } },
- { "get_size", HONEY_FUNCTION, { .function = honey_window_get_size } },
- { "set_size", HONEY_FUNCTION, { .function = honey_window_set_size } },
- { "resize_bind", HONEY_FUNCTION, { .function = honey_window_resize_bind } },
- { "resize_unbind", HONEY_FUNCTION, { .function = honey_window_resize_unbind } },
- { "focus_bind", HONEY_FUNCTION, { .function = honey_window_focus_bind } },
- { "focus_unbind", HONEY_FUNCTION, { .function = honey_window_focus_unbind } },
- };
-
- honey_lua_create_table(L, window_elements, 8);
- return true;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_set_fullscreen(lua_State* L)
-{
- if (!honey_lua_validate_types(L, 1, HONEY_BOOLEAN))
- lua_error(L);
-
- bool fullscreen = lua_toboolean(L, 1);
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, honey_window_info_ref);
- honey_window_information* info = lua_touserdata(L, -1);
-
- if (fullscreen) {
- glfwGetWindowSize(info->window, &(info->width), &(info->height));
-
- GLFWmonitor* monitor = glfwGetPrimaryMonitor();
- const GLFWvidmode* mode = glfwGetVideoMode(monitor);
- glfwSetWindowMonitor(info->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
- info->fullscreen = true;
- }
- else {
- glfwSetWindowMonitor(info->window, NULL, 20, 20, info->width, info->height, 0);
- info->fullscreen = false;
- }
- return 0;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_set_title(lua_State* L)
-{
- if (!honey_lua_validate_types(L, 1, HONEY_STRING))
- lua_error(L);
-
- const char* title = lua_tostring(L, 1);
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, honey_window_info_ref);
- honey_window_information* info = lua_touserdata(L, -1);
-
- glfwSetWindowTitle(info->window, title);
- return 0;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_get_size(lua_State* L)
-{
- lua_rawgeti(L, LUA_REGISTRYINDEX, honey_window_info_ref);
- honey_window_information* info = lua_touserdata(L, -1);
-
- int width, height;
- glfwGetWindowSize(info->window, &width, &height);
- lua_pushinteger(L, width);
- lua_pushinteger(L, height);
- return 2;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_set_size(lua_State* L)
-{
- if (!honey_lua_validate_types(L, 2, HONEY_INTEGER, HONEY_INTEGER))
- lua_error(L);
-
- int width = lua_tointeger(L, 1);
- int height = lua_tointeger(L, 2);
-
- lua_rawgeti(L, LUA_REGISTRYINDEX, honey_window_info_ref);
- honey_window_information* info = lua_touserdata(L, -1);
-
- glfwSetWindowSize(info->window, width, height);
- return 0;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_resize_bind(lua_State* L)
-{
- if (!honey_lua_validate_types(L, 2, HONEY_FUNCTION, HONEY_ANY))
- lua_error(L);
-
- lua_pushvalue(L, 1);
- honey_window_resize_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
- lua_pushvalue(L, 2);
- honey_window_resize_callback_data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
-
- return 0;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_resize_unbind(lua_State* L)
-{
- int callback = honey_window_resize_callback_ref;
- int data = honey_window_resize_callback_data_ref;
-
- if (callback != LUA_NOREF) {
- lua_pushnil(L);
- lua_rawseti(L, LUA_REGISTRYINDEX, callback);
- }
-
- if (data != LUA_NOREF && data != LUA_REFNIL) {
- lua_pushnil(L);
- lua_rawseti(L, LUA_REGISTRYINDEX, callback);
- }
-
- honey_window_resize_callback_ref = LUA_NOREF;
- honey_window_resize_callback_data_ref = LUA_NOREF;
- return 0;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_focus_bind(lua_State* L)
-{
- if (!honey_lua_validate_types(L, 2, HONEY_FUNCTION, HONEY_ANY))
- lua_error(L);
-
- lua_pushvalue(L, 1);
- honey_window_focus_callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
- lua_pushvalue(L, 2);
- honey_window_focus_callback_data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
-
- return 0;
-}
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-int honey_window_focus_unbind(lua_State* L)
-{
- int callback = honey_window_focus_callback_ref;
- int data = honey_window_focus_callback_data_ref;
-
- if (callback != LUA_NOREF) {
- lua_pushnil(L);
- lua_rawseti(L, LUA_REGISTRYINDEX, callback);
- }
-
- if (data != LUA_NOREF && data != LUA_REFNIL) {
- lua_pushnil(L);
- lua_rawseti(L, LUA_REGISTRYINDEX, callback);
- }
-
- honey_window_focus_callback_ref = LUA_NOREF;
- honey_window_focus_callback_data_ref = LUA_NOREF;
- return 0;
-}
diff --git a/src/window/window.h b/src/window/window.h
deleted file mode 100644
index 3ac982a..0000000
--- a/src/window/window.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/** @file */
-
-#ifndef HONEY_WINDOW_H
-#define HONEY_WINDOW_H
-
-#include "../common.h"
-
-#define HONEY_WINDOW_DEFAULT_WIDTH 640
-#define HONEY_WINDOW_DEFAULT_HEIGHT 480
-
-/** @brief Push the various honey.window table to the stack.
- *
- * @param[in] L The lua state to push to
- * @param[in] window The window created by honey_setup()
- *
- * @returns Nothing.
- */
-bool honey_setup_window(lua_State* L);
-
-/** @brief Set whether or not the window is fullscreen.
- *
- * Lua parameters:
- * @param[in] fullscreen Boolean set to true if the window is to be fullscreen and false otherwise.
- *
- * @returns Nothing.
- */
-int honey_window_set_fullscreen(lua_State* L);
-
-/** @brief Set the title of the window.
- *
- * @param[in] title String containing the desired window title.
- *
- * @returns Nothing.
- */
-int honey_window_set_title(lua_State* L);
-
-/** @brief Get the current size of the window.
- *
- * @returns width, height numbers representing the window size in pixels.
- */
-int honey_window_get_size(lua_State* L);
-
-/** @brief Set the current size of the window.
- *
- * @param[in] width Integer of the desired width in pixels.
- * @param[in] height Integer of the desired height in pixels.
- *
- * @returns Nothing.
- */
-int honey_window_set_size(lua_State* L);
-
-/** @brief Bind a call back to the window resize.
- *
- * @param[in] callback The callback function to call on a window resize.
- *
- * @returns Nothing.
- */
-int honey_window_resize_bind(lua_State* L);
-
-/** @brief Unbind any callback that may be attached to the window resize.
- *
- * @returns Nothing.
- */
-int honey_window_resize_unbind(lua_State* L);
-
-/** @brief Bind a callback to the window changing focus.
- *
- * The supplied callback function should be of the form
- * function(boolean, data). The boolean is true if the window
- * is gaining focus, and false if it is losing focus. The data is
- * just the data parameter passed to this function.
- *
- * @param callback The callback function to call on a window resize.
- * @param data Data to send to the callback.
- *
- * @returns Nothing.
- */
-int honey_window_focus_bind(lua_State* L);
-
-/** @brief Unbind any callback that may be attached to the window focus.
- *
- * @returns Nothing.
- */
-int honey_window_focus_unbind(lua_State* L);
-
-#endif