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;
38 // Logf("Freeing %s (%d)\n", fileName, bitmap.picture);
39 // bitmap.Free(bitmap);
46 void Load(BitmapResource copy, DisplaySystem displaySystem)
49 fileName = CopyString(copy.fileName);
52 transparent = copy.transparent;
53 alphaBlend = copy.alphaBlend;
54 keepData = copy.keepData;
58 DisplaySystem ds = displaySystem;
60 bitmap = Bitmap { alphaBlend = (alphaBlend && displaySystem.pixelFormat != pixelFormat8), keepData = keepData };
61 #if defined(__WIN32__)
62 // if(bitmap.alphaBlend) ds = null;
64 if((mono && !bitmap.LoadMonochrome(fileName, null, ds)) ||
65 (!mono && grayed && !bitmap.LoadGrayed(fileName, null, ds)) ||
66 (!mono && !grayed && transparent && !bitmap.LoadT(fileName, null, ds)) ||
67 (!mono && !grayed && !transparent && !bitmap.Load(fileName, null, ds)))
69 if(bitmap && bitmap.alphaBlend)
71 bitmap.Convert(null, pixelFormat888, null);
72 bitmap.displaySystem = displaySystem;
77 void Reference(BitmapResource reference)
79 bitmap = reference.bitmap;
90 Window OnEdit(DataBox window, DataBox master, int x, int y, int w, int h, void * userData)
92 Window editData = class::OnEdit(window, master, x + 24, y, w - 48, h, userData);
95 window, master = editData, inactive = true, text = "...", hotKey = f2,
96 position = { Max(x + 24, x + w - 24), y }, size = { 24, h };
98 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
100 DataBox master = (DataBox)this.master;
101 fileDialog.master = rootWindow;
102 if(fileDialog.Modal() == ok)
104 const char * filePath = fileDialog.filePath;
105 BitmapResource resource { fileName = filePath };
107 master.SetData(resource, false);
108 // TOCHECK: Why do we need to Refresh here?
111 // TODO: This is a Button?
112 // contents = filePath;
117 editData.anchor.right = 24;
123 void OnDisplay(Surface surface, int x, int y, int width, void * fieldData, Alignment alignment, DataDisplayFlags displayFlags)
125 char * string = this ? fileName : null;
126 Bitmap bitmap = this ? this.bitmap : null;
127 // TODO: This isn't an ideal way of obtaining the clipped height, will fail on hidden areas
128 int yOffset = (1+surface.box.bottom - surface.box.top - 17)/2;
131 if(!string) string = "(none)";
132 surface.WriteTextDots(alignment, x + 24, y + 1, width - 24, string, strlen(string));
135 surface.WriteTextDots(alignment, x + 24, y + 1, width - 24, string, strlen(string));
137 surface.WriteTextDots(alignment, x + 24, y + 1, width - 24, "(none)", 6);
140 surface.SetBackground(white);
141 surface.Area(x - 4, y, x + 20, y + 15);
143 surface.Filter(bitmap, x, y + 2, 0,0, 18, 12, bitmap.width, bitmap.height);
145 surface.SetForeground(black);
146 surface.Rectangle(x-1, y + 1, x + 18, y + 14);
150 property const char * fileName
155 fileName = CopyString(value);
156 if(value && SearchString(value, 0, ".png", false, true))
159 get { return this ? fileName : null; }
161 property bool grayed { set { grayed = value; } get { return this ? grayed : false; } };
162 property bool monochrome
168 get { return this ? mono : false; }
170 property bool transparent { set { transparent = value; } get { return this ? transparent : false; } isset { return (this && !transparent) ? true : false; } };
171 property bool alphaBlend
173 set { alphaBlend = value; }
174 get { return this ? alphaBlend : false; }
175 isset { return alphaBlend && (!fileName || !SearchString(fileName, 0, ".png", false, true)); }
177 property bool keepData { set { keepData = value; } get { return this ? keepData : false; } };
178 property Bitmap bitmap { get { return this ? bitmap : null; } set { bitmap = value; if(bitmap) incref bitmap; } };
179 property Window window { set { if(value) value.AddResource(this); } };