mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-30 22:20:50 +00:00
probably better
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@571 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -6,15 +6,26 @@ MwWidget cpicker;
|
||||
MwWidget window;
|
||||
MwWidget button;
|
||||
|
||||
void color_callback(MwRGB rgb) {
|
||||
void color_callback(MwWidget handle, void* user_data, void* call_data) {
|
||||
char hexColor[8];
|
||||
MwRGB* rgb = call_data;
|
||||
|
||||
sprintf(hexColor, "#%02X%02X%02X", rgb.r, rgb.g, rgb.b);
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
|
||||
sprintf(hexColor, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
|
||||
MwSetText(window, MwNbackground, hexColor);
|
||||
}
|
||||
|
||||
void color_picker(MwWidget handle, void* user_data, void* call_data) {
|
||||
MwWidget cpicker = MwColorPicker(window, "cpicker", color_callback);
|
||||
MwWidget cpicker = MwColorPicker(window, "cpicker");
|
||||
|
||||
(void)handle;
|
||||
(void)user_data;
|
||||
(void)call_data;
|
||||
|
||||
MwAddUserHandler(cpicker, MwNcolorChosenHandler, color_callback, NULL);
|
||||
|
||||
MwSetText(cpicker, MwNbackground, MwDefaultBackground);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ typedef struct _MwRect MwRect;
|
||||
typedef struct _MwSizeHints MwSizeHints;
|
||||
typedef struct _MwFont MwFont;
|
||||
typedef struct _MwCursor MwCursor;
|
||||
typedef struct _MwRGB MwRGB;
|
||||
|
||||
typedef unsigned char MwBool;
|
||||
#define MwTRUE ((MwBool)1)
|
||||
@@ -104,4 +105,10 @@ struct _MwFont {
|
||||
unsigned char data[16];
|
||||
};
|
||||
|
||||
struct _MwRGB {
|
||||
MwU32 red;
|
||||
MwU32 green;
|
||||
MwU32 blue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,17 +14,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _MwRGB MwRGB;
|
||||
|
||||
struct _MwRGB {
|
||||
MwU32 r;
|
||||
MwU32 g;
|
||||
MwU32 b;
|
||||
};
|
||||
|
||||
typedef void (*MwColorPickerCallback)(MwRGB rgb);
|
||||
|
||||
MWDECL MwWidget MwColorPicker(MwWidget handle, const char* title, MwColorPickerCallback cb);
|
||||
/*!
|
||||
* @brief Creates a color picker
|
||||
* @param handle Widget
|
||||
* @param title Title text
|
||||
* @return Widget
|
||||
*/
|
||||
MWDECL MwWidget MwColorPicker(MwWidget handle, const char* title);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ MWDECL void MwLLPolygon(MwLL handle, MwPoint* points, int points_count, MwLLColo
|
||||
MWDECL void MwLLLine(MwLL handle, MwPoint* points, MwLLColor color);
|
||||
|
||||
MWDECL MwLLColor MwLLAllocColor(MwLL handle, int r, int g, int b);
|
||||
MWDECL void MwLLColorUpdate(MwLL handle, int r, int g, int b, MwLLColor c);
|
||||
MWDECL void MwLLColorUpdate(MwLL handle, MwLLColor c, int r, int g, int b);
|
||||
MWDECL void MwLLFreeColor(MwLLColor color);
|
||||
|
||||
MWDECL void MwLLGetXYWH(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h);
|
||||
|
||||
@@ -53,5 +53,6 @@
|
||||
#define MwNfocusInHandler "CfocusIn" /* NULL */
|
||||
#define MwNfocusOutHandler "CfocusOut" /* NULL */
|
||||
#define MwNfileChosenHandler "CfileChosen" /* char* */
|
||||
#define MwNcolorChosenHandler "CcolorChosen" /* MwRGB* */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -208,32 +208,11 @@ void MwLLLine(MwLL handle, MwPoint* points, MwLLColor color) {
|
||||
|
||||
MwLLColor MwLLAllocColor(MwLL handle, int r, int g, int b) {
|
||||
MwLLColor c = malloc(sizeof(*c));
|
||||
XColor xc;
|
||||
|
||||
if(handle->red_mask == 0) {
|
||||
if(r > 255) r = 255;
|
||||
if(g > 255) g = 255;
|
||||
if(b > 255) b = 255;
|
||||
if(r < 0) r = 0;
|
||||
if(g < 0) g = 0;
|
||||
if(b < 0) b = 0;
|
||||
|
||||
xc.red = 256 * r;
|
||||
xc.green = 256 * g;
|
||||
xc.blue = 256 * b;
|
||||
XAllocColor(handle->display, handle->colormap, &xc);
|
||||
|
||||
c->pixel = xc.pixel;
|
||||
} else {
|
||||
c->pixel = generate_color(handle, r, g, b);
|
||||
}
|
||||
c->red = r;
|
||||
c->green = g;
|
||||
c->blue = b;
|
||||
MwLLColorUpdate(handle, c, r, g, b);
|
||||
return c;
|
||||
}
|
||||
|
||||
void MwLLColorUpdate(MwLL handle, int r, int g, int b, MwLLColor c) {
|
||||
void MwLLColorUpdate(MwLL handle, MwLLColor c, int r, int g, int b) {
|
||||
XColor xc;
|
||||
|
||||
if(handle->red_mask == 0) {
|
||||
@@ -455,7 +434,6 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei
|
||||
MwLLPixmap r = malloc(sizeof(*r));
|
||||
char* di = malloc(4 * width * height);
|
||||
char* dm = malloc(4 * width * height);
|
||||
int y, x;
|
||||
int evbase, erbase;
|
||||
XWindowAttributes attr;
|
||||
|
||||
@@ -481,22 +459,20 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei
|
||||
|
||||
void MwLLPixmapUpdate(MwLL handle, MwLLPixmap r) {
|
||||
int y, x;
|
||||
MwLLColor c = NULL;
|
||||
for(y = 0; y < r->height; y++) {
|
||||
for(x = 0; x < r->width; x++) {
|
||||
unsigned char* px = &r->data_buf[(y * r->width + x) * 4];
|
||||
if(c == NULL) {
|
||||
c = MwLLAllocColor(handle, px[0], px[1], px[2]);
|
||||
} else {
|
||||
MwLLColorUpdate(handle, px[0], px[1], px[2], c);
|
||||
}
|
||||
unsigned long p = c->pixel;
|
||||
MwLLColor c = NULL;
|
||||
unsigned long p;
|
||||
|
||||
c = MwLLAllocColor(handle, px[0], px[1], px[2]);
|
||||
p = c->pixel;
|
||||
MwLLFreeColor(c);
|
||||
|
||||
XPutPixel(r->image, x, y, p);
|
||||
*(unsigned long*)(&r->data[(y * r->width + x) * sizeof(unsigned long)]) = (px[3] << 24) | p;
|
||||
}
|
||||
}
|
||||
MwLLFreeColor(c);
|
||||
|
||||
for(y = 0; y < r->height; y++) {
|
||||
for(x = 0; x < r->width; x++) {
|
||||
|
||||
@@ -65,19 +65,4 @@ struct _MwLLPixmap {
|
||||
XImage* mask;
|
||||
};
|
||||
|
||||
#ifdef HAS_FREETYPE
|
||||
void print_ft_error(void* ftLib, FT_Error err);
|
||||
#define MwFreeTypeFontSize 181388
|
||||
extern FT_Byte MwFreeTypeFontData[MwFreeTypeFontSize];
|
||||
|
||||
#define FT_WITH_FUNC(handle, func, block) \
|
||||
{ \
|
||||
_##func = dlsym(handle->ftLib, #func); \
|
||||
if(_##func != NULL) { \
|
||||
block \
|
||||
} else \
|
||||
printf("[WARNING] Unable to resolve function " #func ".\n"); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <Mw/LowLevelMath.h>
|
||||
|
||||
static void hsv2rgb(MwU32 h, MwU32 s, MwU32 v, MwU32* r, MwU32* g, MwU32* b) {
|
||||
uint8_t sextant = h >> 8;
|
||||
MwU8 sextant = h >> 8;
|
||||
MwU16 ww;
|
||||
MwU32 h_fraction, d;
|
||||
|
||||
#define HSV_SWAPPTR(a, b) \
|
||||
do { \
|
||||
@@ -39,14 +41,12 @@ static void hsv2rgb(MwU32 h, MwU32 s, MwU32 v, MwU32* r, MwU32* g, MwU32* b) {
|
||||
* Bottom level: v * (1.0 - s)
|
||||
* --> (v * (255 - s) + error_corr + 1) / 256
|
||||
*/
|
||||
uint16_t ww; // Intermediate result
|
||||
ww = v * (255 - (s)); // We don't use ~s to prevent size-promotion side effects
|
||||
ww += 1; // Error correction
|
||||
ww += ww >> 8; // Error correction
|
||||
*b = ww >> 8;
|
||||
|
||||
MwU32 h_fraction = h & 0xff; // 0...255
|
||||
MwU32 d; // Intermediate result
|
||||
h_fraction = h & 0xff; // 0...255
|
||||
|
||||
if(!(sextant & 1)) {
|
||||
// *r = ...slope_up...;
|
||||
@@ -62,17 +62,17 @@ static void hsv2rgb(MwU32 h, MwU32 s, MwU32 v, MwU32* r, MwU32* g, MwU32* b) {
|
||||
|
||||
static void color_picker_image_update(color_picker* picker) {
|
||||
int y, x;
|
||||
double h;
|
||||
for(y = 0; y < PICKER_SIZE; y++) {
|
||||
for(x = 0; x < PICKER_SIZE; x++) {
|
||||
int i = ((y * PICKER_SIZE) + x) * 4;
|
||||
int _x = x - (PICKER_SIZE / 2);
|
||||
int _y = y - (PICKER_SIZE / 2);
|
||||
double dist;
|
||||
|
||||
if(picker->dist_table[y][x] == 0) {
|
||||
picker->dist_table[y][x] = sqrt(_x * _x + _y * _y);
|
||||
}
|
||||
double dist = picker->dist_table[y][x];
|
||||
dist = picker->dist_table[y][x];
|
||||
|
||||
if(dist >= 180.) {
|
||||
picker->color_picker_image_data[i] = 0;
|
||||
@@ -101,11 +101,11 @@ static void color_picker_image_update(color_picker* picker) {
|
||||
hsv_v.v = HSV_VAL_MAX - (picker->value * HSV_VAL_MAX);
|
||||
|
||||
MwRGB color;
|
||||
hsv2rgb(hsv_v.h, hsv_v.s, hsv_v.v, &color.r, &color.g, &color.b);
|
||||
hsv2rgb(hsv_v.h, hsv_v.s, hsv_v.v, &color.red, &color.green, &color.blue);
|
||||
|
||||
picker->color_picker_image_data[i] = color.r;
|
||||
picker->color_picker_image_data[i + 1] = color.g;
|
||||
picker->color_picker_image_data[i + 2] = color.b;
|
||||
picker->color_picker_image_data[i] = color.red;
|
||||
picker->color_picker_image_data[i + 1] = color.green;
|
||||
picker->color_picker_image_data[i + 2] = color.blue;
|
||||
|
||||
picker->color_picker_image_data[i + 3] = 255;
|
||||
}
|
||||
@@ -137,15 +137,15 @@ static void color_picker_click(MwWidget handle, void* user, void* call) {
|
||||
|
||||
i = ((mouse->point.y * PICKER_SIZE) + mouse->point.x) * 4;
|
||||
|
||||
picker->chosen_color.r = picker->color_picker_image_data[i];
|
||||
picker->chosen_color.g = picker->color_picker_image_data[i + 1];
|
||||
picker->chosen_color.b = picker->color_picker_image_data[i + 2];
|
||||
picker->chosen_color.red = picker->color_picker_image_data[i];
|
||||
picker->chosen_color.green = picker->color_picker_image_data[i + 1];
|
||||
picker->chosen_color.blue = picker->color_picker_image_data[i + 2];
|
||||
|
||||
sprintf(hexColor, "#%02X%02X%02X", picker->chosen_color.r, picker->chosen_color.g, picker->chosen_color.b);
|
||||
sprintf(hexColor, "#%02X%02X%02X", picker->chosen_color.red, picker->chosen_color.green, picker->chosen_color.blue);
|
||||
|
||||
fr = picker->chosen_color.r > 128 ? 0 : 255;
|
||||
fg = picker->chosen_color.g > 128 ? 0 : 255;
|
||||
fb = picker->chosen_color.b > 128 ? 0 : 255;
|
||||
fr = picker->chosen_color.red > 128 ? 0 : 255;
|
||||
fg = picker->chosen_color.green > 128 ? 0 : 255;
|
||||
fb = picker->chosen_color.blue > 128 ? 0 : 255;
|
||||
|
||||
sprintf(fgColor, "#%02X%02X%02X", fr, fg, fb);
|
||||
MwSetText(picker->color_display, MwNbackground, hexColor);
|
||||
@@ -172,16 +172,14 @@ static void color_picker_on_change_value(MwWidget handle, void* user,
|
||||
static void color_picker_destroy(color_picker* picker) {
|
||||
free(picker->color_picker_image_data);
|
||||
MwLLDestroyPixmap(picker->color_picker_pixmap);
|
||||
|
||||
MwDestroyWidget(picker->color_display_text);
|
||||
MwDestroyWidget(picker->color_display);
|
||||
MwDestroyWidget(picker->value_slider);
|
||||
MwDestroyWidget(picker->color_picker_img);
|
||||
}
|
||||
|
||||
static void color_picker_close(MwWidget handle, void* user,
|
||||
void* call) {
|
||||
color_picker* picker = (color_picker*)user;
|
||||
|
||||
(void)call;
|
||||
|
||||
color_picker_destroy(picker);
|
||||
MwDestroyWidget(handle);
|
||||
}
|
||||
@@ -190,7 +188,9 @@ static void color_picker_finish(MwWidget handle, void* user,
|
||||
void* call) {
|
||||
color_picker* picker = (color_picker*)user;
|
||||
|
||||
picker->cb(picker->chosen_color);
|
||||
(void)call;
|
||||
|
||||
MwDispatchUserHandler(picker->parent, MwNcolorChosenHandler, &picker->chosen_color);
|
||||
|
||||
color_picker_destroy(picker);
|
||||
MwDestroyWidget(handle->parent);
|
||||
@@ -264,8 +264,9 @@ color_picker* color_picker_setup(MwWidget parent, int w, int h) {
|
||||
memset(picker->hue_table, 0, sizeof(picker->hue_table));
|
||||
|
||||
return picker;
|
||||
};
|
||||
MwWidget MwColorPicker(MwWidget handle, const char* title, MwColorPickerCallback cb) {
|
||||
}
|
||||
|
||||
MwWidget MwColorPicker(MwWidget handle, const char* title) {
|
||||
MwPoint p;
|
||||
color_picker* wheel;
|
||||
MwWidget window;
|
||||
@@ -282,7 +283,5 @@ MwWidget MwColorPicker(MwWidget handle, const char* title, MwColorPickerCallback
|
||||
MwLLDetach(window->lowlevel, &p);
|
||||
MwLLMakePopup(window->lowlevel, handle->lowlevel);
|
||||
|
||||
wheel->cb = cb;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ struct _color_picker {
|
||||
MwPoint point;
|
||||
double dist_table[PICKER_SIZE][PICKER_SIZE];
|
||||
MwHSV hue_table[PICKER_SIZE][PICKER_SIZE];
|
||||
MwColorPickerCallback cb;
|
||||
MwRGB chosen_color;
|
||||
};
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ MAKE_DEFAULT_TABLE(i16, MwI16);
|
||||
MAKE_DEFAULT_TABLE(i32, MwI32);
|
||||
MAKE_DEFAULT_TABLE(i64, MwI64);
|
||||
|
||||
#if 0
|
||||
static MwLLMathVTable* defaultMultiTable[MwLLVecType_Max] = {
|
||||
&table_u8, /*MwLLVecTypeU8*/
|
||||
&table_u16, /*MwLLVecTypeU16*/
|
||||
@@ -78,6 +79,7 @@ static MwLLMathVTable* defaultMultiTable[MwLLVecType_Max] = {
|
||||
&table_i32, /*MwLLVecTypeI32*/
|
||||
&table_i64, /*MwLLVecTypeI64*/
|
||||
};
|
||||
#endif
|
||||
void default_apply(MwLLVec* v) {
|
||||
switch(v->ty) {
|
||||
case MwLLVecTypeU8:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define DO_MMX_INTRINSIC(intrin, _ty, _cty) \
|
||||
int i = 0; \
|
||||
for(; i < a->size; i += 8) { \
|
||||
__m64 m = intrin(*(__m64*)&a->buffer[i], *(__m64*)&b->buffer[i]); \
|
||||
__m64 m = intrin(((__m64*)a->buffer)[i], ((__m64*)b->buffer)[i]); \
|
||||
memcpy(&((_cty*)out->buffer)[i], &m, sizeof(m)); \
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user