Skip to content

Commit

Permalink
Align with existing Glk functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiegel committed Aug 27, 2023
1 parent b6978e5 commit 9301752
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
9 changes: 2 additions & 7 deletions garglk/cheapglk/glk.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef int32_t glsi32;

#define GLK_MODULE_GARGLKTEXT
#define GLK_MODULE_GARGLKBLEEP
#define GLK_MODULE_GARGLKWININFO
#define GLK_MODULE_GARGLKWINSIZE

/* Define a macro for a function attribute that indicates a function that
never returns. (E.g., glk_exit().) We try to do this only in C compilers
Expand Down Expand Up @@ -523,12 +523,7 @@ extern void garglk_set_reversevideo_stream(strid_t str, glui32 reverse);

extern void garglk_zbleep(glui32 number);

struct GarglkWininfo {
glui32 width;
glui32 height;
};

extern struct GarglkWininfo garglk_wininfo(winid_t win);
void garglk_window_get_size_pixels(winid_t win, glui32 *width, glui32 *height);

/* non standard keycodes */
#define keycode_Erase (0xffffef7f)
Expand Down
24 changes: 15 additions & 9 deletions garglk/garglk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,28 @@ bool garglk::read_file(const std::string &filename, std::vector<unsigned char> &
return !f.fail();
}

GarglkWininfo garglk_wininfo(window_t *win)
void garglk_window_get_size_pixels(window_t *win, glui32 *width, glui32 *height)
{
GarglkWininfo wininfo{};

glk_window_get_size(win, &wininfo.width, &wininfo.height);
glui32 wid;
glui32 hgt;
glk_window_get_size(win, &wid, &hgt);

// For text windows, the size should be reported in pixels, and
// since glk_window_get_size() does integer division, this can't
// just multiply by gli_cellw/gli_cellh; calculate directly.
if (win->type == wintype_TextGrid) {
wininfo.width = win->bbox.x1 - win->bbox.x0;
wininfo.height = win->bbox.y1 - win->bbox.y0;
wid = win->bbox.x1 - win->bbox.x0;
hgt = win->bbox.y1 - win->bbox.y0;
} else if (win->type == wintype_TextBuffer) {
wininfo.width = win->bbox.x1 - win->bbox.x0 - gli_tmarginx * 2;
wininfo.height = win->bbox.y1 - win->bbox.y0 - gli_tmarginy * 2;
wid = win->bbox.x1 - win->bbox.x0 - gli_tmarginx * 2;
hgt = win->bbox.y1 - win->bbox.y0 - gli_tmarginy * 2;
}

if (width != nullptr) {
*width = wid;
}

return wininfo;
if (height != nullptr) {
*height = hgt;
}
}

0 comments on commit 9301752

Please sign in to comment.