#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#define USE_OPENGL 1 //#define USE_CONTEXTPLUS 1 #ifdef USE_OPENGL #include #include #endif #if _MSC_VER < 1800 /* vc12 (2013) */ #define DEFINE_ROUND #endif #ifdef DEFINE_ROUND double round(double x) { return (int)(x>0 ? x + 0.5 : x - 0.5); } #endif /********************************** Images *****************************************/ Ihandle* load_image_PaintLine(void) { unsigned char imgdata[] = { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 12, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 239, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 227, 0, 0, 0, 8, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 16, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_Pointer(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 162, 180, 203, 255, 162, 180, 203, 84, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 162, 180, 203, 255, 162, 180, 203, 255, 162, 180, 203, 84, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 162, 180, 203, 255, 240, 243, 246, 255, 162, 180, 203, 255, 162, 180, 203, 69, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 162, 180, 203, 255, 255, 255, 255, 255, 241, 244, 247, 255, 161, 179, 202, 255, 161, 179, 202, 57, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 158, 176, 200, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 242, 246, 255, 147, 165, 189, 255, 134, 152, 176, 57, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 153, 172, 195, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 227, 231, 236, 255, 129, 147, 171, 255, 115, 134, 158, 48, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 148, 166, 189, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 253, 254, 255, 213, 218, 226, 255, 111, 130, 154, 255, 96, 115, 140, 57, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 141, 159, 183, 255, 254, 255, 255, 255, 252, 253, 254, 255, 250, 251, 253, 255, 247, 248, 251, 255, 243, 246, 250, 255, 206, 213, 223, 255, 91, 110, 136, 255, 73, 92, 118, 48, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 134, 152, 176, 255, 249, 250, 252, 255, 246, 247, 251, 255, 242, 245, 249, 255, 238, 242, 247, 255, 92, 111, 137, 255, 56, 76, 102, 255, 60, 80, 106, 255, 73, 92, 118, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 127, 145, 170, 255, 241, 244, 249, 255, 205, 212, 221, 255, 88, 108, 133, 255, 229, 234, 243, 255, 105, 124, 148, 255, 105, 124, 148, 83, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 119, 138, 163, 255, 203, 209, 220, 255, 63, 83, 109, 255, 102, 121, 145, 255, 197, 206, 221, 255, 187, 197, 214, 255, 89, 108, 133, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 112, 131, 156, 255, 82, 101, 127, 255, 55, 75, 101, 81, 102, 121, 145, 123, 102, 121, 145, 255, 206, 215, 233, 255, 79, 99, 124, 255, 79, 99, 124, 45, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 105, 124, 150, 255, 255, 255, 255, 0, 255, 255, 255, 0, 102, 121, 145, 18, 95, 115, 140, 255, 190, 202, 223, 255, 152, 167, 189, 255, 67, 87, 112, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 95, 115, 140, 150, 84, 104, 129, 255, 164, 178, 202, 255, 58, 78, 104, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 95, 115, 140, 6, 70, 90, 116, 255, 59, 79, 105, 255, 55, 75, 101, 87, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintPencil(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 194, 126, 104, 73, 173, 108, 94, 255, 173, 108, 94, 255, 188, 121, 101, 48, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 173, 108, 94, 255, 235, 159, 129, 255, 208, 118, 94, 255, 173, 108, 94, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 187, 176, 125, 255, 172, 184, 202, 255, 209, 133, 115, 255, 173, 108, 94, 255, 144, 53, 53, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 185, 172, 115, 255, 238, 224, 140, 255, 217, 196, 108, 255, 134, 134, 125, 255, 144, 53, 53, 255, 131, 57, 47, 78, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 183, 166, 101, 255, 238, 224, 140, 255, 215, 191, 98, 255, 178, 154, 73, 255, 22, 18, 14, 255, 102, 85, 40, 48, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 185, 172, 115, 255, 238, 224, 140, 255, 215, 191, 98, 255, 178, 154, 73, 255, 22, 18, 14, 255, 117, 98, 45, 59, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 183, 166, 101, 255, 238, 224, 140, 255, 215, 191, 98, 255, 178, 154, 73, 255, 22, 18, 14, 255, 117, 98, 45, 59, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 181, 160, 87, 255, 238, 224, 140, 255, 215, 191, 98, 255, 178, 154, 73, 255, 22, 18, 14, 255, 117, 98, 45, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 175, 158, 120, 66, 179, 156, 77, 255, 238, 224, 140, 255, 215, 191, 98, 255, 178, 154, 73, 255, 22, 18, 14, 255, 117, 98, 45, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 157, 163, 255, 199, 183, 136, 255, 226, 206, 116, 255, 178, 154, 73, 255, 22, 18, 14, 255, 82, 68, 37, 40, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 157, 163, 118, 152, 157, 163, 255, 254, 254, 253, 255, 169, 147, 81, 255, 22, 18, 14, 255, 117, 98, 45, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 118, 110, 113, 117, 255, 81, 84, 87, 255, 0, 0, 0, 255, 82, 68, 37, 40, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 224, 0, 0, 0, 118, 81, 84, 87, 104, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintColorPicker(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 1, 1, 1, 85, 0, 0, 1, 192, 0, 0, 0, 192, 0, 0, 0, 85, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 7, 11, 15, 37, 8, 12, 16, 70, 79, 81, 83, 224, 205, 205, 205, 255, 136, 138, 142, 255, 11, 13, 15, 203, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 9, 15, 21, 119, 18, 26, 37, 255, 68, 70, 72, 255, 88, 93, 99, 255, 117, 120, 126, 255, 84, 86, 91, 255, 2, 2, 2, 194, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 15, 21, 30, 31, 23, 34, 49, 235, 49, 56, 65, 255, 70, 72, 72, 255, 54, 56, 58, 255, 21, 22, 22, 199, 0, 0, 0, 85, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 20, 30, 42, 42, 21, 32, 45, 237, 49, 56, 65, 255, 7, 9, 13, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 255, 255, 255, 255, 202, 208, 222, 255, 173, 183, 202, 255, 6, 10, 15, 236, 2, 4, 5, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 255, 255, 255, 255, 202, 208, 222, 255, 143, 156, 181, 255, 68, 88, 114, 255, 1, 1, 3, 33, 0, 0, 0, 111, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 255, 255, 255, 255, 214, 220, 230, 255, 143, 156, 181, 255, 68, 88, 114, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 255, 255, 255, 255, 215, 221, 231, 255, 143, 156, 181, 255, 65, 85, 112, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 255, 255, 255, 255, 216, 220, 231, 255, 143, 156, 181, 255, 65, 85, 112, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 152, 166, 185, 255, 216, 220, 231, 218, 143, 156, 181, 255, 66, 86, 113, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 43, 134, 240, 46, 43, 134, 240, 107, 152, 166, 185, 255, 255, 255, 255, 255, 69, 89, 114, 255, 51, 72, 99, 255, 43, 134, 240, 236, 43, 134, 240, 204, 43, 133, 240, 161, 43, 132, 239, 107, 43, 130, 239, 46, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 43, 133, 239, 170, 43, 133, 240, 255, 87, 105, 130, 255, 79, 97, 123, 255, 43, 134, 240, 255, 43, 134, 240, 255, 43, 135, 240, 255, 43, 134, 240, 255, 43, 134, 240, 255, 43, 134, 240, 255, 43, 133, 239, 170, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 42, 120, 237, 46, 42, 124, 238, 107, 42, 125, 238, 161, 42, 126, 238, 204, 42, 128, 238, 236, 43, 130, 239, 253, 43, 131, 239, 236, 43, 131, 239, 204, 43, 131, 239, 161, 43, 129, 239, 107, 42, 127, 238, 46, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintEllipse(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 20, 0, 0, 0, 84, 0, 0, 0, 128, 0, 0, 0, 128, 0, 0, 0, 84, 0, 0, 0, 20, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 16, 0, 0, 0, 155, 0, 0, 0, 239, 0, 0, 0, 175, 0, 0, 0, 131, 0, 0, 0, 131, 0, 0, 0, 175, 0, 0, 0, 239, 0, 0, 0, 155, 0, 0, 0, 16, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 24, 0, 0, 0, 215, 0, 0, 0, 143, 0, 0, 0, 16, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 16, 0, 0, 0, 143, 0, 0, 0, 215, 0, 0, 0, 24, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 199, 0, 0, 0, 120, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 120, 0, 0, 0, 199, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 60, 0, 0, 0, 211, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 211, 0, 0, 0, 60, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 120, 0, 0, 0, 139, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 139, 0, 0, 0, 120, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 120, 0, 0, 0, 135, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 135, 0, 0, 0, 120, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 68, 0, 0, 0, 211, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 211, 0, 0, 0, 68, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 199, 0, 0, 0, 120, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 120, 0, 0, 0, 199, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 36, 0, 0, 0, 231, 0, 0, 0, 135, 0, 0, 0, 12, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 12, 0, 0, 0, 135, 0, 0, 0, 231, 0, 0, 0, 36, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 20, 0, 0, 0, 163, 0, 0, 0, 239, 0, 0, 0, 171, 0, 0, 0, 131, 0, 0, 0, 131, 0, 0, 0, 171, 0, 0, 0, 239, 0, 0, 0, 163, 0, 0, 0, 20, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 24, 0, 0, 0, 88, 0, 0, 0, 128, 0, 0, 0, 128, 0, 0, 0, 88, 0, 0, 0, 24, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintRect(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 254, 0, 0, 0, 247, 0, 0, 0, 239, 0, 0, 0, 247, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintOval(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 24, 0, 0, 0, 135, 0, 0, 0, 211, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 211, 0, 0, 0, 135, 0, 0, 0, 24, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 80, 0, 0, 0, 239, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 239, 0, 0, 0, 80, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 48, 0, 0, 0, 251, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 251, 0, 0, 0, 48, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 183, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 183, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 247, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 247, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 247, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 247, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 183, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 183, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 56, 0, 0, 0, 251, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 251, 0, 0, 0, 56, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 84, 0, 0, 0, 243, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 243, 0, 0, 0, 84, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 24, 0, 0, 0, 139, 0, 0, 0, 211, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 211, 0, 0, 0, 139, 0, 0, 0, 24, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintBox(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 254, 0, 0, 0, 247, 0, 0, 0, 239, 0, 0, 0, 247, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintZoomGrid(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 110, 155, 223, 255, 255, 255, 255, 0, 255, 255, 255, 0, 106, 151, 219, 255, 255, 255, 255, 0, 255, 255, 255, 0, 95, 142, 210, 255, 255, 255, 255, 0, 255, 255, 255, 0, 84, 129, 201, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 110, 155, 223, 255, 255, 255, 255, 0, 255, 255, 255, 0, 102, 147, 217, 255, 255, 255, 255, 0, 255, 255, 255, 0, 92, 137, 207, 255, 255, 255, 255, 0, 255, 255, 255, 0, 80, 125, 197, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 110, 155, 223, 255, 110, 155, 223, 255, 107, 152, 222, 255, 104, 151, 219, 255, 103, 148, 216, 255, 100, 145, 213, 255, 97, 142, 210, 255, 93, 138, 206, 255, 88, 133, 203, 255, 84, 129, 201, 255, 80, 125, 197, 255, 76, 121, 193, 255, 72, 117, 189, 255, 68, 113, 183, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 106, 149, 219, 255, 255, 255, 255, 0, 255, 255, 255, 0, 97, 142, 210, 255, 255, 255, 255, 0, 255, 255, 255, 0, 84, 131, 199, 255, 255, 255, 255, 0, 255, 255, 255, 0, 72, 117, 187, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 103, 148, 216, 255, 255, 255, 255, 0, 255, 255, 255, 0, 92, 137, 207, 255, 255, 255, 255, 0, 255, 255, 255, 0, 81, 125, 196, 255, 255, 255, 255, 0, 255, 255, 255, 0, 68, 113, 185, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 104, 151, 219, 255, 104, 148, 216, 255, 100, 145, 213, 255, 97, 142, 210, 255, 92, 137, 207, 255, 88, 135, 203, 255, 84, 129, 199, 255, 80, 125, 195, 255, 76, 121, 193, 255, 70, 117, 189, 255, 68, 112, 183, 255, 62, 109, 181, 255, 60, 105, 177, 255, 57, 102, 174, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 97, 142, 210, 255, 255, 255, 255, 0, 255, 255, 255, 0, 84, 129, 199, 255, 255, 255, 255, 0, 255, 255, 255, 0, 72, 117, 187, 255, 255, 255, 255, 0, 255, 255, 255, 0, 60, 105, 177, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 93, 138, 206, 255, 255, 255, 255, 0, 255, 255, 255, 0, 80, 125, 195, 255, 255, 255, 255, 0, 255, 255, 255, 0, 66, 113, 185, 255, 255, 255, 255, 0, 255, 255, 255, 0, 56, 103, 173, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 95, 140, 212, 255, 92, 137, 207, 255, 88, 133, 203, 255, 84, 129, 199, 255, 80, 125, 195, 255, 76, 121, 193, 255, 72, 117, 187, 255, 68, 113, 185, 255, 64, 107, 181, 255, 59, 105, 178, 255, 55, 101, 174, 255, 53, 98, 170, 255, 49, 95, 168, 255, 48, 91, 165, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 84, 131, 199, 255, 255, 255, 255, 0, 255, 255, 255, 0, 70, 117, 189, 255, 255, 255, 255, 0, 255, 255, 255, 0, 60, 105, 177, 255, 255, 255, 255, 0, 255, 255, 255, 0, 49, 95, 168, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 82, 125, 195, 255, 255, 255, 255, 0, 255, 255, 255, 0, 68, 113, 185, 255, 255, 255, 255, 0, 255, 255, 255, 0, 57, 102, 174, 255, 255, 255, 255, 0, 255, 255, 255, 0, 46, 92, 165, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 84, 129, 199, 255, 80, 125, 195, 255, 76, 121, 191, 255, 72, 117, 189, 255, 66, 113, 185, 255, 64, 109, 181, 255, 60, 105, 177, 255, 55, 102, 174, 255, 52, 98, 171, 255, 49, 95, 168, 255, 46, 91, 166, 255, 44, 90, 163, 255, 42, 88, 161, 255, 42, 88, 161, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 72, 117, 187, 255, 255, 255, 255, 0, 255, 255, 255, 0, 60, 107, 177, 255, 255, 255, 255, 0, 255, 255, 255, 0, 50, 95, 167, 255, 255, 255, 255, 0, 255, 255, 255, 0, 42, 88, 161, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 68, 113, 185, 255, 255, 255, 255, 0, 255, 255, 255, 0, 56, 101, 173, 255, 255, 255, 255, 0, 255, 255, 255, 0, 46, 92, 165, 255, 255, 255, 255, 0, 255, 255, 255, 0, 42, 88, 161, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintFill(void) { unsigned char imgdata[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 53, 53, 86, 59, 59, 59, 111, 108, 108, 108, 82, 127, 127, 127, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 54, 54, 122, 72, 72, 72, 7, 119, 122, 124, 117, 124, 124, 130, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 77, 76, 154, 144, 166, 188, 23, 158, 169, 181, 191, 144, 151, 159, 194, 134, 147, 174, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 126, 129, 197, 141, 160, 183, 179, 212, 219, 225, 254, 157, 162, 166, 254, 163, 180, 200, 168, 159, 175, 191, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, 141, 158, 45, 130, 143, 155, 245, 218, 225, 232, 250, 222, 232, 239, 255, 136, 139, 142, 255, 205, 217, 227, 252, 148, 167, 189, 163, 155, 155, 184, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 148, 170, 24, 134, 155, 174, 172, 213, 220, 227, 254, 218, 233, 243, 255, 197, 207, 217, 255, 149, 149, 150, 255, 232, 241, 245, 255, 179, 196, 213, 252, 129, 147, 172, 164, 75, 103, 144, 37, 17, 51, 102, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 134, 147, 174, 19, 122, 146, 168, 179, 216, 223, 228, 252, 217, 231, 242, 255, 213, 227, 238, 255, 159, 162, 164, 255, 128, 129, 128, 255, 228, 235, 239, 255, 171, 197, 218, 255, 136, 162, 190, 253, 87, 116, 156, 227, 37, 75, 150, 183, 0, 31, 107, 57, 0, 0, 0, 0, 0, 0, 0, 0, 120, 134, 161, 19, 126, 147, 168, 157, 209, 217, 225, 245, 217, 231, 241, 255, 203, 217, 232, 255, 242, 244, 245, 255, 192, 192, 191, 255, 164, 166, 169, 255, 202, 213, 223, 255, 158, 176, 194, 255, 126, 154, 184, 255, 103, 134, 168, 255, 76, 110, 169, 255, 49, 93, 175, 201, 37, 66, 132, 27, 122, 132, 160, 27, 102, 124, 149, 172, 194, 209, 220, 241, 213, 228, 239, 246, 204, 218, 232, 249, 241, 242, 244, 255, 247, 245, 245, 255, 243, 244, 243, 255, 222, 228, 234, 255, 192, 203, 214, 255, 159, 172, 185, 255, 138, 152, 168, 255, 84, 116, 151, 248, 74, 104, 158, 246, 83, 129, 213, 243, 77, 108, 169, 92, 125, 134, 152, 55, 111, 131, 154, 211, 189, 201, 214, 255, 214, 223, 234, 254, 238, 240, 243, 236, 248, 246, 245, 241, 242, 243, 243, 254, 221, 228, 234, 255, 192, 203, 214, 255, 165, 178, 192, 255, 142, 155, 169, 255, 98, 117, 137, 243, 77, 94, 120, 121, 46, 82, 158, 171, 87, 131, 209, 247, 85, 114, 171, 122, 0, 255, 255, 1, 134, 140, 167, 38, 137, 155, 179, 206, 218, 223, 230, 254, 244, 242, 243, 252, 242, 244, 243, 239, 220, 228, 234, 252, 192, 202, 214, 255, 164, 176, 190, 255, 140, 154, 168, 255, 92, 112, 132, 243, 75, 91, 114, 111, 102, 102, 153, 5, 29, 61, 136, 140, 68, 109, 192, 244, 84, 113, 170, 94, 0, 0, 0, 0, 0, 0, 255, 1, 157, 173, 195, 47, 148, 166, 191, 205, 204, 210, 220, 248, 227, 231, 235, 253, 193, 204, 216, 255, 163, 175, 189, 255, 138, 151, 166, 255, 95, 113, 134, 242, 74, 88, 113, 110, 95, 127, 127, 8, 0, 0, 0, 0, 35, 66, 135, 145, 72, 109, 182, 239, 91, 120, 178, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 142, 165, 34, 103, 124, 151, 197, 158, 172, 187, 252, 164, 176, 189, 255, 134, 148, 162, 254, 96, 113, 133, 245, 75, 87, 110, 122, 102, 102, 102, 5, 0, 0, 0, 0, 0, 0, 0, 0, 60, 91, 151, 173, 84, 115, 173, 195, 98, 117, 176, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 102, 110, 119, 30, 73, 96, 120, 204, 107, 126, 144, 255, 106, 123, 141, 255, 102, 115, 135, 152, 139, 150, 162, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 92, 154, 173, 85, 115, 173, 119, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 82, 115, 31, 49, 79, 109, 212, 92, 110, 134, 169, 143, 159, 175, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 93, 154, 163, 63, 89, 153, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 118, 140, 58, 85, 106, 148, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 92, 154, 33, 0, 0, 0, 0, 0, 0, 0, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } Ihandle* load_image_PaintText(void) { unsigned char imgdata[] = { 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 36, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 96, 0, 0, 0, 72, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 96, 0, 0, 0, 255, 0, 0, 0, 203, 0, 0, 0, 124, 0, 0, 0, 135, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 215, 0, 0, 0, 96, 0, 0, 0, 131, 0, 0, 0, 243, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 96, 0, 0, 0, 163, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 44, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 96, 0, 0, 0, 48, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 116, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 64, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 191, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 96, 0, 0, 0, 187, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 243, 0, 0, 0, 116, 0, 0, 0, 48, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0 }; Ihandle* image = IupImageRGBA(16, 16, imgdata); return image; } /********************************** Utilities *****************************************/ char* str_duplicate(const char* str) { if (!str) return NULL; int size = (int)strlen(str); char* new_str = new char[size+1]; memcpy(new_str, str, size + 1); return new_str; } const char* str_filetitle(const char *filename) { /* Start at the last character */ int len = (int)strlen(filename); int offset = len - 1; while (offset != 0) { if (filename[offset] == '\\' || filename[offset] == '/') { offset++; break; } offset--; } return filename + offset; } const char* str_fileext(const char *filename) { /* Start at the last character */ int len = (int)strlen(filename); int offset = len - 1; while (offset != 0) { if (filename[offset] == '\\' || filename[offset] == '/') break; if (filename[offset] == '.') { offset++; return filename + offset; } offset--; } return NULL; } int str_compare(const char *l, const char *r, int casesensitive) { if (!l || !r) return 0; while (*l && *r) { int diff; char l_char = *l, r_char = *r; /* compute the difference of both characters */ if (casesensitive) diff = l_char - r_char; else diff = tolower((int)l_char) - tolower((int)r_char); /* if they differ we have a result */ if (diff != 0) return 0; /* otherwise process the next characters */ ++l; ++r; } /* check also for terminator */ if (*l == *r) return 1; if (*r == 0) return 1; /* if second string is at terminator, then it is partially equal */ return 0; } void show_error(const char* message, int is_error) { Ihandle* dlg = IupMessageDlg(); IupSetStrAttribute(dlg, "PARENTDIALOG", IupGetGlobal("PARENTDIALOG")); IupSetAttribute(dlg, "DIALOGTYPE", is_error ? "ERROR" : "WARNING"); IupSetAttribute(dlg, "BUTTONS", "OK"); IupSetStrAttribute(dlg, "TITLE", is_error ? "Error" : "Warning"); IupSetStrAttribute(dlg, "VALUE", message); IupPopup(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT); IupDestroy(dlg); } void show_file_error(int error) { switch (error) { case IM_ERR_OPEN: show_error("Error Opening File.", 1); break; case IM_ERR_MEM: show_error("Insufficient memory.", 1); break; case IM_ERR_ACCESS: show_error("Error Accessing File.", 1); break; case IM_ERR_DATA: show_error("Image type not Supported.", 1); break; case IM_ERR_FORMAT: show_error("Invalid Format.", 1); break; case IM_ERR_COMPRESS: show_error("Invalid or unsupported compression.", 1); break; default: show_error("Unknown Error.", 1); } } /* extracted from the SCROLLBAR attribute documentation */ void scroll_update(Ihandle* ih, int view_width, int view_height) { /* view_width and view_height is the virtual space size */ /* here we assume XMIN=0, XMAX=1, YMIN=0, YMAX=1 */ int elem_width, elem_height; int canvas_width, canvas_height; int scrollbar_size = IupGetInt(NULL, "SCROLLBARSIZE"); int border = IupGetInt(ih, "BORDER"); IupGetIntInt(ih, "RASTERSIZE", &elem_width, &elem_height); /* if view is greater than canvas in one direction, then it has scrollbars, but this affects the opposite direction */ elem_width -= 2 * border; /* remove BORDER (always size=1) */ elem_height -= 2 * border; canvas_width = elem_width; canvas_height = elem_height; if (view_width > elem_width) /* check for horizontal scrollbar */ canvas_height -= scrollbar_size; /* affect vertical size */ if (view_height > elem_height) canvas_width -= scrollbar_size; if (view_width <= elem_width && view_width > canvas_width) /* check if still has horizontal scrollbar */ canvas_height -= scrollbar_size; if (view_height <= elem_height && view_height > canvas_height) canvas_width -= scrollbar_size; if (canvas_width < 0) canvas_width = 0; if (canvas_height < 0) canvas_height = 0; IupSetFloat(ih, "DX", (float)canvas_width / (float)view_width); IupSetFloat(ih, "DY", (float)canvas_height / (float)view_height); } void scroll_calc_center(Ihandle* ih, float *x, float *y) { *x = IupGetFloat(ih, "POSX") + IupGetFloat(ih, "DX") / 2.0f; *y = IupGetFloat(ih, "POSY") + IupGetFloat(ih, "DY") / 2.0f; } void scroll_center(Ihandle* ih, float old_center_x, float old_center_y) { /* always update the scroll position keeping it proportional to the old position relative to the center of the ih. */ float dx = IupGetFloat(ih, "DX"); float dy = IupGetFloat(ih, "DY"); float posx = old_center_x - dx / 2.0f; float posy = old_center_y - dy / 2.0f; if (posx < 0) posx = 0; if (posx > 1 - dx) posx = 1 - dx; if (posy < 0) posy = 0; if (posy > 1 - dy) posy = 1 - dy; IupSetFloat(ih, "POSX", posx); IupSetFloat(ih, "POSY", posy); } void scroll_move(Ihandle* ih, int canvas_width, int canvas_height, int move_x, int move_y, int view_width, int view_height) { float posy = 0; float posx = 0; if (move_x == 0 && move_y == 0) return; if (canvas_height < view_height) { posy = IupGetFloat(ih, "POSY"); posy -= (float)move_y / (float)view_height; } if (canvas_width < view_width) { posx = IupGetFloat(ih, "POSX"); posx -= (float)move_x / (float)view_width; } if (posx != 0 || posy != 0) { IupSetFloat(ih, "POSX", posx); IupSetFloat(ih, "POSY", posy); IupUpdate(ih); } } void image_flood_fill(imImage* image, int start_x, int start_y, long replace_color, double tol_percent) { #if IM_VERSION_NUMBER > 312000 double color[3]; double tol; #else float color[3]; float tol; #endif color[0] = cdRed(replace_color); color[1] = cdGreen(replace_color); color[2] = cdBlue(replace_color); /* max value = 255*255*3 = 195075 */ /* sqrt(195075) = 441 */ tol = (441 * tol_percent) / 100; /* still too high */ tol = tol / 5; /* empirical reduce. TODO: What is the best formula? */ imProcessRenderFloodFill(image, start_x, start_y, color, tol); } void image_fill_white(imImage* image) { float color[3]; color[0] = 255; color[1] = 255; color[2] = 255; imProcessRenderConstant(image, color); } void view_fit_rect(int canvas_width, int canvas_height, int image_width, int image_height, int *view_width, int *view_height) { *view_width = canvas_width; *view_height = (canvas_width * image_height) / image_width; if (*view_height > canvas_height) { *view_height = canvas_height; *view_width = (canvas_height * image_width) / image_height; } } void view_zoom_offset(int view_x, int view_y, int image_width, int image_height, double zoom_factor, int *x, int *y) { *x -= view_x; *y -= view_y; *x = (int)(*x / zoom_factor); *y = (int)(*y / zoom_factor); if (*x < 0) *x = 0; if (*y < 0) *y = 0; if (*x > image_width - 1) *x = image_width - 1; if (*y > image_height - 1) *y = image_height - 1; } /*********************************** Classes **************************************/ class SimplePaintFile { char* filename; imImage* image; public: bool dirty; /* leave it public */ SimplePaintFile() :filename(NULL), image(NULL), dirty(false) { } void SetFilename(const char* new_filename); const char* GetFilename() const { return filename; } void SetImage(imImage* new_image, bool release = true); const imImage* GetImage() const { return image; } imImage* Read(const char* new_filename) const; bool Write(const char* new_filename) const; void SetFormat(const char* new_filename); bool New(int width, int height); void New(imImage* new_image); bool Open(const char* new_filename); bool SaveAsFile(const char* new_filename); bool SaveCheck(); void SaveFile(); void Close(); }; class SimplePaintToolbox { public: enum Tool { TOOL_POINTER, TOOL_COLORPICKER, TOOL_PENCIL, TOOL_LINE, TOOL_RECT, TOOL_BOX, TOOL_ELLIPSE, TOOL_OVAL, TOOL_TEXT, TOOL_FILLCOLOR }; private: Ihandle *toolbox, *config, *paint_canvas; Tool tool_index; struct { long color; int line_width; int line_style; double fill_tol; } options; public: SimplePaintToolbox() :toolbox(NULL), config(NULL), paint_canvas(NULL), tool_index(TOOL_POINTER) { options.color = CD_BLACK; options.line_width = 1; options.line_style = 0; options.fill_tol = 50; } Tool ToolIndex() const { return tool_index; } long Color() const { return options.color; } int LineWidth() const { return options.line_width; } int LineStyle() const { return options.line_style; } double FillTol() const { return options.fill_tol; } const char* Font() const { return IupGetAttribute(toolbox, "TOOLFONT"); } const char* Text() const { return IupGetAttribute(toolbox, "TOOLTEXT"); } void SetColor(long new_color); void MoveDialog(int dx, int dy); bool HideDialog(); void ShowDialog(); void CreateDialog(Ihandle* canvas, Ihandle* config); void ToolGetText(); protected: IUP_CLASS_DECLARECALLBACK_IFn(SimplePaintToolbox, CloseCallback); IUP_CLASS_DECLARECALLBACK_IFni(SimplePaintToolbox, ToolActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaintToolbox, ToolColorActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaintToolbox, ToolWidthValueChangedCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaintToolbox, ToolStyleValueChangedCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaintToolbox, ToolFontActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaintToolbox, ToolFillTolValueChangedCallback); }; class SimplePaint { Ihandle *dlg, *config, *canvas; cdCanvas* cd_canvas; SimplePaintFile file; SimplePaintToolbox toolbox; struct { bool overlay; int start_x, start_y; int end_x, end_y; int start_cursor_x, start_cursor_y; } interact; public: SimplePaint(); void CheckNewFile(); void OpenFile(const char* filename); protected: void CreateMainDialog(); Ihandle* CreateStatusbar(); Ihandle* CreateToolbar(); Ihandle* CreateMainMenu(); void DrawToolOverlay(cdCanvas* cnv, int start_x, int start_y, int end_x, int end_y); void DrawPencil(int start_x, int start_y, int end_x, int end_y); void SelectFile(bool is_open); void UpdateFile(); void UpdateImage(imImage* new_image, bool update_size = false); void UpdateZoom(double zoom_index); void ToggleBarVisibility(Ihandle* item, Ihandle* bar); double ViewZoomRect(int *_x, int *_y, int *_view_width, int *_view_height); IUP_CLASS_DECLARECALLBACK_IFnii(SimplePaint, DialogMoveCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ConfigRecentCallback); IUP_CLASS_DECLARECALLBACK_IFns(SimplePaint, DropfilesCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemNewActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemOpenActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemSaveActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemSaveasActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemRevertActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemPagesetupActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemPrintActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemExitActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemCopyActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemPasteActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemZoominActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemZoomoutActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemActualsizeActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemZoomgridActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemBackgroundActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemToolbarActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemToolboxActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemHelpActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemAboutActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemStatusbarActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemResizeActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemMirrorActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemFlipActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemRotate180ActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemRotate90cwActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemRotate90ccwActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemNegativeActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ItemBrightcontActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, FileMenuOpenCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, EditMenuOpenCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, CanvasActionCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, CanvasMapCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, CanvasUnmapCallback); IUP_CLASS_DECLARECALLBACK_IFnfiis(SimplePaint, CanvasWheelCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, CanvasResizeCallback); IUP_CLASS_DECLARECALLBACK_IFniis(SimplePaint, CanvasMotionCallback); IUP_CLASS_DECLARECALLBACK_IFniiii(SimplePaint, CanvasButtonCallback); IUP_CLASS_DECLARECALLBACK_IFn(SimplePaint, ZoomValueChangedCallback); }; /*********************************** SimplePaintFile Utilities Methods **************************************/ void SimplePaintFile::Close() { if (filename) delete[] filename; if (image) imImageDestroy(image); } void SimplePaintFile::SetFilename(const char* new_filename) { if (filename != new_filename) { if (filename) delete[] filename; filename = str_duplicate(new_filename); } } imImage* SimplePaintFile::Read(const char* new_filename) const { int error; imImage* image = imFileImageLoadBitmap(new_filename, 0, &error); if (error) show_file_error(error); return image; } bool SimplePaintFile::Write(const char* new_filename) const { const char* format = imImageGetAttribString(image, "FileFormat"); int error = imFileImageSave(new_filename, format, image); if (error) { show_file_error(error); return false; } return true; } void SimplePaintFile::SetFormat(const char* new_filename) { const char* ext = str_fileext(new_filename); const char* format = "JPEG"; if (str_compare(ext, "jpg", 0) || str_compare(ext, "jpeg", 0)) format = "JPEG"; else if (str_compare(ext, "bmp", 0)) format = "BMP"; else if (str_compare(ext, "png", 0)) format = "PNG"; else if (str_compare(ext, "tga", 0)) format = "TGA"; else if (str_compare(ext, "tif", 0) || str_compare(ext, "tiff", 0)) format = "TIFF"; imImageSetAttribString(image, "FileFormat", format); } bool SimplePaintFile::SaveCheck() { if (dirty) { switch (IupAlarm("Warning", "File not saved! Save it now?", "Yes", "No", "Cancel")) { case 1: /* save the changes and continue */ SaveFile(); break; case 2: /* ignore the changes and continue */ break; case 3: /* cancel */ return false; } } return true; } void SimplePaintFile::SaveFile() { if (Write(filename)) dirty = false; } bool SimplePaintFile::SaveAsFile(const char* new_filename) { SetFormat(new_filename); if (Write(new_filename)) { SetFilename(new_filename); dirty = false; return true; } return false; } bool SimplePaintFile::New(int width, int height) { imImage* new_image = imImageCreate(width, height, IM_RGB, IM_BYTE); if (!new_image) { show_file_error(IM_ERR_MEM); return false; } /* new image default contents */ image_fill_white(new_image); /* default file format */ imImageSetAttribString(new_image, "FileFormat", "JPEG"); SetImage(new_image); /* set properties */ SetFilename(NULL); dirty = false; return true; } void SimplePaintFile::SetImage(imImage* new_image, bool release) { /* remove previous one if any */ if (release && image) imImageDestroy(image); /* set properties (leave filename as it is) */ dirty = true; image = new_image; } void SimplePaintFile::New(imImage* new_image) { /* this tests are necessary only for open and paste */ /* we are going to support only RGB images with no alpha */ imImageRemoveAlpha(new_image); if (new_image->color_space != IM_RGB) { imImage* rgb_image = imImageCreateBased(new_image, -1, -1, IM_RGB, -1); imConvertColorSpace(new_image, rgb_image); imImageDestroy(new_image); new_image = rgb_image; } /* default file format */ const char* format = imImageGetAttribString(new_image, "FileFormat"); if (!format) imImageSetAttribString(new_image, "FileFormat", "JPEG"); SetImage(new_image); } bool SimplePaintFile::Open(const char* new_filename) { imImage* new_image = Read(new_filename); if (new_image) { New(new_image); /* set properties */ dirty = false; SetFilename(new_filename); return true; } return false; } /*********************************** SimplePaint Utilities Methods **************************************/ void SimplePaint::UpdateZoom(double zoom_index) { Ihandle* zoom_lbl = IupGetDialogChild(dlg, "ZOOMLABEL"); double zoom_factor = pow(2, zoom_index); IupSetStrf(zoom_lbl, "TITLE", "%.0f%%", floor(zoom_factor * 100)); if (file.GetImage()) { float old_center_x, old_center_y; int view_width = (int)(zoom_factor * file.GetImage()->width); int view_height = (int)(zoom_factor * file.GetImage()->height); scroll_calc_center(canvas, &old_center_x, &old_center_y); scroll_update(canvas, view_width, view_height); scroll_center(canvas, old_center_x, old_center_y); } IupUpdate(canvas); } void SimplePaint::UpdateImage(imImage* new_image, bool update_size) { file.SetImage(new_image); if (update_size) { Ihandle* size_lbl = IupGetDialogChild(dlg, "SIZELABEL"); Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); double zoom_index = IupGetDouble(zoom_val, "VALUE"); IupSetfAttribute(size_lbl, "TITLE", "%d x %d px", file.GetImage()->width, file.GetImage()->height); UpdateZoom(zoom_index); } else IupUpdate(canvas); } void SimplePaint::UpdateFile() { Ihandle* size_lbl = IupGetDialogChild(dlg, "SIZELABEL"); Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); if (file.GetFilename()) IupSetfAttribute(dlg, "TITLE", "%s - Simple Paint", str_filetitle(file.GetFilename())); else IupSetAttribute(dlg, "TITLE", "Untitled - Simple Paint"); IupSetfAttribute(size_lbl, "TITLE", "%d x %d px", file.GetImage()->width, file.GetImage()->height); IupSetDouble(zoom_val, "VALUE", 0); UpdateZoom(0); } void SimplePaint::CheckNewFile() { if (!file.GetImage()) { int width = IupConfigGetVariableIntDef(config, "NewImage", "Width", 640); int height = IupConfigGetVariableIntDef(config, "NewImage", "Height", 480); if (file.New(width, height)) UpdateFile(); } } void SimplePaint::OpenFile(const char* filename) { if (file.Open(filename)) { UpdateFile(); IupConfigRecentUpdate(config, filename); } } void SimplePaint::ToggleBarVisibility(Ihandle* item, Ihandle* bar) { if (IupGetInt(item, "VALUE")) { IupSetAttribute(bar, "FLOATING", "YES"); IupSetAttribute(bar, "VISIBLE", "NO"); IupSetAttribute(item, "VALUE", "OFF"); } else { IupSetAttribute(bar, "FLOATING", "NO"); IupSetAttribute(bar, "VISIBLE", "YES"); IupSetAttribute(item, "VALUE", "ON"); } IupRefresh(bar); /* refresh the dialog layout */ } void SimplePaint::SelectFile(bool is_open) { const char* dir = IupConfigGetVariableStr(config, "MainWindow", "LastDirectory"); Ihandle* filedlg = IupFileDlg(); if (is_open) IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN"); else { IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE"); IupSetStrAttribute(filedlg, "FILE", file.GetFilename()); } IupSetAttribute(filedlg, "EXTFILTER", "Image Files|*.bmp;*.jpg;*.png;*.tif;*.tga|All Files|*.*|"); IupSetStrAttribute(filedlg, "DIRECTORY", dir); IupSetAttributeHandle(filedlg, "PARENTDIALOG", dlg); IupPopup(filedlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(filedlg, "STATUS") != -1) { char* filename = IupGetAttribute(filedlg, "VALUE"); if (is_open) OpenFile(filename); else { if (file.SaveAsFile(filename)) { IupSetfAttribute(dlg, "TITLE", "%s - Simple Paint", str_filetitle(filename)); IupConfigRecentUpdate(config, filename); } } dir = IupGetAttribute(filedlg, "DIRECTORY"); IupConfigSetVariableStr(config, "MainWindow", "LastDirectory", dir); } IupDestroy(filedlg); } double SimplePaint::ViewZoomRect(int *_x, int *_y, int *_view_width, int *_view_height) { int x, y, canvas_width, canvas_height; int view_width, view_height; Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); double zoom_index = IupGetDouble(zoom_val, "VALUE"); double zoom_factor = pow(2, zoom_index); float posy = IupGetFloat(canvas, "POSY"); float posx = IupGetFloat(canvas, "POSX"); IupGetIntInt(canvas, "DRAWSIZE", &canvas_width, &canvas_height); view_width = (int)(zoom_factor * file.GetImage()->width); view_height = (int)(zoom_factor * file.GetImage()->height); if (canvas_width < view_width) x = (int)floor(-posx*view_width); else x = (canvas_width - view_width) / 2; if (canvas_height < view_height) { /* posy is top-bottom, CD is bottom-top. invert posy reference (YMAX-DY - POSY) */ float dy = IupGetFloat(canvas, "DY"); posy = 1.0f - dy - posy; y = (int)floor(-posy*view_height); } else y = (canvas_height - view_height) / 2; *_x = x; *_y = y; *_view_width = view_width; *_view_height = view_height; return zoom_factor; } void SimplePaint::DrawPencil(int start_x, int start_y, int end_x, int end_y) { double res = IupGetDouble(NULL, "SCREENDPI") / 25.4; int line_width = toolbox.LineWidth(); long color = toolbox.Color(); /* do not use line style here */ cdCanvas* rgb_canvas = cdCreateCanvas(CD_IMIMAGE, (imImage*)file.GetImage()); cdCanvasSetfAttribute(rgb_canvas, "RESOLUTION", "%g", res); cdCanvasForeground(rgb_canvas, color); cdCanvasLineWidth(rgb_canvas, line_width); cdCanvasLine(rgb_canvas, start_x, start_y, end_x, end_y); cdKillCanvas(rgb_canvas); } void SimplePaint::DrawToolOverlay(cdCanvas* cnv, int start_x, int start_y, int end_x, int end_y) { SimplePaintToolbox::Tool tool_index = toolbox.ToolIndex(); int line_width = toolbox.LineWidth(); int line_style = toolbox.LineStyle(); long color = toolbox.Color(); cdCanvasForeground(cnv, color); cdCanvasLineWidth(cnv, line_width); if (line_width == 1) cdCanvasLineStyle(cnv, line_style); if (tool_index == SimplePaintToolbox::TOOL_LINE) cdCanvasLine(cnv, start_x, start_y, end_x, end_y); else if (tool_index == SimplePaintToolbox::TOOL_RECT) cdCanvasRect(cnv, start_x, end_x, start_y, end_y); else if (tool_index == SimplePaintToolbox::TOOL_BOX) cdCanvasBox(cnv, start_x, end_x, start_y, end_y); else if (tool_index == SimplePaintToolbox::TOOL_ELLIPSE) cdCanvasArc(cnv, (end_x + start_x) / 2, (end_y + start_y) / 2, abs(end_x - start_x), abs(end_y - start_y), 0, 360); else if (tool_index == SimplePaintToolbox::TOOL_OVAL) cdCanvasSector(cnv, (end_x + start_x) / 2, (end_y + start_y) / 2, abs(end_x - start_x), abs(end_y - start_y), 0, 360); else if (tool_index == SimplePaintToolbox::TOOL_TEXT) { cdCanvasTextAlignment(cnv, CD_SOUTH_WEST); cdCanvasNativeFont(cnv, toolbox.Font()); cdCanvasText(cnv, end_x, end_y, toolbox.Text()); } } /********************************** Callbacks Methods *****************************************/ int SimplePaint::CanvasActionCallback(Ihandle*) { unsigned int ri, gi, bi; const char* background = IupConfigGetVariableStrDef(config, "Canvas", "Background", "208 208 208"); #ifdef USE_OPENGL IupGLMakeCurrent(canvas); #endif cdCanvasActivate(cd_canvas); /* draw the background */ sscanf(background, "%u %u %u", &ri, &gi, &bi); cdCanvasBackground(cd_canvas, cdEncodeColor((unsigned char)ri, (unsigned char)gi, (unsigned char)bi)); cdCanvasClear(cd_canvas); /* draw the image at the center of the canvas */ if (file.GetImage()) { int x, y, view_width, view_height; ViewZoomRect(&x, &y, &view_width, &view_height); /* black line around the image */ cdCanvasForeground(cd_canvas, CD_BLACK); cdCanvasLineWidth(cd_canvas, 1); cdCanvasLineStyle(cd_canvas, CD_CONTINUOUS); cdCanvasRect(cd_canvas, x - 1, x + view_width, y - 1, y + view_height); /* Some CD drivers have interpolation options for image zoom */ /* we force NEAREST so we can see the pixel boundary in zoom in */ /* an alternative would be to set BILINEAR when zoom out */ cdCanvasSetAttribute(cd_canvas, "IMGINTERP", (char*)"NEAREST"); /* affects only drivers that have this attribute */ cdCanvasPutImImage(cd_canvas, file.GetImage(), x, y, view_width, view_height); if (IupConfigGetVariableInt(config, "Canvas", "ZoomGrid")) { Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); double zoom_index = IupGetDouble(zoom_val, "VALUE"); if (zoom_index > 1) { int ix, iy; double zoom_factor = pow(2, zoom_index); cdCanvasForeground(cd_canvas, CD_GRAY); for (ix = 0; ix < file.GetImage()->width; ix++) { int gx = (int)(ix * zoom_factor); cdCanvasLine(cd_canvas, gx + x, y, gx + x, y + view_height); } for (iy = 0; iy < file.GetImage()->height; iy++) { int gy = (int)(iy * zoom_factor); cdCanvasLine(cd_canvas, x, gy + y, x + view_width, gy + y); } } } if (interact.overlay) { double scale_x = (double)view_width / (double)file.GetImage()->width; double scale_y = (double)view_height / (double)file.GetImage()->height; /* offset and scale drawing in screen to match the image */ if (scale_x > 1 || scale_y > 1) cdCanvasTransformTranslate(cd_canvas, x + scale_x / 2, y + scale_y / 2); /* also draw at the center of the pixel when zoom in */ else cdCanvasTransformTranslate(cd_canvas, x, y); cdCanvasTransformScale(cd_canvas, scale_x, scale_y); DrawToolOverlay(cd_canvas, interact.start_x, interact.start_y, interact.end_x, interact.end_y); cdCanvasTransform(cd_canvas, NULL); } } cdCanvasFlush(cd_canvas); #ifdef USE_OPENGL IupGLSwapBuffers(canvas); #endif return IUP_DEFAULT; } int SimplePaint::CanvasMapCallback(Ihandle* canvas) { #ifdef USE_OPENGL double res = IupGetDouble(NULL, "SCREENDPI") / 25.4; IupGLMakeCurrent(canvas); cd_canvas = cdCreateCanvasf(CD_GL, "10x10 %g", res); #else #ifdef USE_CONTEXTPLUS cdUseContextPlus(1); #endif cd_canvas = cdCreateCanvas(CD_IUPDBUFFER, canvas); #ifdef USE_CONTEXTPLUS cdUseContextPlus(0); #endif #endif return IUP_DEFAULT; } int SimplePaint::CanvasUnmapCallback(Ihandle*) { cdKillCanvas(cd_canvas); return IUP_DEFAULT; } int SimplePaint::CanvasResizeCallback(Ihandle* canvas) { if (file.GetImage()) { Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); double zoom_index = IupGetDouble(zoom_val, "VALUE"); double zoom_factor = pow(2, zoom_index); float old_center_x, old_center_y; int view_width = (int)(zoom_factor * file.GetImage()->width); int view_height = (int)(zoom_factor * file.GetImage()->height); scroll_calc_center(canvas, &old_center_x, &old_center_y); scroll_update(canvas, view_width, view_height); scroll_center(canvas, old_center_x, old_center_y); } #ifdef USE_OPENGL { int canvas_width, canvas_height; double res = IupGetDouble(NULL, "SCREENDPI") / 25.4; IupGetIntInt(canvas, "DRAWSIZE", &canvas_width, &canvas_height); IupGLMakeCurrent(canvas); cdCanvasSetfAttribute(cd_canvas, "SIZE", "%dx%d %g", canvas_width, canvas_height, res); } #endif return IUP_DEFAULT; } int SimplePaint::CanvasWheelCallback(Ihandle* canvas, float delta, int, int, char*) { if (IupGetInt(NULL, "CONTROLKEY")) { if (delta < 0) ItemZoomoutActionCallback(canvas); else ItemZoominActionCallback(canvas); } else { float posy = IupGetFloat(canvas, "POSY"); posy -= delta * IupGetFloat(canvas, "DY") / 10.0f; IupSetFloat(canvas, "POSY", posy); IupUpdate(canvas); } return IUP_DEFAULT; } int SimplePaint::CanvasButtonCallback(Ihandle* canvas, int button, int pressed, int x, int y) { if (file.GetImage()) { int cursor_x = x, cursor_y = y; int view_x, view_y, view_width, view_height; double zoom_factor = ViewZoomRect(&view_x, &view_y, &view_width, &view_height); /* y is top-down in IUP */ int canvas_height = IupGetInt2(canvas, "DRAWSIZE"); y = canvas_height - y - 1; /* inside image area */ if (x > view_x && y > view_y && x < view_x + view_width && y < view_y + view_height) { view_zoom_offset(view_x, view_y, file.GetImage()->width, file.GetImage()->height, zoom_factor, &x, &y); if (button == IUP_BUTTON1) { if (pressed) { interact.start_x = x; interact.start_y = y; interact.start_cursor_x = cursor_x; interact.start_cursor_y = cursor_y; } else { SimplePaintToolbox::Tool tool_index = toolbox.ToolIndex(); if (tool_index == SimplePaintToolbox::TOOL_COLORPICKER) { unsigned char** data = (unsigned char**)file.GetImage()->data; unsigned char r, g, b; int offset; offset = y * file.GetImage()->width + x; r = data[0][offset]; g = data[1][offset]; b = data[2][offset]; toolbox.SetColor(cdEncodeColor(r, g, b)); } else if (tool_index == SimplePaintToolbox::TOOL_PENCIL) { DrawPencil(interact.start_x, interact.start_y, x, y); file.dirty = true; IupUpdate(canvas); interact.start_x = x; interact.start_y = y; } else if (tool_index >= SimplePaintToolbox::TOOL_LINE && tool_index <= SimplePaintToolbox::TOOL_TEXT) /* All Shapes */ { if (interact.overlay) { double res = IupGetDouble(NULL, "SCREENDPI") / 25.4; cdCanvas* rgb_canvas = cdCreateCanvas(CD_IMIMAGE, (imImage*)file.GetImage()); cdCanvasSetfAttribute(rgb_canvas, "RESOLUTION", "%g", res); DrawToolOverlay(rgb_canvas, interact.start_x, interact.start_y, x, y); cdKillCanvas(rgb_canvas); interact.overlay = false; file.dirty = true; IupUpdate(canvas); } } else if (tool_index == SimplePaintToolbox::TOOL_FILLCOLOR) { double tol_percent = toolbox.FillTol(); long color = toolbox.Color(); image_flood_fill((imImage*)file.GetImage(), x, y, color, tol_percent); file.dirty = true; IupUpdate(canvas); } } } else if (button == IUP_BUTTON3) { if (!pressed) { SimplePaintToolbox::Tool tool_index = toolbox.ToolIndex(); if (tool_index == SimplePaintToolbox::TOOL_TEXT) toolbox.ToolGetText(); } } } } return IUP_DEFAULT; } int SimplePaint::CanvasMotionCallback(Ihandle* canvas, int x, int y, char *status) { if (file.GetImage()) { int cursor_x = x, cursor_y = y; int view_x, view_y, view_width, view_height; double zoom_factor = ViewZoomRect(&view_x, &view_y, &view_width, &view_height); /* y is top-down in IUP */ int canvas_height = IupGetInt2(canvas, "DRAWSIZE"); y = canvas_height - y - 1; /* inside image area */ if (x > view_x && y > view_y && x < view_x + view_width && y < view_y + view_height) { Ihandle* status_lbl = IupGetDialogChild(dlg, "STATUSLABEL"); unsigned char** data = (unsigned char**)file.GetImage()->data; unsigned char r, g, b; int offset; view_zoom_offset(view_x, view_y, file.GetImage()->width, file.GetImage()->height, zoom_factor, &x, &y); offset = y * file.GetImage()->width + x; r = data[0][offset]; g = data[1][offset]; b = data[2][offset]; IupSetStrf(status_lbl, "TITLE", "(%4d, %4d) = %3d %3d %3d", x, y, (int)r, (int)g, (int)b); if (iup_isbutton1(status)) /* button1 is pressed */ { SimplePaintToolbox::Tool tool_index = toolbox.ToolIndex(); if (tool_index == SimplePaintToolbox::TOOL_POINTER) { int canvas_width = IupGetInt(canvas, "DRAWSIZE"); scroll_move(canvas, canvas_width, canvas_height, cursor_x - interact.start_cursor_x, cursor_y - interact.start_cursor_y, view_width, view_height); interact.start_cursor_x = cursor_x; interact.start_cursor_y = cursor_y; } else if (tool_index == SimplePaintToolbox::TOOL_PENCIL) { DrawPencil(interact.start_x, interact.start_y, x, y); file.dirty = true; IupUpdate(canvas); interact.start_x = x; interact.start_y = y; } else if (tool_index >= SimplePaintToolbox::TOOL_LINE && tool_index <= SimplePaintToolbox::TOOL_TEXT) /* All Shapes */ { interact.end_x = x; interact.end_y = y; interact.overlay = true; IupUpdate(canvas); } } } } return IUP_DEFAULT; } int SimplePaint::ZoomValueChangedCallback(Ihandle* val) { double zoom_index = IupGetDouble(val, "VALUE"); UpdateZoom(zoom_index); return IUP_DEFAULT; } int SimplePaint::DropfilesCallback(Ihandle*, char* filename) { if (file.SaveCheck()) OpenFile(filename); return IUP_DEFAULT; } int SimplePaint::FileMenuOpenCallback(Ihandle*) { Ihandle* item_save = IupGetDialogChild(dlg, "ITEM_SAVE"); if (file.dirty) IupSetAttribute(item_save, "ACTIVE", "YES"); else IupSetAttribute(item_save, "ACTIVE", "NO"); Ihandle* item_revert = IupGetDialogChild(dlg, "ITEM_REVERT"); if (file.dirty && file.GetFilename()) IupSetAttribute(item_revert, "ACTIVE", "YES"); else IupSetAttribute(item_revert, "ACTIVE", "NO"); return IUP_DEFAULT; } int SimplePaint::EditMenuOpenCallback(Ihandle*) { Ihandle *clipboard = IupClipboard(); Ihandle *item_paste = IupGetDialogChild(dlg, "ITEM_PASTE"); if (!IupGetInt(clipboard, "IMAGEAVAILABLE")) IupSetAttribute(item_paste, "ACTIVE", "NO"); else IupSetAttribute(item_paste, "ACTIVE", "YES"); IupDestroy(clipboard); return IUP_DEFAULT; } int SimplePaint::ConfigRecentCallback(Ihandle* ih) { if (file.SaveCheck()) { char* filename = IupGetAttribute(ih, "RECENTFILENAME"); OpenFile(filename); } return IUP_DEFAULT; } int SimplePaint::DialogMoveCallback(Ihandle* dlg, int x, int y) { int old_x = IupGetInt(dlg, "_OLD_X"); int old_y = IupGetInt(dlg, "_OLD_Y"); if (old_x == x && old_y == y) return IUP_DEFAULT; toolbox.MoveDialog(x - old_x, y - old_y); IupSetInt(dlg, "_OLD_X", x); IupSetInt(dlg, "_OLD_Y", y); return IUP_DEFAULT; } /********************************* SimplePaint Menu Item Callbacks Methods **************************/ int SimplePaint::ItemNewActionCallback(Ihandle*) { if (file.SaveCheck()) { int width = IupConfigGetVariableIntDef(config, "NewImage", "Width", 640); int height = IupConfigGetVariableIntDef(config, "NewImage", "Height", 480); if (IupGetParam("New Image", NULL, NULL, "Width: %i[1,]\nHeight: %i[1,]\n", &width, &height, NULL)) { IupConfigSetVariableInt(config, "NewImage", "Width", width); IupConfigSetVariableInt(config, "NewImage", "Height", height); file.New(width, height); UpdateFile(); } } return IUP_DEFAULT; } int SimplePaint::ItemOpenActionCallback(Ihandle*) { if (!file.SaveCheck()) return IUP_DEFAULT; SelectFile(true); return IUP_DEFAULT; } int SimplePaint::ItemSaveasActionCallback(Ihandle*) { SelectFile(false); return IUP_DEFAULT; } int SimplePaint::ItemSaveActionCallback(Ihandle* item_save) { if (!file.GetFilename()) ItemSaveasActionCallback(item_save); else { /* test again because in can be called using the hot key */ if (file.dirty) file.SaveFile(); } return IUP_DEFAULT; } int SimplePaint::ItemRevertActionCallback(Ihandle*) { OpenFile(file.GetFilename()); return IUP_DEFAULT; } int SimplePaint::ItemPagesetupActionCallback(Ihandle*) { int margin_width = IupConfigGetVariableIntDef(config, "Print", "MarginWidth", 20); int margin_height = IupConfigGetVariableIntDef(config, "Print", "MarginHeight", 20); if (IupGetParam("Page Setup", NULL, NULL, "Margin Width (mm): %i[1,]\nMargin Height (mm): %i[1,]\n", &margin_width, &margin_height, NULL)) { IupConfigSetVariableInt(config, "Print", "MarginWidth", margin_width); IupConfigSetVariableInt(config, "Print", "MarginHeight", margin_height); } return IUP_DEFAULT; } int SimplePaint::ItemPrintActionCallback(Ihandle*) { char* title = IupGetAttribute(dlg, "TITLE"); cdCanvas* print_canvas = cdCreateCanvasf(CD_PRINTER, "%s -d", title); if (!print_canvas) return IUP_DEFAULT; /* do NOT draw the background, use the paper color */ /* draw the image at the center of the canvas */ if (file.GetImage()) { int x, y, canvas_width, canvas_height, view_width, view_height; double canvas_width_mm, canvas_height_mm; int margin_width = IupConfigGetVariableIntDef(config, "Print", "MarginWidth", 20); int margin_height = IupConfigGetVariableIntDef(config, "Print", "MarginHeight", 20); cdCanvasGetSize(print_canvas, &canvas_width, &canvas_height, &canvas_width_mm, &canvas_height_mm); /* convert to pixels */ margin_width = (int)((margin_width * canvas_width) / canvas_width_mm); margin_height = (int)((margin_height * canvas_height) / canvas_height_mm); view_fit_rect(canvas_width - 2 * margin_width, canvas_height - 2 * margin_height, file.GetImage()->width, file.GetImage()->height, &view_width, &view_height); x = (canvas_width - view_width) / 2; y = (canvas_height - view_height) / 2; cdCanvasPutImImage(print_canvas, file.GetImage(), x, y, view_width, view_height); } cdKillCanvas(print_canvas); return IUP_DEFAULT; } int SimplePaint::ItemExitActionCallback(Ihandle*) { if (!file.SaveCheck()) return IUP_IGNORE; /* to abort the CLOSE_CB callback normal processing */ toolbox.HideDialog(); file.Close(); IupConfigDialogClosed(config, dlg, "MainWindow"); IupConfigSave(config); IupDestroy(config); return IUP_CLOSE; } int SimplePaint::ItemCopyActionCallback(Ihandle*) { Ihandle *clipboard = IupClipboard(); IupSetAttribute(clipboard, "NATIVEIMAGE", NULL); /* clear clipboard first */ IupSetAttribute(clipboard, "NATIVEIMAGE", (char*)IupGetImageNativeHandle(file.GetImage())); IupDestroy(clipboard); return IUP_DEFAULT; } int SimplePaint::ItemPasteActionCallback(Ihandle*) { if (file.SaveCheck()) { Ihandle *clipboard = IupClipboard(); imImage* new_image = IupGetNativeHandleImage(IupGetAttribute(clipboard, "NATIVEIMAGE")); IupDestroy(clipboard); if (!new_image) { show_error("Invalid Clipboard Data", 1); return IUP_DEFAULT; } file.New(new_image); UpdateFile(); } return IUP_DEFAULT; } int SimplePaint::ItemBackgroundActionCallback(Ihandle*) { Ihandle* colordlg = IupColorDlg(); const char* background = IupConfigGetVariableStrDef(config, "Canvas", "Background", "208 208 208"); IupSetStrAttribute(colordlg, "VALUE", background); IupSetAttributeHandle(colordlg, "PARENTDIALOG", dlg); IupPopup(colordlg, IUP_CENTERPARENT, IUP_CENTERPARENT); if (IupGetInt(colordlg, "STATUS") == 1) { background = IupGetAttribute(colordlg, "VALUE"); IupConfigSetVariableStr(config, "Canvas", "Background", background); IupUpdate(canvas); } IupDestroy(colordlg); return IUP_DEFAULT; } int SimplePaint::ItemZoomoutActionCallback(Ihandle*) { Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); double zoom_index = IupGetDouble(zoom_val, "VALUE"); zoom_index--; if (zoom_index < -6) zoom_index = -6; IupSetDouble(zoom_val, "VALUE", round(zoom_index)); /* fixed increments when using buttons */ UpdateZoom(zoom_index); return IUP_DEFAULT; } int SimplePaint::ItemZoominActionCallback(Ihandle*) { Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); double zoom_index = IupGetDouble(zoom_val, "VALUE"); zoom_index++; if (zoom_index > 6) zoom_index = 6; IupSetDouble(zoom_val, "VALUE", round(zoom_index)); /* fixed increments when using buttons */ UpdateZoom(zoom_index); return IUP_DEFAULT; } int SimplePaint::ItemActualsizeActionCallback(Ihandle*) { Ihandle* zoom_val = IupGetDialogChild(dlg, "ZOOMVAL"); IupSetDouble(zoom_val, "VALUE", 0); UpdateZoom(0); return IUP_DEFAULT; } int SimplePaint::ItemZoomgridActionCallback(Ihandle*) { Ihandle* item_zoomgrid = IupGetDialogChild(dlg, "ZOOMGRID"); if (IupGetInt(item_zoomgrid, "VALUE")) IupSetAttribute(item_zoomgrid, "VALUE", "OFF"); else IupSetAttribute(item_zoomgrid, "VALUE", "ON"); IupConfigSetVariableStr(config, "Canvas", "ZoomGrid", IupGetAttribute(item_zoomgrid, "VALUE")); IupUpdate(canvas); return IUP_DEFAULT; } int SimplePaint::ItemToolbarActionCallback(Ihandle* item_toolbar) { Ihandle* toolbar = IupGetDialogChild(item_toolbar, "TOOLBAR"); ToggleBarVisibility(item_toolbar, toolbar); IupConfigSetVariableStr(config, "MainWindow", "Toolbar", IupGetAttribute(item_toolbar, "VALUE")); return IUP_DEFAULT; } int SimplePaint::ItemToolboxActionCallback(Ihandle* item_toolbox) { if (toolbox.HideDialog()) IupSetAttribute(item_toolbox, "VALUE", "OFF"); else { IupSetAttribute(item_toolbox, "VALUE", "ON"); toolbox.ShowDialog(); } IupConfigSetVariableStr(config, "MainWindow", "Toolbox", IupGetAttribute(item_toolbox, "VALUE")); return IUP_DEFAULT; } int SimplePaint::ItemStatusbarActionCallback(Ihandle* item_statusbar) { Ihandle* statusbar = IupGetDialogChild(item_statusbar, "STATUSBAR"); ToggleBarVisibility(item_statusbar, statusbar); IupConfigSetVariableStr(config, "MainWindow", "Statusbar", IupGetAttribute(item_statusbar, "VALUE")); return IUP_DEFAULT; } int SimplePaint::ItemResizeActionCallback(Ihandle*) { int height = file.GetImage()->height, width = file.GetImage()->width; int quality = IupConfigGetVariableIntDef(config, "Image", "ResizeQuality", 1); /* medium default */ if (!IupGetParam("Resize", NULL, NULL, "Width: %i[1,]\n" "Height: %i[1,]\n" "Quality: %l|low|medium|high|\n", &width, &height, &quality, NULL)) return IUP_DEFAULT; IupConfigSetVariableInt(config, "Image", "ResizeQuality", quality); imImage* new_image = imImageCreateBased(file.GetImage(), width, height, -1, -1); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } if (quality == 2) quality = 3; /* interpolation order can be 0, 1, and 3 */ imProcessResize(file.GetImage(), new_image, quality); UpdateImage(new_image, true); /* update size */ return IUP_DEFAULT; } int SimplePaint::ItemMirrorActionCallback(Ihandle*) { imImage* new_image = imImageClone(file.GetImage()); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } imProcessMirror(file.GetImage(), new_image); UpdateImage(new_image); return IUP_DEFAULT; } int SimplePaint::ItemFlipActionCallback(Ihandle*) { imImage* new_image = imImageClone(file.GetImage()); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } imProcessFlip(file.GetImage(), new_image); UpdateImage(new_image); return IUP_DEFAULT; } int SimplePaint::ItemRotate180ActionCallback(Ihandle*) { imImage* new_image = imImageClone(file.GetImage()); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } imProcessRotate180(file.GetImage(), new_image); UpdateImage(new_image); return IUP_DEFAULT; } int SimplePaint::ItemRotate90cwActionCallback(Ihandle*) { imImage* new_image = imImageCreateBased(file.GetImage(), file.GetImage()->height, file.GetImage()->width, -1, -1); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } imProcessRotate90(file.GetImage(), new_image, 1); UpdateImage(new_image, true); /* update size */ return IUP_DEFAULT; } int SimplePaint::ItemRotate90ccwActionCallback(Ihandle*) { imImage* new_image = imImageCreateBased(file.GetImage(), file.GetImage()->height, file.GetImage()->width, -1, -1); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } imProcessRotate90(file.GetImage(), new_image, -1); UpdateImage(new_image, true); /* update size */ return IUP_DEFAULT; } int SimplePaint::ItemNegativeActionCallback(Ihandle*) { imImage* new_image = imImageClone(file.GetImage()); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } imProcessNegative(file.GetImage(), new_image); UpdateImage(new_image); return IUP_DEFAULT; } static int brightcont_param_cb(Ihandle* dialog, int param_index, void* user_data) { Ihandle* canvas = (Ihandle*)user_data; if (param_index == 0 || param_index == 1) { float param[2] = { 0, 0 }; imImage* image = (imImage*)IupGetAttribute(canvas, "ORIGINAL_IMAGE"); imImage* new_image = (imImage*)IupGetAttribute(canvas, "NEW_IMAGE"); SimplePaintFile* file = (SimplePaintFile*)IupGetAttribute(canvas, "IMAGE_FILE"); Ihandle* brightness_shift_param = (Ihandle*)IupGetAttribute(dialog, "PARAM0"); Ihandle* contrast_factor_param = (Ihandle*)IupGetAttribute(dialog, "PARAM1"); param[0] = IupGetFloat(brightness_shift_param, "VALUE"); param[1] = IupGetFloat(contrast_factor_param, "VALUE"); imProcessToneGamut(image, new_image, IM_GAMUT_BRIGHTCONT, param); file->SetImage(new_image, false); IupUpdate(canvas); } else if (param_index != IUP_GETPARAM_INIT && param_index != IUP_GETPARAM_MAP) { /* restore original configuration */ SimplePaintFile* file = (SimplePaintFile*)IupGetAttribute(canvas, "IMAGE_FILE"); imImage* image = (imImage*)IupGetAttribute(canvas, "ORIGINAL_IMAGE"); file->SetImage(image, false); IupSetAttribute(canvas, "ORIGINAL_IMAGE", NULL); IupSetAttribute(canvas, "NEW_IMAGE", NULL); IupSetAttribute(canvas, "IMAGE_FILE", NULL); if (param_index == IUP_GETPARAM_BUTTON2) /* cancel */ IupUpdate(canvas); } return 1; } int SimplePaint::ItemBrightcontActionCallback(Ihandle*) { imImage* new_image = imImageClone(file.GetImage()); if (!new_image) { show_file_error(IM_ERR_MEM); return IUP_DEFAULT; } IupSetAttribute(canvas, "ORIGINAL_IMAGE", (char*)file.GetImage()); IupSetAttribute(canvas, "NEW_IMAGE", (char*)new_image); IupSetAttribute(canvas, "IMAGE_FILE", (char*)&file); float param[2] = { 0, 0 }; if (!IupGetParam("Brightness and Contrast", brightcont_param_cb, canvas, "Brightness Shift: %r[-100,100]\n" "Contrast Factor: %r[-100,100]\n", ¶m[0], ¶m[1], NULL)) { imImageDestroy(new_image); return IUP_DEFAULT; } /* since the image was already processed in preview we don't need to process it again, but leave it here to illustrate the logic */ imProcessToneGamut(file.GetImage(), new_image, IM_GAMUT_BRIGHTCONT, param); UpdateImage(new_image); return IUP_DEFAULT; } int SimplePaint::ItemHelpActionCallback(Ihandle*) { IupHelp("http://www.tecgraf.puc-rio.br/iup"); return IUP_DEFAULT; } int SimplePaint::ItemAboutActionCallback(Ihandle*) { IupMessage("About", " Simple Paint\n\nAuthors:\n Gustavo Lyrio\n Antonio Scuri"); return IUP_DEFAULT; } /************************************* SimplePaintToolbox Callbacks Methods ****************************************/ int SimplePaintToolbox::CloseCallback(Ihandle*) { Ihandle* item_toolbox = IupGetDialogChild(paint_canvas, "TOOLBOXMENU"); IupSetAttribute(item_toolbox, "VALUE", "OFF"); IupConfigDialogClosed(config, toolbox, "Toolbox"); IupConfigSetVariableStr(config, "MainWindow", "Toolbox", "OFF"); return IUP_DEFAULT; } void SimplePaintToolbox::MoveDialog(int dx, int dy) { if (!toolbox) return; if (IupGetInt(toolbox, "VISIBLE")) { int tb_x = IupGetInt(toolbox, "X"); int tb_y = IupGetInt(toolbox, "Y"); tb_x += dx; tb_y += dy; IupShowXY(toolbox, tb_x, tb_y); } } bool SimplePaintToolbox::HideDialog() { if (IupGetInt(toolbox, "VISIBLE")) { IupConfigDialogClosed(config, toolbox, "Toolbox"); IupHide(toolbox); return true; } return false; } void SimplePaintToolbox::ShowDialog() { IupConfigDialogShow(config, toolbox, "Toolbox"); } void SimplePaintToolbox::SetColor(long new_color) { Ihandle* color = IupGetDialogChild(toolbox, "COLOR"); IupSetRGB(color, "BGCOLOR", cdRed(new_color), cdGreen(new_color), cdBlue(new_color)); options.color = new_color; } int SimplePaintToolbox::ToolActionCallback(Ihandle* ih, int state) { if (state == 1) { tool_index = (Tool)IupGetInt(ih, "TOOLINDEX"); if (tool_index == TOOL_POINTER) IupSetAttribute(paint_canvas, "CURSOR", "ARROW"); else IupSetAttribute(paint_canvas, "CURSOR", "CROSS"); if (tool_index == TOOL_TEXT) ToolGetText(); } return IUP_DEFAULT; } static int tool_get_text_enter_cb(void) { return IUP_CLOSE; } void SimplePaintToolbox::ToolGetText() { Ihandle *text, *dlg; char* value = IupGetAttribute(toolbox, "TOOLTEXT"); char* font = IupGetAttribute(toolbox, "TOOLFONT"); text = IupText(NULL); IupSetAttribute(text, "EXPAND", "YES"); IupSetStrAttribute(text, "VALUE", value); IupSetStrAttribute(text, "FONT", font); IupSetAttribute(text, "VISIBLECOLUMNS", "20"); dlg = IupDialog(text); IupSetStrAttribute(dlg, "TITLE", "Enter Text:"); IupSetAttribute(dlg, "MINBOX", "NO"); IupSetAttribute(dlg, "MAXBOX", "NO"); IupSetCallback(dlg, "K_CR", (Icallback)tool_get_text_enter_cb); IupSetAttributeHandle(dlg, "PARENTDIALOG", toolbox); IupPopup(dlg, IUP_MOUSEPOS, IUP_MOUSEPOS); value = IupGetAttribute(text, "VALUE"); IupSetStrAttribute(toolbox, "TOOLTEXT", value); IupDestroy(dlg); } int SimplePaintToolbox::ToolColorActionCallback(Ihandle* ih) { Ihandle* colordlg = IupColorDlg(); const char* color = IupGetAttribute(ih, "BGCOLOR"); IupSetStrAttribute(colordlg, "VALUE", color); IupSetAttributeHandle(colordlg, "PARENTDIALOG", toolbox); IupPopup(colordlg, IUP_CENTER, IUP_CENTER); if (IupGetInt(colordlg, "STATUS") == 1) { color = IupGetAttribute(colordlg, "VALUE"); IupSetStrAttribute(ih, "BGCOLOR", color); unsigned char r, g, b; IupGetRGB(ih, "BGCOLOR", &r, &g, &b); options.color = cdEncodeColor(r, g, b); } IupDestroy(colordlg); return IUP_DEFAULT; } int SimplePaintToolbox::ToolWidthValueChangedCallback(Ihandle* ih) { options.line_width = IupGetInt(ih, "VALUE"); return IUP_DEFAULT; } int SimplePaintToolbox::ToolStyleValueChangedCallback(Ihandle* ih) { options.line_style = IupGetInt(ih, "VALUE") - 1; return IUP_DEFAULT; } int SimplePaintToolbox::ToolFontActionCallback(Ihandle* ih) { Ihandle* font_dlg = IupFontDlg(); IupSetAttributeHandle(font_dlg, "PARENTDIALOG", toolbox); char* font = IupGetAttribute(ih, "TOOLFONT"); IupSetStrAttribute(font_dlg, "VALUE", font); IupPopup(font_dlg, IUP_CENTER, IUP_CENTER); if (IupGetInt(font_dlg, "STATUS") == 1) { font = IupGetAttribute(font_dlg, "VALUE"); IupSetStrAttribute(toolbox, "TOOLFONT", font); } IupDestroy(font_dlg); return IUP_DEFAULT; } int SimplePaintToolbox::ToolFillTolValueChangedCallback(Ihandle* ih) { Ihandle* filltol_label = IupGetDialogChild(toolbox, "FILLTOLLABEL"); options.fill_tol = IupGetDouble(ih, "VALUE"); IupSetStrf(filltol_label, "TITLE", "Tol.: %.0f%%", options.fill_tol); return IUP_DEFAULT; } /********************************** Main *****************************************/ Ihandle* SimplePaint::CreateMainMenu() { Ihandle *menu, *sub_menu_file; Ihandle *file_menu, *item_exit, *item_new, *item_open, *item_save, *item_saveas, *item_revert; Ihandle *sub_menu_edit, *edit_menu, *item_copy, *item_paste, *item_print, *item_pagesetup; Ihandle *sub_menu_help, *help_menu, *item_help, *item_about; Ihandle *sub_menu_view, *view_menu, *item_toolbar, *item_statusbar; Ihandle *item_zoomin, *item_zoomout, *item_actualsize; Ihandle *recent_menu, *item_background, *item_toolbox, *item_zoomgrid; Ihandle *sub_menu_image, *image_menu; item_new = IupItem("&New\tCtrl+N", NULL); IupSetAttribute(item_new, "IMAGE", "IUP_FileNew"); IUP_CLASS_SETCALLBACK(item_new, "ACTION", ItemNewActionCallback); item_open = IupItem("&Open...\tCtrl+O", NULL); IupSetAttribute(item_open, "IMAGE", "IUP_FileOpen"); IUP_CLASS_SETCALLBACK(item_open, "ACTION", ItemOpenActionCallback); item_save = IupItem("&Save\tCtrl+S", NULL); IupSetAttribute(item_save, "NAME", "ITEM_SAVE"); IupSetAttribute(item_save, "IMAGE", "IUP_FileSave"); IUP_CLASS_SETCALLBACK(item_save, "ACTION", ItemSaveActionCallback); item_saveas = IupItem("Save &As...", NULL); IupSetAttribute(item_saveas, "NAME", "ITEM_SAVEAS"); IUP_CLASS_SETCALLBACK(item_saveas, "ACTION", ItemSaveasActionCallback); item_revert = IupItem("&Revert", NULL); IupSetAttribute(item_revert, "NAME", "ITEM_REVERT"); IUP_CLASS_SETCALLBACK(item_revert, "ACTION", ItemRevertActionCallback); item_pagesetup = IupItem("Page Set&up...", NULL); IUP_CLASS_SETCALLBACK(item_pagesetup, "ACTION", ItemPagesetupActionCallback); item_print = IupItem("&Print...\tCtrl+P", NULL); IUP_CLASS_SETCALLBACK(item_print, "ACTION", ItemPrintActionCallback); item_exit = IupItem("E&xit", NULL); IUP_CLASS_SETCALLBACK(item_exit, "ACTION", ItemExitActionCallback); item_copy = IupItem("&Copy\tCtrl+C", NULL); IupSetAttribute(item_copy, "NAME", "ITEM_COPY"); IupSetAttribute(item_copy, "IMAGE", "IUP_EditCopy"); IUP_CLASS_SETCALLBACK(item_copy, "ACTION", ItemCopyActionCallback); item_paste = IupItem("&Paste\tCtrl+V", NULL); IupSetAttribute(item_paste, "NAME", "ITEM_PASTE"); IupSetAttribute(item_paste, "IMAGE", "IUP_EditPaste"); IUP_CLASS_SETCALLBACK(item_paste, "ACTION", ItemPasteActionCallback); item_zoomin = IupItem("Zoom &In\tCtrl++", NULL); IupSetAttribute(item_zoomin, "IMAGE", "IUP_ZoomIn"); IUP_CLASS_SETCALLBACK(item_zoomin, "ACTION", ItemZoominActionCallback); item_zoomout = IupItem("Zoom &Out\tCtrl+-", NULL); IupSetAttribute(item_zoomout, "IMAGE", "IUP_ZoomOut"); IUP_CLASS_SETCALLBACK(item_zoomout, "ACTION", ItemZoomoutActionCallback); item_actualsize = IupItem("&Actual Size\tCtrl+0", NULL); IupSetAttribute(item_actualsize, "IMAGE", "IUP_ZoomActualSize"); IUP_CLASS_SETCALLBACK(item_actualsize, "ACTION", ItemActualsizeActionCallback); item_zoomgrid = IupItem("&Zoom Grid", NULL); IUP_CLASS_SETCALLBACK(item_zoomgrid, "ACTION", ItemZoomgridActionCallback); IupSetAttribute(item_zoomgrid, "NAME", "ZOOMGRID"); IupSetAttribute(item_zoomgrid, "VALUE", "ON"); /* default is ON */ item_background = IupItem("&Background...", NULL); IUP_CLASS_SETCALLBACK(item_background, "ACTION", ItemBackgroundActionCallback); item_toolbar = IupItem("&Toobar", NULL); IUP_CLASS_SETCALLBACK(item_toolbar, "ACTION", ItemToolbarActionCallback); IupSetAttribute(item_toolbar, "VALUE", "ON"); /* default is ON */ item_toolbox = IupItem("&Toobox", NULL); IUP_CLASS_SETCALLBACK(item_toolbox, "ACTION", ItemToolboxActionCallback); IupSetAttribute(item_toolbox, "NAME", "TOOLBOXMENU"); IupSetAttribute(item_toolbox, "VALUE", "ON"); /* default is ON */ item_statusbar = IupItem("&Statusbar", NULL); IUP_CLASS_SETCALLBACK(item_statusbar, "ACTION", ItemStatusbarActionCallback); IupSetAttribute(item_statusbar, "VALUE", "ON"); /* default is ON */ item_help = IupItem("&Help...", NULL); IUP_CLASS_SETCALLBACK(item_help, "ACTION", ItemHelpActionCallback); item_about = IupItem("&About...", NULL); IUP_CLASS_SETCALLBACK(item_about, "ACTION", ItemAboutActionCallback); recent_menu = IupMenu(NULL); file_menu = IupMenu( item_new, item_open, item_save, item_saveas, item_revert, IupSeparator(), item_pagesetup, item_print, IupSeparator(), IupSubmenu("Recent &Files", recent_menu), IupSeparator(), item_exit, NULL); edit_menu = IupMenu( item_copy, item_paste, NULL); view_menu = IupMenu( item_zoomin, item_zoomout, item_actualsize, item_zoomgrid, IupSeparator(), item_background, IupSeparator(), item_toolbar, item_toolbox, item_statusbar, NULL); image_menu = IupMenu( IupSetCallbacks(IupItem("&Resize...", NULL), "ACTION", CB_ItemResizeActionCallback, NULL), IupSetCallbacks(IupItem("&Mirror", NULL), "ACTION", CB_ItemMirrorActionCallback, NULL), IupSetCallbacks(IupItem("&Flip", NULL), "ACTION", CB_ItemFlipActionCallback, NULL), IupSetCallbacks(IupItem("&Rotate 180º", NULL), "ACTION", CB_ItemRotate180ActionCallback, NULL), IupSetCallbacks(IupItem("&Rotate +90º (clock-wise)", NULL), "ACTION", CB_ItemRotate90cwActionCallback, NULL), IupSetCallbacks(IupItem("&Rotate -90º (counter-clock)", NULL), "ACTION", CB_ItemRotate90ccwActionCallback, NULL), IupSeparator(), IupSetCallbacks(IupItem("&Negative", NULL), "ACTION", CB_ItemNegativeActionCallback, NULL), IupSetCallbacks(IupItem("&Brightness and Contrast...", NULL), "ACTION", CB_ItemBrightcontActionCallback, NULL), NULL); help_menu = IupMenu( item_help, item_about, NULL); IUP_CLASS_SETCALLBACK(file_menu, "OPEN_CB", FileMenuOpenCallback); IUP_CLASS_SETCALLBACK(edit_menu, "OPEN_CB", EditMenuOpenCallback); sub_menu_file = IupSubmenu("&File", file_menu); sub_menu_edit = IupSubmenu("&Edit", edit_menu); sub_menu_view = IupSubmenu("&View", view_menu); sub_menu_image = IupSubmenu("&Image", image_menu); sub_menu_help = IupSubmenu("&Help", help_menu); menu = IupMenu( sub_menu_file, sub_menu_edit, sub_menu_view, sub_menu_image, sub_menu_help, NULL); /* Initialize variables from the configuration file */ IupConfigRecentInit(config, recent_menu, CB_ConfigRecentCallback, 10); if (!IupConfigGetVariableIntDef(config, "Canvas", "ZoomGrid", 1)) IupSetAttribute(item_zoomgrid, "VALUE", "OFF"); if (!IupConfigGetVariableIntDef(config, "MainWindow", "Toolbar", 1)) IupSetAttribute(item_toolbar, "VALUE", "OFF"); if (!IupConfigGetVariableIntDef(config, "MainWindow", "Toolbox", 1)) IupSetAttribute(item_toolbox, "VALUE", "OFF"); if (!IupConfigGetVariableIntDef(config, "MainWindow", "Statusbar", 1)) IupSetAttribute(item_statusbar, "VALUE", "OFF"); return menu; } Ihandle* SimplePaint::CreateToolbar() { Ihandle *toolbar; Ihandle *btn_copy, *btn_paste, *btn_new, *btn_open, *btn_save, *btn_zoomgrid; IupSetHandle("PaintZoomGrid", load_image_PaintZoomGrid()); btn_new = IupButton(NULL, NULL); IupSetAttribute(btn_new, "IMAGE", "IUP_FileNew"); IupSetAttribute(btn_new, "FLAT", "Yes"); IUP_CLASS_SETCALLBACK(btn_new, "ACTION", ItemNewActionCallback); IupSetAttribute(btn_new, "TIP", "New (Ctrl+N)"); IupSetAttribute(btn_new, "CANFOCUS", "No"); btn_open = IupButton(NULL, NULL); IupSetAttribute(btn_open, "IMAGE", "IUP_FileOpen"); IupSetAttribute(btn_open, "FLAT", "Yes"); IUP_CLASS_SETCALLBACK(btn_open, "ACTION", ItemOpenActionCallback); IupSetAttribute(btn_open, "TIP", "Open (Ctrl+O)"); IupSetAttribute(btn_open, "CANFOCUS", "No"); btn_save = IupButton(NULL, NULL); IupSetAttribute(btn_save, "IMAGE", "IUP_FileSave"); IupSetAttribute(btn_save, "FLAT", "Yes"); IUP_CLASS_SETCALLBACK(btn_save, "ACTION", ItemSaveActionCallback); IupSetAttribute(btn_save, "TIP", "Save (Ctrl+S)"); IupSetAttribute(btn_save, "CANFOCUS", "No"); btn_copy = IupButton(NULL, NULL); IupSetAttribute(btn_copy, "IMAGE", "IUP_EditCopy"); IupSetAttribute(btn_copy, "FLAT", "Yes"); IUP_CLASS_SETCALLBACK(btn_copy, "ACTION", ItemCopyActionCallback); IupSetAttribute(btn_copy, "TIP", "Copy (Ctrl+C)"); IupSetAttribute(btn_copy, "CANFOCUS", "No"); btn_paste = IupButton(NULL, NULL); IupSetAttribute(btn_paste, "IMAGE", "IUP_EditPaste"); IupSetAttribute(btn_paste, "FLAT", "Yes"); IUP_CLASS_SETCALLBACK(btn_paste, "ACTION", ItemPasteActionCallback); IupSetAttribute(btn_paste, "TIP", "Paste (Ctrl+V)"); IupSetAttribute(btn_paste, "CANFOCUS", "No"); btn_zoomgrid = IupButton(NULL, NULL); IupSetAttribute(btn_zoomgrid, "IMAGE", "PaintZoomGrid"); IupSetAttribute(btn_zoomgrid, "FLAT", "Yes"); IUP_CLASS_SETCALLBACK(btn_zoomgrid, "ACTION", ItemZoomgridActionCallback); IupSetAttribute(btn_zoomgrid, "TIP", "Zoom Grid"); IupSetAttribute(btn_paste, "CANFOCUS", "No"); toolbar = IupHbox( btn_new, btn_open, btn_save, IupSetAttributes(IupLabel(NULL), "SEPARATOR=VERTICAL"), btn_copy, btn_paste, IupSetAttributes(IupLabel(NULL), "SEPARATOR=VERTICAL"), btn_zoomgrid, NULL); IupSetAttribute(toolbar, "MARGIN", "5x5"); IupSetAttribute(toolbar, "GAP", "2"); IupSetAttribute(toolbar, "NAME", "TOOLBAR"); /* Initialize variables from the configuration file */ if (!IupConfigGetVariableIntDef(config, "MainWindow", "Toolbar", 1)) { IupSetAttribute(toolbar, "FLOATING", "YES"); IupSetAttribute(toolbar, "VISIBLE", "NO"); } return toolbar; } void SimplePaintToolbox::CreateDialog(Ihandle* canvas, Ihandle* main_config) { Ihandle *gbox, *vbox; IupSetHandle("PaintPointer", load_image_Pointer()); IupSetHandle("PaintColorPicker", load_image_PaintColorPicker()); IupSetHandle("PaintPencil", load_image_PaintPencil()); IupSetHandle("PaintLine", load_image_PaintLine()); IupSetHandle("PaintEllipse", load_image_PaintEllipse()); IupSetHandle("PaintRect", load_image_PaintRect()); IupSetHandle("PaintOval", load_image_PaintOval()); IupSetHandle("PaintBox", load_image_PaintBox()); IupSetHandle("PaintFill", load_image_PaintFill()); IupSetHandle("PaintText", load_image_PaintText()); gbox = IupGridBox( IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=0, IMAGE=PaintPointer, VALUE=ON, FLAT=Yes, TIP=\"Pointer\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=1, IMAGE=PaintColorPicker, FLAT=Yes, TIP=\"Color Picker\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=2, IMAGE=PaintPencil, FLAT=Yes, TIP=\"Pencil\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=3, IMAGE=PaintLine, FLAT=Yes, TIP=\"Line\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=4, IMAGE=PaintRect, FLAT=Yes, TIP=\"Hollow Rectangle\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=5, IMAGE=PaintBox, FLAT=Yes, TIP=\"Box (Filled Rectangle)\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=6, IMAGE=PaintEllipse, FLAT=Yes, TIP=\"Hollow Ellipse\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=7, IMAGE=PaintOval, FLAT=Yes, TIP=\"Oval (Filled Ellipse)\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=8, IMAGE=PaintText, FLAT=Yes, TIP=\"Text\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TOOLINDEX=9, IMAGE=PaintFill, FLAT=Yes, TIP=\"Fill Color\""), "ACTION", (Icallback)CB_ToolActionCallback, NULL), NULL); IupSetAttribute(gbox, "GAPCOL", "2"); IupSetAttribute(gbox, "GAPLIN", "2"); IupSetAttribute(gbox, "MARGIN", "5x10"); IupSetAttribute(gbox, "NUMDIV", "2"); vbox = IupVbox( IupRadio(gbox), IupFrame(IupSetAttributes(IupVbox( IupSetAttributes(IupLabel("Color:"), "EXPAND=HORIZONTAL"), IupSetCallbacks(IupSetAttributes(IupButton(NULL, NULL), "NAME=COLOR, BGCOLOR=\"0 0 0\", RASTERSIZE=28x21"), "ACTION", CB_ToolColorActionCallback, NULL), IupSetAttributes(IupLabel("Width:"), "EXPAND=HORIZONTAL"), IupSetCallbacks(IupSetAttributes(IupText(NULL), "SPIN=Yes, SPINMIN=1, RASTERSIZE=48x"), "VALUECHANGED_CB", CB_ToolWidthValueChangedCallback, NULL), IupSetAttributes(IupLabel("Style:"), "EXPAND=HORIZONTAL"), IupSetCallbacks(IupSetAttributes(IupList(NULL), "DROPDOWN=Yes, VALUE=1, 1=\"____\", 2=\"----\", 3=\"....\", 4=\"-.-.\", 5=\"-..-..\""), "VALUECHANGED_CB", CB_ToolStyleValueChangedCallback, NULL), IupSetAttributes(IupLabel("Tol.: 50%"), "EXPAND=HORIZONTAL, NAME=FILLTOLLABEL"), IupSetCallbacks(IupSetAttributes(IupVal(NULL), "NAME=FILLTOL, RASTERSIZE=60x30, VALUE=50, MAX=100"), "VALUECHANGED_CB", CB_ToolFillTolValueChangedCallback, NULL), IupSetAttributes(IupLabel("Font:"), "EXPAND=HORIZONTAL"), IupSetCallbacks(IupSetAttributes(IupButton("F", NULL), "NAME=FONT, RASTERSIZE=21x21, FONT=\"Times, Bold Italic 11\""), "ACTION", CB_ToolFontActionCallback, NULL), NULL), "MARGIN=3x2, GAP=2, ALIGNMENT=ACENTER")), NULL); IupSetAttribute(vbox, "NMARGIN", "2x2"); IupSetAttribute(vbox, "ALIGNMENT", "ACENTER"); toolbox = IupDialog(vbox); IupSetAttribute(toolbox, "DIALOGFRAME", "Yes"); IupSetAttribute(toolbox, "TITLE", "Tools"); IupSetAttribute(toolbox, "FONTSIZE", "8"); IupSetAttribute(toolbox, "TOOLBOX", "Yes"); IUP_CLASS_SETCALLBACK(toolbox, "CLOSE_CB", CloseCallback); IupSetAttributeHandle(toolbox, "PARENTDIALOG", IupGetDialog(canvas)); IupSetStrAttribute(toolbox, "TOOLFONT", IupGetAttribute(canvas, "FONT")); config = main_config; paint_canvas = canvas; /* Initialize variables from the configuration file */ if (IupConfigGetVariableIntDef(config, "MainWindow", "Toolbox", 1)) { /* configure the very first time to be aligned with the main window */ if (!IupConfigGetVariableStr(config, "Toolbox", "X")) { int x = IupGetInt(canvas, "X"); int y = IupGetInt(canvas, "Y"); IupConfigSetVariableInt(config, "Toolbox", "X", x); IupConfigSetVariableInt(config, "Toolbox", "Y", y); } IupConfigDialogShow(config, toolbox, "Toolbox"); } IUP_CLASS_INITCALLBACK(toolbox, SimplePaintToolbox); } Ihandle* SimplePaint::CreateStatusbar() { Ihandle *statusbar; statusbar = IupHbox( IupSetAttributes(IupLabel("(0, 0) = 0 0 0"), "EXPAND=HORIZONTAL, PADDING=10x5, NAME=STATUSLABEL"), IupSetAttributes(IupLabel(NULL), "SEPARATOR=VERTICAL"), IupSetAttributes(IupLabel("0 x 0"), "SIZE=70x, PADDING=10x5, NAME=SIZELABEL, ALIGNMENT=ACENTER"), IupSetAttributes(IupLabel(NULL), "SEPARATOR=VERTICAL"), IupSetAttributes(IupLabel("100%"), "SIZE=30x, PADDING=10x5, NAME=ZOOMLABEL, ALIGNMENT=ARIGHT"), IupSetCallbacks(IupSetAttributes(IupButton(NULL, NULL), "IMAGE=IUP_ZoomOut, FLAT=Yes, TIP=\"Zoom Out (Ctrl+-)\""), "ACTION", CB_ItemZoomoutActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupVal(NULL), "VALUE=0, MIN=-6, MAX=6, RASTERSIZE=150x25, NAME=ZOOMVAL"), "VALUECHANGED_CB", CB_ZoomValueChangedCallback, NULL), IupSetCallbacks(IupSetAttributes(IupButton(NULL, NULL), "IMAGE=IUP_ZoomIn, FLAT=Yes, TIP=\"Zoom In (Ctrl++)\""), "ACTION", CB_ItemZoominActionCallback, NULL), IupSetCallbacks(IupSetAttributes(IupButton(NULL, NULL), "IMAGE=IUP_ZoomActualSize, FLAT=Yes, TIP=\"Actual Size (Ctrl+0)\""), "ACTION", CB_ItemActualsizeActionCallback, NULL), NULL); IupSetAttribute(statusbar, "NAME", "STATUSBAR"); IupSetAttribute(statusbar, "ALIGNMENT", "ACENTER"); /* Initialize variables from the configuration file */ if (!IupConfigGetVariableIntDef(config, "MainWindow", "Statusbar", 1)) { IupSetAttribute(statusbar, "FLOATING", "YES"); IupSetAttribute(statusbar, "VISIBLE", "NO"); } return statusbar; } void SimplePaint::CreateMainDialog() { Ihandle *vbox; #ifdef USE_OPENGL canvas = IupGLCanvas(NULL); IupSetAttribute(canvas, "BUFFER", "DOUBLE"); #else canvas = IupCanvas(NULL); #endif IupSetAttribute(canvas, "SCROLLBAR", "Yes"); IUP_CLASS_SETCALLBACK(canvas, "ACTION", CanvasActionCallback); IUP_CLASS_SETCALLBACK(canvas, "MAP_CB", CanvasMapCallback); IUP_CLASS_SETCALLBACK(canvas, "UNMAP_CB", CanvasUnmapCallback); IUP_CLASS_SETCALLBACK(canvas, "WHEEL_CB", CanvasWheelCallback); IUP_CLASS_SETCALLBACK(canvas, "RESIZE_CB", CanvasResizeCallback); IUP_CLASS_SETCALLBACK(canvas, "MOTION_CB", CanvasMotionCallback); IUP_CLASS_SETCALLBACK(canvas, "BUTTON_CB", CanvasButtonCallback); IUP_CLASS_SETCALLBACK(canvas, "DROPFILES_CB", DropfilesCallback); vbox = IupVbox( CreateToolbar(), canvas, CreateStatusbar(), NULL); dlg = IupDialog(vbox); IupSetAttributeHandle(dlg, "MENU", CreateMainMenu()); IupSetAttribute(dlg, "SIZE", "HALFxHALF"); IUP_CLASS_SETCALLBACK(dlg, "CLOSE_CB", ItemExitActionCallback); IUP_CLASS_SETCALLBACK(dlg, "DROPFILES_CB", DropfilesCallback); IUP_CLASS_SETCALLBACK(dlg, "MOVE_CB", DialogMoveCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cN", ItemNewActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cO", ItemOpenActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cS", ItemSaveActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cV", ItemPasteActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cC", ItemCopyActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cP", ItemPrintActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cMinus", ItemZoomoutActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cPlus", ItemZoominActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_cEqual", ItemZoominActionCallback); IUP_CLASS_SETCALLBACK(dlg, "K_c0", ItemActualsizeActionCallback); /* parent for pre-defined dialogs in closed functions (IupMessage and IupAlarm) */ IupSetAttributeHandle(NULL, "PARENTDIALOG", dlg); } SimplePaint::SimplePaint() :cd_canvas(NULL), toolbox() { interact.overlay = false; config = IupConfig(); IupSetAttribute(config, "APP_NAME", "simple_paint"); IupConfigLoad(config); CreateMainDialog(); IUP_CLASS_INITCALLBACK(dlg, SimplePaint); /* show the dialog at the last position, with the last size */ IupConfigDialogShow(config, dlg, "MainWindow"); /* create and show the toolbox */ toolbox.CreateDialog(canvas, config); } int main(int argc, char **argv) { IupOpen(&argc, &argv); IupImageLibOpen(); #ifdef USE_OPENGL IupGLCanvasOpen(); #endif #ifdef USE_CONTEXTPLUS cdInitContextPlus(); #endif SimplePaint app; /* open a file from the command line (allow file association in Windows) */ if (argc > 1 && argv[1]) { const char* filename = argv[1]; app.OpenFile(filename); } /* initialize the current file, if not already loaded */ app.CheckNewFile(); IupMainLoop(); IupClose(); return EXIT_SUCCESS; } /* Possible Enhancements: - Save last used toolbox options in configuration file? - Hide/show toolbox options according to selected tool - Capture image from Camera using IM - Undo/Redo - Secondary color for drawing of shapes with both outline and filled at the same time - Alpha for colors - Area Selection */