5 static Array<FileFilter> filters
8 $"Image Files (*.jpg, *.jpeg, *.bmp, *.pcx, *.png, *.gif)",
9 "jpg, jpeg, bmp, pcx, png, gif"
12 static Array<FileType> types
17 static FileDialog fileDialog { autoCreate = false, filters = filters.array, sizeFilters = filters.count * sizeof(FileFilter), types = types.array, sizeTypes = types.count * sizeof(FileType), text = $"Select Image" };
19 public class BitmapResource : Resource
23 bool grayed, mono, transparent;
39 // Logf("Freeing %s (%d)\n", fileName, bitmap.picture);
40 // bitmap.Free(bitmap);
47 void Load(BitmapResource copy, DisplaySystem displaySystem)
50 fileName = CopyString(copy.fileName);
53 transparent = copy.transparent;
54 alphaBlend = copy.alphaBlend;
55 mipMaps = copy.mipMaps;
56 keepData = copy.keepData;
60 DisplaySystem ds = displaySystem;
62 bitmap = Bitmap { alphaBlend = (alphaBlend && displaySystem.pixelFormat != pixelFormat8), keepData = keepData };
63 #if defined(__WIN32__)
64 // if(bitmap.alphaBlend) ds = null;
67 (mipMaps && !bitmap.LoadMipMaps(fileName, null, ds)) ||
68 (!mipMaps && mono && !bitmap.LoadMonochrome(fileName, null, ds)) ||
69 (!mipMaps && !mono && grayed && !bitmap.LoadGrayed(fileName, null, ds)) ||
70 (!mipMaps && !mono && !grayed && transparent && !bitmap.LoadT(fileName, null, ds)) ||
71 (!mipMaps && !mono && !grayed && !transparent && !bitmap.Load(fileName, null, ds)))
73 if(bitmap && bitmap.alphaBlend)
75 bitmap.Convert(null, pixelFormat888, null);
76 bitmap.displaySystem = displaySystem;
81 void Reference(BitmapResource reference)
83 bitmap = reference.bitmap;
94 Window OnEdit(DataBox window, DataBox master, int x, int y, int w, int h, void * userData)
96 Window editData = class::OnEdit(window, master, x + 24, y, w - 48, h, userData);
99 window, master = editData, inactive = true, text = "...", hotKey = f2,
100 position = { Max(x + 24, x + w - 24), y }, size = { 24, h };
102 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
104 DataBox master = (DataBox)this.master;
105 fileDialog.master = rootWindow;
106 if(fileDialog.Modal() == ok)
108 const char * filePath = fileDialog.filePath;
109 BitmapResource resource { fileName = filePath };
111 master.SetData(resource, false);
112 // TOCHECK: Why do we need to Refresh here?
115 // TODO: This is a Button?
116 // contents = filePath;
121 editData.anchor.right = 24;
127 void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
129 char * string = this ? fileName : null;
130 Bitmap bitmap = this ? this.bitmap : null;
131 // TODO: This isn't an ideal way of obtaining the clipped height, will fail on hidden areas
132 int yOffset = (1+surface.box.bottom - surface.box.top - 17)/2;
135 if(!string) string = "(none)";
136 surface.WriteTextDots(alignment, x + 24, y + 1, width - 24, string, strlen(string));
139 surface.WriteTextDots(alignment, x + 24, y + 1, width - 24, string, strlen(string));
141 surface.WriteTextDots(alignment, x + 24, y + 1, width - 24, "(none)", 6);
144 surface.SetBackground(white);
145 surface.Area(x - 4, y, x + 20, y + 15);
147 surface.Filter(bitmap, x, y + 2, 0,0, 18, 12, bitmap.width, bitmap.height);
149 surface.SetForeground(black);
150 surface.Rectangle(x-1, y + 1, x + 18, y + 14);
154 property const char * fileName
159 fileName = CopyString(value);
160 if(value && SearchString(value, 0, ".png", false, true))
163 get { return this ? fileName : null; }
165 property bool grayed { set { grayed = value; } get { return this ? grayed : false; } };
166 property bool monochrome
172 get { return this ? mono : false; }
174 property bool transparent { set { transparent = value; } get { return this ? transparent : false; } isset { return (this && !transparent) ? true : false; } };
175 property bool alphaBlend
177 set { alphaBlend = value; }
178 get { return this ? alphaBlend : false; }
179 isset { return alphaBlend && (!fileName || !SearchString(fileName, 0, ".png", false, true)); }
181 property bool mipMaps
183 set { mipMaps = value; }
184 get { return this ? mipMaps : false; }
185 isset { return mipMaps; }
187 property bool keepData { set { keepData = value; } get { return this ? keepData : false; } };
188 property Bitmap bitmap { get { return this ? bitmap : null; } set { bitmap = value; if(bitmap) incref bitmap; } };
189 property Window window { set { if(value) value.AddResource(this); } };