diff --git a/src/ui/hotbar.c b/src/ui/hotbar.c index 7af0f5b..f40f0d5 100644 --- a/src/ui/hotbar.c +++ b/src/ui/hotbar.c @@ -64,9 +64,30 @@ static void update(struct UIHotbar *self) { } } +static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset){ + // Y-offset is either 1 or -1 (scroll up or down) + struct UIHotbar* self = (struct UIHotbar*)glfwGetWindowUserPointer(window); + // Scroll left + if (yoffset == 1){ + if (self->index == 0){ + self->index = 9; + }else{ + self->index -= 1; + } + // Scroll right + }else if(yoffset == -1){ + self->index += 1; + self->index = self->index % 10; + } + return; +} + struct UIComponent hotbar_init(struct UIHotbar *self) { self->index = 0; + glfwSetWindowUserPointer(state.window->handle,self); + glfwSetScrollCallback(state.window->handle,scrollCallback); + memcpy(self->values, (enum BlockId[]) { GRASS, DIRT, @@ -87,4 +108,4 @@ struct UIComponent hotbar_init(struct UIHotbar *self) { .update = (FUIComponent) update, .tick = NULL }; -} \ No newline at end of file +}