Skip to content

Commit fa24258

Browse files
committed
Solved bug on GTK images, build 3657, v.1.2.1-r6
1 parent f853ab7 commit fa24258

File tree

14 files changed

+64
-39
lines changed

14 files changed

+64
-39
lines changed

prj/build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3651
1+
3657

src/draw2d/gtk3/osimage.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,13 @@ void osimage_frame(const OSImage *image, const uint32_t frame_index, real32_t *f
810810

811811
/*---------------------------------------------------------------------------*/
812812

813+
const void *osimage_native(const OSImage *image)
814+
{
815+
return (const void*)osimage_pixbuf(image, 0);
816+
}
817+
818+
/*---------------------------------------------------------------------------*/
819+
813820
const GdkPixbuf *osimage_pixbuf(const OSImage *image, const uint32_t frame_index)
814821
{
815822
cassert_no_null(image);

src/draw2d/image.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,22 @@ real32_t image_frame_length(const Image *image, const uint32_t findex)
614614

615615
/*---------------------------------------------------------------------------*/
616616

617-
//func(image_native).Devuelve un puntero al objeto nativo que implementa la imagen.
618-
//fret(void*).El objeto nativo. Ser� <c>Gdiplus::Bitmap</c> en Windows, <c>NSImage</c> en macOS y <c>GdkPixbuf</c> en Linux/Gtk.
619-
//fpar(const Image*,image).La imagen.
620-
//fnote.Utiliza este puntero para crear c�digo especializado, dependiente de plataforma.
621-
void *image_native(const Image *image)
617+
const OSImage *osimage_from_image(const Image *image)
622618
{
623619
cassert_no_null(image);
624620
return image->osimage;
625621
}
626622

627623
/*---------------------------------------------------------------------------*/
628624

625+
const void *image_native(const Image *image)
626+
{
627+
cassert_no_null(image);
628+
return osimage_native(image->osimage);
629+
}
630+
631+
/*---------------------------------------------------------------------------*/
632+
629633
Image *dctx_image(DCtx **ctx)
630634
{
631635
OSImage *osimage = NULL;

src/draw2d/image.inl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
__EXTERN_C
1616

17-
void *image_native(const Image *image);
17+
const void *image_native(const Image *image);
1818

1919
void osimage_alloc_globals(void);
2020

@@ -30,6 +30,8 @@ OSImage *osimage_create_scaled(const OSImage *image, const uint32_t new_width, c
3030

3131
OSImage *osimage_from_context(DCtx **ctx);
3232

33+
const OSImage *osimage_from_image(const Image *image);
34+
3335
void osimage_destroy(OSImage **image);
3436

3537
void osimage_info(const OSImage *image, uint32_t *width, uint32_t *height, pixformat_t *format, Pixbuf **pixels);
@@ -42,8 +44,7 @@ void osimage_frames(const OSImage *image, uint32_t *num_frames, uint32_t *num_lo
4244

4345
void osimage_frame(const OSImage *image, const uint32_t frame_index, real32_t *frame_length);
4446

45-
__END_C
46-
47-
47+
const void *osimage_native(const OSImage *image);
4848

49+
__END_C
4950

src/draw2d/osx/osimage.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ void osimage_frame(const OSImage *image, const uint32_t frame_index, real32_t *f
489489

490490
/*---------------------------------------------------------------------------*/
491491

492+
const void *osimage_native(const OSImage *image)
493+
{
494+
return (const void*)image;
495+
}
496+
497+
/*---------------------------------------------------------------------------*/
498+
492499
/*void osimage_set_frame(const OSImage *image, const uint32_t frame_index)
493500
{
494501
NSBitmapImageRep *irep = nil;

src/draw2d/win/draw2d_win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ void draw_imgimp(DCtx *ctx, const OSImage *image, const uint32_t frame_index, co
10611061
cassert_no_null(ctx);
10621062
cassert_no_null(ctx->graphics);
10631063
cassert_unref(raster == FALSE, raster);
1064-
bitmap = (Gdiplus::Bitmap*)osimage_bitmap(image);
1064+
bitmap = (Gdiplus::Bitmap*)osimage_native(image);
10651065
i_set_gdiplus_mode(ctx);
10661066

10671067
if (frame_index != UINT32_MAX)

src/draw2d/win/osimage.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ void osimage_frame(const OSImage *image, const uint32_t frame_index, real32_t *f
826826

827827
/*---------------------------------------------------------------------------*/
828828

829-
void *osimage_bitmap(const OSImage *osimage)
829+
const void *osimage_native(const OSImage *osimage)
830830
{
831831
cassert_no_null(osimage);
832832
return osimage->bitmap;
@@ -836,12 +836,11 @@ void *osimage_bitmap(const OSImage *osimage)
836836

837837
HBITMAP osimage_hbitmap(const Image *image, COLORREF background)
838838
{
839-
OSImage *osimage = (OSImage*)image_native(image);
839+
Gdiplus::Bitmap *bitmap = (Gdiplus::Bitmap*)image_native(image);
840840
Gdiplus::Color c;
841841
HBITMAP hbitmap;
842-
cassert_no_null(osimage);
843842
c.SetFromCOLORREF(background);
844-
Gdiplus::Status status = osimage->bitmap->GetHBITMAP(c, &hbitmap);
843+
Gdiplus::Status status = bitmap->GetHBITMAP(c, &hbitmap);
845844
cassert_unref(status == Gdiplus::Ok, status);
846845
return hbitmap;
847846
}
@@ -850,25 +849,25 @@ HBITMAP osimage_hbitmap(const Image *image, COLORREF background)
850849

851850
HBITMAP osimage_hbitmap_cache(const Image *image, COLORREF background, LONG *width, LONG *height)
852851
{
853-
OSImage *osimage = (OSImage*)image_native(image);
852+
const OSImage *osimage = osimage_from_image(image);
854853
cassert_no_null(osimage);
855854

856855
if (osimage->hbitmap != NULL && osimage->hbitmap_background != background)
857856
{
858857
BOOL ret = DeleteObject(osimage->hbitmap);
859858
cassert_unref(ret != 0, ret);
860-
osimage->hbitmap = NULL;
859+
((OSImage*)osimage)->hbitmap = NULL;
861860
}
862861

863862
if (osimage->hbitmap == NULL)
864863
{
865864
BITMAP bm;
866865
HBITMAP hbitmap = osimage_hbitmap(image, background);
867-
osimage->hbitmap = hbitmap;
866+
((OSImage*)osimage)->hbitmap = hbitmap;
868867
GetObject(hbitmap, sizeof(bm), &bm);
869-
osimage->hbitmap_width = bm.bmWidth;
870-
osimage->hbitmap_height = bm.bmHeight;
871-
osimage->hbitmap_background = background;
868+
((OSImage*)osimage)->hbitmap_width = bm.bmWidth;
869+
((OSImage*)osimage)->hbitmap_height = bm.bmHeight;
870+
((OSImage*)osimage)->hbitmap_background = background;
872871
}
873872

874873
*width = osimage->hbitmap_width;
@@ -954,12 +953,12 @@ HCURSOR osimage_hcursor(const Image *image, const uint32_t hot_x, const uint32_t
954953
{
955954
// HCURSOR direct from Gdiplus::Bitmap ;-)
956955
// http://csharphelper.com/blog/2017/01/convert-a-bitmap-into-a-cursor-in-c/
957-
OSImage *osimage = (OSImage*)image_native(image);
956+
Gdiplus::Bitmap *bitmap = (Gdiplus::Bitmap*)image_native(image);
958957
HICON icon = NULL;
959958
ICONINFO info;
960959
HCURSOR hcursor = NULL;
961960
BOOL ret = FALSE;
962-
Gdiplus::Status st = osimage->bitmap->GetHICON(&icon);
961+
Gdiplus::Status st = bitmap->GetHICON(&icon);
963962
cassert_unref(st == Gdiplus::Ok, st);
964963
GetIconInfo(icon, &info);
965964
info.xHotspot = (DWORD)hot_x;
@@ -979,12 +978,12 @@ HCURSOR osimage_hcursor(const Image *image, const uint32_t hot_x, const uint32_t
979978

980979
void osimage_draw(const Image *image, HDC hdc, const uint32_t frame_index, const real32_t x, const real32_t y, const real32_t width, const real32_t height, const BOOL gray)
981980
{
982-
OSImage *osimage = (OSImage*)image_native(image);
981+
Gdiplus::Bitmap *bitmap = (Gdiplus::Bitmap*)image_native(image);
983982
Gdiplus::Graphics graphics(hdc);
984983

985984
if (frame_index != UINT32_MAX)
986985
{
987-
Gdiplus::Status status = osimage->bitmap->SelectActiveFrame(&Gdiplus::FrameDimensionTime, (UINT)frame_index);
986+
Gdiplus::Status status = bitmap->SelectActiveFrame(&Gdiplus::FrameDimensionTime, (UINT)frame_index);
988987
cassert_unref(status == Gdiplus::Ok, status);
989988
}
990989

@@ -1051,10 +1050,10 @@ void osimage_draw(const Image *image, HDC hdc, const uint32_t frame_index, const
10511050
Gdiplus::ImageAttributes attr;
10521051
Gdiplus::RectF rect((Gdiplus::REAL)x, (Gdiplus::REAL)y, (Gdiplus::REAL)width, (Gdiplus::REAL)height);
10531052
attr.SetColorMatrix(&matrix, Gdiplus::ColorMatrixFlagsDefault, Gdiplus::ColorAdjustTypeBitmap);
1054-
graphics.DrawImage(osimage->bitmap, rect, (Gdiplus::REAL)0, (Gdiplus::REAL)0, (Gdiplus::REAL)width, (Gdiplus::REAL)height, Gdiplus::UnitPixel, &attr);
1053+
graphics.DrawImage(bitmap, rect, (Gdiplus::REAL)0, (Gdiplus::REAL)0, (Gdiplus::REAL)width, (Gdiplus::REAL)height, Gdiplus::UnitPixel, &attr);
10551054
}
10561055
else
10571056
{
1058-
graphics.DrawImage(osimage->bitmap, (Gdiplus::REAL)x, (Gdiplus::REAL)y, (Gdiplus::REAL)width, (Gdiplus::REAL)height);
1057+
graphics.DrawImage(bitmap, (Gdiplus::REAL)x, (Gdiplus::REAL)y, (Gdiplus::REAL)width, (Gdiplus::REAL)height);
10591058
}
10601059
}

src/draw2d/win/osimage.inl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
__EXTERN_C
1616

17-
void *osimage_bitmap(const OSImage *osimage);
18-
1917
HBITMAP osimage_hbitmap(const Image *image, COLORREF background);
2018

2119
HBITMAP osimage_hbitmap_cache(const Image *image, COLORREF background, LONG *width, LONG *height);

src/osgui/gtk3/oscombo.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,12 @@ void _oscombo_elem(GtkComboBox *combo, const op_t op, const uint32_t index, cons
441441
arrpt_append(images, img, Image);
442442
break;
443443
}
444+
444445
case ekOPDEL:
445446
arrpt_delete(texts, index, str_destroy, String);
446447
arrpt_delete(images, index, i_img_dest, Image);
447448
break;
449+
448450
case ekOPINS:
449451
{
450452
String *str = str_c(text);
@@ -453,6 +455,7 @@ void _oscombo_elem(GtkComboBox *combo, const op_t op, const uint32_t index, cons
453455
arrpt_insert(images, index, img, Image);
454456
break;
455457
}
458+
456459
case ekOPSET:
457460
{
458461
String **str = arrpt_all(texts, String) + index;
@@ -465,6 +468,7 @@ void _oscombo_elem(GtkComboBox *combo, const op_t op, const uint32_t index, cons
465468
}
466469
break;
467470
}
471+
468472
cassert_default();
469473
}
470474

@@ -478,7 +482,7 @@ void _oscombo_elem(GtkComboBox *combo, const op_t op, const uint32_t index, cons
478482
cassert(n == arrpt_size(images, Image));
479483
for (i = 0; i < n; ++i, ++strs, ++imgs)
480484
{
481-
void *pixbuf = NULL;
485+
const void *pixbuf = NULL;
482486
if (*imgs != NULL)
483487
{
484488
uint32_t w = image_width(*imgs);

src/osgui/gtk3/osdrawctrl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void osdrawctrl_text(DCtx *ctx, const char_t *text, const uint32_t x, const uint
197197

198198
void osdrawctrl_image(DCtx *ctx, const Image *image, const uint32_t x, const uint32_t y, const cstate_t state)
199199
{
200-
const OSImage *osimage = image_native(image);
200+
const OSImage *osimage = osimage_from_image(image);
201201
unref(state);
202202
draw_imgimp(ctx, osimage, UINT32_MAX, x, y, TRUE);
203203
}

0 commit comments

Comments
 (0)