Copyright (c) 2003 Jerome Jacovella-St-Louis
All Rights Reserved.
-
+
pictureEdit.ec - Picture Editor Control
****************************************************************************/
#ifdef ECERE_STATIC
float zoomFactor;
char fileName[MAX_LOCATION];
Bitmap bitmap;
-
+ Bitmap bitmapNotIndexed;
+
//saveDialog = pictureEditFileDialog;
-
- Menu fileMenu { menu, "File", f }
- MenuItem { fileMenu, "Save", s, ctrlS, NotifySelect = MenuFileSave };
- MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
- Menu imageMenu { menu, "Image", i };
- Menu modeMenu { imageMenu, "Mode", m };
+
+ Menu fileMenu { menu, $"File", f };
+ MenuItem { fileMenu, $"Save", s, ctrlS, NotifySelect = MenuFileSave };
+ MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
+ Menu imageMenu { menu, $"Image", i };
+ Menu modeMenu { imageMenu, $"Mode", m };
MenuItem imageModeIndexedItem
{
- modeMenu, "Indexed Color...", i, isRadio = true;
+ modeMenu, $"Indexed Color...", i, isRadio = true;
bool NotifySelect(MenuItem selection, Modifiers mods)
{
- ColorAlpha * palette = bitmap.Quantize(0, 255);
- /*
- eBitmap_Convert(null, bitmap, PixelFormat8, palette);
- bitmap.allocatePalette = true;
- */
-
- imageModeColorTableItem.disabled = false;
- Update(null);
- modifiedDocument = true;
+ if(bitmap)
+ {
+ ColorAlpha * palette = bitmap.Quantize(0, 255);
+ bitmapNotIndexed = { };
+ bitmapNotIndexed.Copy(bitmap);
+ bitmapNotIndexed.Convert(null, pixelFormat888, null);
+
+ /*
+ eBitmap_Convert(null, bitmap, PixelFormat8, palette);
+ bitmap.allocatePalette = true;
+ */
+
+ imageModeColorTableItem.disabled = false;
+ Update(null);
+ modifiedDocument = true;
+ }
return true;
}
};
MenuItem imageModeRGBItem
{
- modeMenu, "RGB Color", r, isRadio = true;
+ modeMenu, $"RGB Color", r, isRadio = true;
bool NotifySelect(MenuItem selection, Modifiers mods)
{
- bitmap.Convert(null, pixelFormat888, null);
+ if(bitmap)
+ bitmap.Convert(null, pixelFormat888, null);
+ delete bitmapNotIndexed;
imageModeColorTableItem.disabled = true;
Update(null);
modifiedDocument = true;
MenuDivider { modeMenu };
MenuItem imageModeColorTableItem
{
- modeMenu, "Color Table", r;
+ modeMenu, $"Color Table", r;
bool NotifySelect(MenuItem selection, Modifiers mods)
{
- PictureEditColorTable colorTable { master = this };
- colorTable.Modal();
- Update(null);
+ if(bitmap)
+ {
+ PictureEditColorTable colorTable { master = this };
+ colorTable.Modal();
+ Update(null);
+ }
return true;
}
};
MenuDivider { imageMenu };
MenuItem adjustHSVItem
{
- imageMenu, "Adjust Hue, Saturation, Value", h;
+ imageMenu, $"Adjust Hue, Saturation, Value", h;
bool NotifySelect(MenuItem selection, Modifiers mods)
{
- AdjustHSV adjustHSV { master = this };
- adjustHSV.Modal();
- Update(null);
+ if(bitmap)
+ {
+ AdjustHSV adjustHSV { master = this };
+ adjustHSV.Modal();
+ Update(null);
+ }
return true;
}
};
#endif
-
- property char * bitmapFile
+
+ property const char * bitmapFile
{
set
{
if(bitmap.Load(fileName, null, null))
{
if(bitmap.pixelFormat == pixelFormatRGBA)
+ {
+ bitmap.alphaBlend = true;
bitmap.Convert(null, pixelFormat888, null);
-
+ }
+ if(bitmap.pixelFormat == pixelFormat8)
+ {
+ bitmapNotIndexed = { };
+ bitmapNotIndexed.Copy(bitmap);
+ bitmapNotIndexed.Convert(null, pixelFormat888, null);
+ }
//if(!eWindow_GetStartWidth(window) || !eWindow_GetStartHeight(window))
{
Size size = initSize; // what's the use of retrieving initSize
clientSize = size;
/*
- Move(eWindow_GetStartX(window), eWindow_GetStartY(window),
- (!eWindow_GetStartWidth(window)) ? (A_CLIENT|bitmap.width) : eWindow_GetStartWidth(window),
+ Move(eWindow_GetStartX(window), eWindow_GetStartY(window),
+ (!eWindow_GetStartWidth(window)) ? (A_CLIENT|bitmap.width) : eWindow_GetStartWidth(window),
(!eWindow_GetStartHeight(window)) ? (A_CLIENT|bitmap.height) : eWindow_GetStartHeight(window));
*/
/*
- Move(eWindow_GetStartX(window), eWindow_GetStartY(window),
- (!) ? (A_CLIENT|bitmap.width) : eWindow_GetStartWidth(window),
+ Move(eWindow_GetStartX(window), eWindow_GetStartY(window),
+ (!) ? (A_CLIENT|bitmap.width) : eWindow_GetStartWidth(window),
(!eWindow_GetStartHeight(window)) ? (A_CLIENT|bitmap.height) : eWindow_GetStartHeight(window));
*/
}
- scrollArea = Size {bitmap.width, bitmap.height };
+ scrollArea = Size { bitmap.width, bitmap.height };
}
else
delete bitmap;
void OnRedraw(Surface surface)
{
- if(bitmap)
+ Bitmap bmp = (bitmapNotIndexed && displaySystem.pixelFormat != pixelFormat8) ? bitmapNotIndexed : bitmap;
+ if(bmp)
{
- int w = (int)(bitmap.width * zoomFactor);
- int h = (int)(bitmap.height * zoomFactor);
- if(w == bitmap.width && h == bitmap.height)
+ int w = (int)(bmp.width * zoomFactor);
+ int h = (int)(bmp.height * zoomFactor);
+ if(w == bmp.width && h == bmp.height)
{
- surface.Blit(bitmap,
- Max(0, (clientSize.w - w) / 2), Max(0, (clientSize.h - h) / 2),
+ surface.Blit(bmp,
+ Max(0, (clientSize.w - w) / 2), Max(0, (clientSize.h - h) / 2),
scroll.x, scroll.y, w, h);
}
else
{
- surface.Filter(bitmap,
- Max(0, (clientSize.w - w) / 2), Max(0, (clientSize.h - h) / 2),
- (int)(scroll.x / zoomFactor), (int)(scroll.y / zoomFactor), w, h,
- bitmap.width, bitmap.height);
+ surface.Filter(bmp,
+ Max(0, (clientSize.w - w) / 2), Max(0, (clientSize.h - h) / 2),
+ (int)(scroll.x / zoomFactor), (int)(scroll.y / zoomFactor), w, h,
+ bmp.width, bmp.height);
}
}
}
{
case equal:
case keyPadPlus:
- if(zoomFactor < 25)
+ if(bitmap && zoomFactor < 25)
{
float x = 0.5f, y = 0.5f;
- if(bitmap.width * zoomFactor > clientSize.w)
+ if(bitmap.width * zoomFactor > clientSize.w)
x = scroll.x / (bitmap.width * zoomFactor - clientSize.w);
- if(bitmap.height * zoomFactor > clientSize.h)
+ if(bitmap.height * zoomFactor > clientSize.h)
y = scroll.y / (bitmap.height * zoomFactor - clientSize.h);
zoomFactor *= 1.5;
scrollArea = Size { bitmap.width * zoomFactor, bitmap.height * zoomFactor };
- scroll = Point {
- (int)(Max(0, bitmap.width * zoomFactor - clientSize.w) * x),
+ scroll = Point {
+ (int)(Max(0, bitmap.width * zoomFactor - clientSize.w) * x),
(int)(Max(0, bitmap.height * zoomFactor - clientSize.h) * y) };
Update(null);
break;
case minus:
case keyPadMinus:
- if(zoomFactor > 0.05)
+ if(bitmap && zoomFactor > 0.05)
{
float x = 0.5f, y = 0.5f;
- if(bitmap.width * zoomFactor > clientSize.w)
+ if(bitmap.width * zoomFactor > clientSize.w)
x = scroll.x / (bitmap.width * zoomFactor - clientSize.w);
- if(bitmap.height * zoomFactor > clientSize.w)
+ if(bitmap.height * zoomFactor > clientSize.w)
y = scroll.y / (bitmap.height * zoomFactor - clientSize.h);
zoomFactor /= 1.5;
scrollArea = Size { bitmap.width * zoomFactor, bitmap.height * zoomFactor };
- scroll = Point {
+ scroll = Point {
(int)(Max(0, bitmap.width * zoomFactor - clientSize.w) * x),
(int)(Max(0, bitmap.height * zoomFactor - clientSize.h) * y) };
return true;
}
- bool OnSaveFile(char * fileName)
+ bool OnSaveFile(const char * fileName)
{
bool result = false;
if(bitmap)
{
- if(bitmap.Save(fileName,
+ if(bitmap.Save(fileName,
((FileType *)pictureEditFileDialog.types)[pictureEditFileDialog.fileType].typeExtension, (void *) bool::true))
{
modifiedDocument = false;
}
return result;
}
-
+
PictureEdit()
{
zoomFactor = 1.0f;
return true;
}
+ ~PictureEdit()
+ {
+ delete bitmap;
+ delete bitmapNotIndexed;
+ }
}
class PictureEditColorTable : Window
{
hasClose = true;
- text = "Color Table";
- background = activeBorder;
+ text = $"Color Table";
+ background = formColor;
minClientSize = Size { 400, 400 };
Button button
{
- parent = this, hotKey = escape, size = { 80 }, text = "Close";
+ parent = this, hotKey = escape, size = { 80 }, text = $"Close";
anchor = Anchor { right = 10, bottom = 10 };
NotifyClicked = ButtonCloseDialog;
};
{
size = { 400, 300 };
- background = activeBorder;
+ background = formColor;
ColorHSV target;
ColorHSV replace;
replace = { 248, 100, 71 }; //Color { 26, 0, 183 };
Button button1
{
- this, text = "Go", position = { 296, 104 }, isDefault = true;
+ this, text = $"Go", position = { 296, 104 }, isDefault = true;
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
double tolH = 1;
double tolS = 1;
double tolV = 1;
-
+
h = target.h - replace.h;
s = target.s / replace.s;
v = target.v / replace.v;