Skip to content

Commit

Permalink
draw2d cast() macro refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
frang75 committed Oct 22, 2024
1 parent 3e0bb15 commit 569e797
Show file tree
Hide file tree
Showing 30 changed files with 240 additions and 299 deletions.
18 changes: 10 additions & 8 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# NAppGUI Changelog

## v1.4.3 - WIP
## v1.5.0 - WIP

## v1.4.3 - Oct 12, 2024 (r5533)

### Added

Expand All @@ -23,10 +25,10 @@
* [Documentation](https://nappgui.com/en/ogl3d/ogl3d.html).
* [Demo](https://nappgui.com/en/howto/glhello.html).
* `draw_r2df()`, `draw_r2dd()`, `Draw::r2d()`. [Commit](https://github.com/frang75/nappgui_src/commit/51d4022b5d7535f325b253a29e653b9b88b5ced7).
* `draw2d_preferred_monospace()`. [Commit]().
* `listbox_font()`. [Commit]().
* `ekFCELL` in font style to indicate the font size means cell height. [Commit]().
* Support for font stretch. [Doc](https://nappgui.com/en/draw2d/font.html#h6). [Commit]().
* `draw2d_preferred_monospace()`. [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).
* `listbox_font()`. [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).
* `ekFCELL` in font style to indicate the font size means cell height. [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).
* Support for font stretch. [Doc](https://nappgui.com/en/draw2d/font.html#h6). [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).
* `font_with_width()`.
* `font_with_xscale()`.
* `font_width()`.
Expand All @@ -40,9 +42,9 @@
* macOS HighSierra and lowers focus ring drawing issue. [Commit](https://github.com/frang75/nappgui_src/commit/a163cb2555101b831414b6deb781a1d1c49ccd42).
* Issue in `dbind_destroy()`. [Commit](https://github.com/frang75/nappgui_src/commit/f8e16ad9d7712339400ca55b1a3ab4a426f1da2a).
* Issue in `layout_panel_replace()`. [Commit](https://github.com/frang75/nappgui_src/commit/f8e16ad9d7712339400ca55b1a3ab4a426f1da2a).
* GTK buttons always show shortcut underscore. [Commit]().
* macOS pushbuttons images were not shown. [Commit]().
* `gui_alt_color()` avoid to register twice the same color. [Commit]().
* GTK buttons always show shortcut underscore. [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).
* macOS pushbuttons images were not shown. [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).
* `gui_alt_color()` avoid to register twice the same color. [Commit](https://github.com/frang75/nappgui_src/commit/3e0bb15a8244d8d5e21a055148deda48ab09c74b).

### Improved

Expand Down
2 changes: 1 addition & 1 deletion prj/build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5533
5547
2 changes: 1 addition & 1 deletion prj/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.3
1.5.0
2 changes: 1 addition & 1 deletion src/draw2d/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static ___INLINE color_t i_effective(color_t c)
if (i_alpha(c) == 0)
{
cassert(c <= 0xFFFF);
return draw2d_get_indexed_color((uint16_t)c);
return _draw2d_get_indexed_color((uint16_t)c);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/draw2d/dctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/*---------------------------------------------------------------------------*/

void dctx_init(DCtx *ctx)
void _dctx_init(DCtx *ctx)
{
Font *font = font_system(font_regular_size(), 0);
draw_matrixf(ctx, kT2D_IDENTf);
Expand All @@ -49,7 +49,7 @@ void dctx_init(DCtx *ctx)

void draw_matrixf(DCtx *ctx, const T2Df *t2d)
{
dctx_transform(ctx, t2d, FALSE);
_dctx_transform(ctx, t2d, FALSE);
}

/*---------------------------------------------------------------------------*/
Expand All @@ -63,7 +63,7 @@ void draw_matrixd(DCtx *ctx, const T2Dd *t2d)
t2df.j.y = (real32_t)t2d->j.y;
t2df.p.x = (real32_t)t2d->p.x;
t2df.p.y = (real32_t)t2d->p.y;
dctx_transform(ctx, &t2df, FALSE);
_dctx_transform(ctx, &t2df, FALSE);
}

/*---------------------------------------------------------------------------*/
Expand All @@ -80,7 +80,7 @@ void draw_matrix_cartesianf(DCtx *ctx, const T2Df *t2d)
ct2d.p.x = 0;
ct2d.p.y = (real32_t)h;
t2d_multf(&ct2d, &ct2d, t2d);
dctx_transform(ctx, &ct2d, TRUE);
_dctx_transform(ctx, &ct2d, TRUE);
}

/*---------------------------------------------------------------------------*/
Expand All @@ -104,7 +104,7 @@ void draw_matrix_cartesiand(DCtx *ctx, const T2Dd *t2d)
ct2d.p.x = 0;
ct2d.p.y = (real32_t)h;
t2d_multf(&ct2d, &ct2d, &t2df);
dctx_transform(ctx, &ct2d, TRUE);
_dctx_transform(ctx, &ct2d, TRUE);
}

/*---------------------------------------------------------------------------*/
4 changes: 2 additions & 2 deletions src/draw2d/dctx.inl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

__EXTERN_C

void dctx_init(DCtx *ctx);
void _dctx_init(DCtx *ctx);

void dctx_transform(DCtx *ctx, const T2Df *t2d, const bool_t cartesian);
void _dctx_transform(DCtx *ctx, const T2Df *t2d, const bool_t cartesian);

__END_C
8 changes: 4 additions & 4 deletions src/draw2d/draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

__EXTERN_C

void draw_alloc_globals(void);
void _draw_alloc_globals(void);

void draw_dealloc_globals(void);
void _draw_dealloc_globals(void);

void draw_word_extents(MeasureStr *data, const char_t *word, real32_t *width, real32_t *height);
void _draw_word_extents(MeasureStr *data, const char_t *word, real32_t *width, real32_t *height);

void draw_imgimp(DCtx *ctx, const OSImage *image, const uint32_t frame_index, const real32_t x, const real32_t y, const bool_t raster);
void _draw_imgimp(DCtx *ctx, const OSImage *image, const uint32_t frame_index, const real32_t x, const real32_t y, const bool_t raster);

__END_C
18 changes: 9 additions & 9 deletions src/draw2d/draw2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void draw2d_start(void)
core_start();
osimage_alloc_globals();
osfont_alloc_globals();
draw_alloc_globals();
_draw_alloc_globals();
blib_atexit(i_draw2d_atexit);

i_FONT_FAMILIES = arrpt_create(String);
Expand Down Expand Up @@ -108,7 +108,7 @@ void draw2d_finish(void)
str_destopt(&i_MONOSPACE_FONT_FAMILY);
osfont_dealloc_globals();
osimage_dealloc_globals();
draw_dealloc_globals();
_draw_dealloc_globals();
core_finish();
}

Expand All @@ -125,7 +125,7 @@ void draw2d_preferred_monospace(const char_t *family)

/*---------------------------------------------------------------------------*/

uint32_t draw2d_register_font(const char_t *font_family)
uint32_t _draw2d_register_font(const char_t *font_family)
{
/* Check if font name is a system font */
font_family_t fsystem = osfont_system(font_family);
Expand Down Expand Up @@ -156,7 +156,7 @@ uint32_t draw2d_register_font(const char_t *font_family)

/*---------------------------------------------------------------------------*/

const char_t *draw2d_font_family(const uint32_t family)
const char_t *_draw2d_font_family(const uint32_t family)
{
const String *font_family = arrpt_get(i_FONT_FAMILIES, family, String);
return tc(font_family);
Expand Down Expand Up @@ -189,7 +189,7 @@ color_t color_indexed(const uint16_t index, const color_t color)

/*---------------------------------------------------------------------------*/

color_t draw2d_get_indexed_color(const uint16_t index)
color_t _draw2d_get_indexed_color(const uint16_t index)
{
if (index == 0)
return kCOLOR_DEFAULT;
Expand Down Expand Up @@ -312,7 +312,7 @@ static void i_new_line(void *data, FPtr_word_extents func_word_extents, real32_t

/*---------------------------------------------------------------------------*/

void draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const bool_t newlines, const char_t *str, const real32_t refwidth, real32_t *width, real32_t *height)
void _draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const bool_t newlines, const char_t *str, const real32_t refwidth, real32_t *width, real32_t *height)
{
uint32_t num_lines = 0;
real32_t ref_width = refwidth > 0 ? refwidth : 1e8f;
Expand Down Expand Up @@ -408,7 +408,7 @@ void draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const b

/*---------------------------------------------------------------------------*/

const char_t *draw2d_monospace_family(const char_t **desired_fonts, const uint32_t n)
const char_t *_draw2d_monospace_family(const char_t **desired_fonts, const uint32_t n)
{
if (i_MONOSPACE_FONT_FAMILY == NULL)
{
Expand Down Expand Up @@ -439,7 +439,7 @@ const char_t *draw2d_monospace_family(const char_t **desired_fonts, const uint32

/*---------------------------------------------------------------------------*/

const char_t *draw2d_get_preferred_monospace(void)
const char_t *_draw2d_get_preferred_monospace(void)
{
if (i_USER_MONOSPACE_FONT_FAMILY != NULL)
return tc(i_USER_MONOSPACE_FONT_FAMILY);
Expand All @@ -449,7 +449,7 @@ const char_t *draw2d_get_preferred_monospace(void)

/*---------------------------------------------------------------------------*/

const char_t *draw2d_str_avg_char_width(uint32_t *len)
const char_t *_draw2d_str_avg_char_width(uint32_t *len)
{
cassert_no_null(len);
*len = i_AVG_CHAR_WIDTH_LEN;
Expand Down
18 changes: 9 additions & 9 deletions src/draw2d/draw2d.inl
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@

__EXTERN_C

uint32_t draw2d_register_font(const char_t *font_family);
uint32_t _draw2d_register_font(const char_t *font_family);

const char_t *draw2d_font_family(const uint32_t family);
const char_t *_draw2d_font_family(const uint32_t family);

color_t draw2d_get_indexed_color(const uint16_t index);
color_t _draw2d_get_indexed_color(const uint16_t index);

void draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const bool_t newlines, const char_t *str, const real32_t refwidth, real32_t *width, real32_t *height);
void _draw2d_extents_imp(void *data, FPtr_word_extents func_word_extents, const bool_t newlines, const char_t *str, const real32_t refwidth, real32_t *width, real32_t *height);

const char_t *draw2d_monospace_family(const char_t **desired_fonts, const uint32_t n);
const char_t *_draw2d_monospace_family(const char_t **desired_fonts, const uint32_t n);

const char_t *draw2d_get_preferred_monospace(void);
const char_t *_draw2d_get_preferred_monospace(void);

const char_t *draw2d_str_avg_char_width(uint32_t *len);
const char_t *_draw2d_str_avg_char_width(uint32_t *len);

__END_C

#define draw2d_extents(data, func_word_extents, newlines, str, refwidth, width, height, type) \
#define _draw2d_extents(data, func_word_extents, newlines, str, refwidth, width, height, type) \
((void)((type *)(data) == (data)), \
FUNC_CHECK_WORD_EXTENTS(func_word_extents, type), \
draw2d_extents_imp((void *)data, (FPtr_word_extents)func_word_extents, newlines, str, refwidth, width, height))
_draw2d_extents_imp((void *)data, (FPtr_word_extents)func_word_extents, newlines, str, refwidth, width, height))
8 changes: 4 additions & 4 deletions src/draw2d/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static ___INLINE void i_osfont(Font *font)
cassert_no_null(font);
if (font->osfont == NULL)
{
const char_t *fname = draw2d_font_family(font->family);
const char_t *fname = _draw2d_font_family(font->family);
font->osfont = osfont_create(fname, font->size, -1, -1, font->style);
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ void font_destroy(Font **font)

Font *font_create(const char_t *family, const real32_t size, const uint32_t style)
{
uint32_t ffamily = draw2d_register_font(family);
uint32_t ffamily = _draw2d_register_font(family);
return i_create_font(ffamily, size, style);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ Font *font_with_width(const Font *font, const real32_t width)
font_scaled = i_create_font(font_nscaled->family, font_nscaled->size, font_nscaled->style);
font_scaled->xscale = width / font_nscaled->avg_width;
cassert(font_scaled->osfont == NULL);
fname = draw2d_font_family(font_scaled->family);
fname = _draw2d_font_family(font_scaled->family);
font_scaled->osfont = osfont_create(fname, font_scaled->size, width, font_scaled->xscale, font_scaled->style);

if (font_nscaled != font)
Expand Down Expand Up @@ -189,7 +189,7 @@ Font *font_with_xscale(const Font *font, const real32_t scale)
font_scaled->xscale = scale;
width = font_nscaled->avg_width * scale;
cassert(font_scaled->osfont == NULL);
fname = draw2d_font_family(font_scaled->family);
fname = _draw2d_font_family(font_scaled->family);
font_scaled->osfont = osfont_create(fname, font_scaled->size, width, font_scaled->xscale, font_scaled->style);

if (font_nscaled != font)
Expand Down
10 changes: 5 additions & 5 deletions src/draw2d/gtk/dctx_gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ void dctx_set_gcontext(DCtx *ctx, void *gcontext, const uint32_t width, const ui
ctx->offset_y = (double)offset_y;
ctx->width = width;
ctx->height = height;
ctx->cairo = (cairo_t *)gcontext;
ctx->cairo = cast(gcontext, cairo_t);
cairo_translate(ctx->cairo, -(double)offset_x, -(double)offset_y);
cairo_get_matrix(ctx->cairo, &ctx->origin);
ctx->raster_mode = FALSE;

if (reset == TRUE)
dctx_init(ctx);
_dctx_init(ctx);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -214,7 +214,7 @@ ellipsis_t dctx_text_trim(const DCtx *ctx)
void *dctx_native(DCtx *ctx)
{
cassert_no_null(ctx);
return (void *)ctx->cairo;
return cast(ctx->cairo, void);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -278,13 +278,13 @@ DCtx *dctx_bitmap(const uint32_t width, const uint32_t height, const pixformat_t
cairo_matrix_init_identity(&ctx->origin);
cairo_matrix_init_identity(&ctx->transform);
cairo_matrix_init_identity(&ctx->pattern_matrix);
dctx_init(ctx);
_dctx_init(ctx);
return ctx;
}

/*---------------------------------------------------------------------------*/

void dctx_transform(DCtx *ctx, const T2Df *t2d, const bool_t cartesian)
void _dctx_transform(DCtx *ctx, const T2Df *t2d, const bool_t cartesian)
{
cairo_matrix_t transform;
cassert_no_null(ctx);
Expand Down
Loading

0 comments on commit 569e797

Please sign in to comment.