Skip to content

Commit

Permalink
Add cursor mode to cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
acgaudette committed Jul 5, 2021
1 parent 6243a40 commit 1c6970a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/demos.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ int main()
.asset_path = "./assets/",
.win_size = { 800, 800 }, // Ignored
.mode = MODE_BORDERLESS,
.cursor = CURSOR_SCREEN,
};

txtquad_init(cfg);
Expand Down
26 changes: 21 additions & 5 deletions lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ static void glfw_char_callback(GLFWwindow *win, unsigned int unicode)
}
#endif

static GLFWwindow *mk_win(const char *name, int type, struct extent *extent)
{
static GLFWwindow *mk_win(
const char *name,
int type,
struct extent *extent,
int cursor
) {
if (!glfwInit()) {
panic_msg("unable to initialize GLFW");
}
Expand Down Expand Up @@ -264,7 +268,7 @@ static GLFWwindow *mk_win(const char *name, int type, struct extent *extent)
#ifdef INP_TEXT
glfwSetCharCallback(win, glfw_char_callback);
#endif
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetInputMode(win, GLFW_CURSOR, cursor);

return win;
}
Expand Down Expand Up @@ -2133,7 +2137,19 @@ void txtquad_init(struct txt_cfg cfg)
cfg.win_size = zero;
break;
default:
assert(0);
panic();
}

int cursor;
switch (cfg.cursor) {
case CURSOR_SCREEN:
cursor = GLFW_CURSOR_HIDDEN;
break;
case CURSOR_INF:
cursor = GLFW_CURSOR_DISABLED;
break;
default:
panic();
}

const char *app_name = cfg.app_name ?: ENG_NAME;
Expand All @@ -2146,7 +2162,7 @@ void txtquad_init(struct txt_cfg cfg)
strncpy(root_path, asset_path, len + 1);
filename = root_path + len;

app.win = mk_win(app_name, cfg.mode, &cfg.win_size);
app.win = mk_win(app_name, cfg.mode, &cfg.win_size, cursor);
app.inst = mk_inst(app_name);
app.surf = mk_surf(app.win, app.inst);
app.dev = mk_dev(app.inst, app.surf);
Expand Down
4 changes: 4 additions & 0 deletions txtquad.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ struct txt_cfg {
} mode;
struct extent win_size; // Ignored for MODE_BORDERLESS
v3 clear_col;
enum {
CURSOR_SCREEN // Always bounded by the screen extent
, CURSOR_INF // Unbounded, but locked to the window
} cursor;
};

// Zero is an acceptable default for all fields
Expand Down

0 comments on commit 1c6970a

Please sign in to comment.