ui/winui/image.cpp

changeset 108
77254bd6dccb
parent 76
641dcc79e0ef
equal deleted inserted replaced
107:b34bd1557c6c 108:77254bd6dccb
45 using namespace winrt::Microsoft::UI::Xaml::Media::Imaging; 45 using namespace winrt::Microsoft::UI::Xaml::Media::Imaging;
46 using namespace winrt::Microsoft::UI::Xaml::Media; 46 using namespace winrt::Microsoft::UI::Xaml::Media;
47 47
48 UiImageSource::UiImageSource(winrt::Microsoft::UI::Xaml::Media::ImageSource& src) : imgsrc(src) {} 48 UiImageSource::UiImageSource(winrt::Microsoft::UI::Xaml::Media::ImageSource& src) : imgsrc(src) {}
49 49
50 void UiImageSource::ref() {
51 refcount++;
52 }
53
54 void UiImageSource::unref() {
55 if (--refcount == 0) {
56 delete this;
57 }
58 }
59
50 UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) { 60 UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) {
51 UiObject* current = uic_current_obj(obj); 61 UiObject* current = uic_current_obj(obj);
52 62
53 Image image = Image(); 63 Image image = Image();
54 FrameworkElement elm = image; 64 FrameworkElement elm = image;
92 } 102 }
93 103
94 UiImageSource *imgdata = (UiImageSource*)data; 104 UiImageSource *imgdata = (UiImageSource*)data;
95 if (g->value) { 105 if (g->value) {
96 UiImageSource *prevData = (UiImageSource*)g->value; 106 UiImageSource *prevData = (UiImageSource*)g->value;
97 delete prevData; 107 //prevData->unref();
98 } 108 }
99 g->value = imgdata; 109 g->value = imgdata;
110 //imgdata->ref();
100 111
101 UiWidget* widget = (UiWidget*)g->obj; 112 UiWidget* widget = (UiWidget*)g->obj;
102 Image image = widget->uielement.as<Image>(); 113 Image image = widget->uielement.as<Image>();
103 image.Source(imgdata->imgsrc); 114 image.Source(imgdata->imgsrc);
104 115
115 bitmapImage.UriSource(uri); 126 bitmapImage.UriSource(uri);
116 ImageSource src = bitmapImage; 127 ImageSource src = bitmapImage;
117 128
118 UiImageSource *imgdata = new UiImageSource(src); 129 UiImageSource *imgdata = new UiImageSource(src);
119 obj->set(obj, imgdata, UI_IMAGE_OBJECT_TYPE); 130 obj->set(obj, imgdata, UI_IMAGE_OBJECT_TYPE);
131 imgdata->unref();
120 132
121 free(wpath); 133 free(wpath);
122 134
123 return 0; 135 return 0;
124 } 136 }
137
138 void ui_image_ref(UIIMAGE img) {
139 UiImageSource* imgdata = (UiImageSource*)img;
140 imgdata->ref();
141 }
142
143 void ui_image_unref(UIIMAGE img) {
144 UiImageSource* imgdata = (UiImageSource*)img;
145 imgdata->unref();
146 }

mercurial