things
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-09-14 02:51:00 +09:00
commit d87569d7c0
7 changed files with 196 additions and 67 deletions

View file

@ -269,12 +269,17 @@ int main() {
wclock = child(f); wclock = child(f);
f = frame("Chart", -PaddingContent, -PaddingContent, MwChartClass, f = frame("Chart", -PaddingContent, -PaddingContent, MwChartClass,
MwNtype, MwCHART_3D_BAR,
MwNcolumnSpan, 2,
NULL); NULL);
w = child(f); w = child(f);
MwChartAdd(w, -1, "A", -100, NULL); MwChartAdd(w, -1, "A", -400, NULL);
MwChartAdd(w, -1, "B", 100, NULL); MwChartAdd(w, -1, "B", -200, NULL);
MwChartAdd(w, -1, "C", 200, NULL); MwChartAdd(w, -1, "C", -100, NULL);
MwChartAdd(w, -1, "D", 300, NULL); MwChartAdd(w, -1, "D", 100, NULL);
MwChartAdd(w, -1, "E", 200, NULL);
MwChartAdd(w, -1, "F", 400, NULL);
MwChartAdd(w, -1, "G", 800, NULL);
f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL); f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL);
w = child(f); w = child(f);
@ -288,6 +293,7 @@ int main() {
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass, f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
MwNtext, "Epic text\nNewline can be used too!", MwNtext, "Epic text\nNewline can be used too!",
MwNcolumnSpan, 2,
NULL); NULL);
f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass, f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass,
@ -321,9 +327,7 @@ int main() {
MwNtitle, "Sub window 2", MwNtitle, "Sub window 2",
NULL); NULL);
f = frame("Tab", -PaddingContent, -PaddingContent, MwTabClass, f = frame("Tab", -PaddingContent, -PaddingContent, MwTabClass, NULL);
MwNcolumnSpan, 2,
NULL);
w = child(f); w = child(f);
MwSetText(MwTabAdd(w, "ABC"), MwNbackground, "#f00"); MwSetText(MwTabAdd(w, "ABC"), MwNbackground, "#f00");
MwSetText(MwTabAdd(w, "DEF"), MwNbackground, "#0f0"); MwSetText(MwTabAdd(w, "DEF"), MwNbackground, "#0f0");

View file

@ -114,7 +114,8 @@ enum MwCLIPBOARD {
}; };
enum MwCHART { enum MwCHART {
MwCHART_BAR = 0 MwCHART_BAR = 0,
MwCHART_3D_BAR,
}; };
enum MwMOUSE { enum MwMOUSE {

View file

@ -52,6 +52,13 @@ MWDECL void MWAPI MwColorTableInit(void);
*/ */
MWDECL MwLLColor MWAPI MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b); MWDECL MwLLColor MWAPI MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b);
/*!
* @brief Fix a rectangle
* @param handle Widget
* @param rect Rectangle area
*/
MWDECL void MWAPI MwFixRect(MwRect* rect);
/*! /*!
* @brief Draws a filled rectangle * @brief Draws a filled rectangle
* @param handle Widget * @param handle Widget

View file

@ -232,6 +232,7 @@
</enumeration> </enumeration>
<enumeration name="MwCHART"> <enumeration name="MwCHART">
<integer name="MwCHART_BAR">0</integer> <integer name="MwCHART_BAR">0</integer>
<integer name="MwCHART_3D_BAR" />
</enumeration> </enumeration>
<enumeration name="MwMOUSE"> <enumeration name="MwMOUSE">
<integer name="MwMOUSE_LEFT">1</integer> <integer name="MwMOUSE_LEFT">1</integer>
@ -657,6 +658,8 @@
<widget name="Chart"> <widget name="Chart">
<properties> <properties>
<property name="type" /> <property name="type" />
<property name="minValue" />
<property name="maxValue" />
</properties> </properties>
<functions> <functions>
<function name="Set"> <function name="Set">

View file

@ -5,7 +5,7 @@
#ifdef USE_COCOA #ifdef USE_COCOA
#define PERIODIC #define PERIODIC
#endif #endif
#define USE_CLASSIC_THEME // #define USE_CLASSIC_THEME
#define RESIZE_ON_TICK #define RESIZE_ON_TICK
#define DRAW(handle) \ #define DRAW(handle) \

View file

@ -99,19 +99,23 @@ MwLLColor MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b)
return MwLLAllocColor(handle->lowlevel, cr, cg, cb); return MwLLAllocColor(handle->lowlevel, cr, cg, cb);
} }
void MwFixRect(MwRect* rect) {
if(rect->width < 0) {
rect->width *= -1;
rect->x -= rect->width;
}
if(rect->height < 0) {
rect->height *= -1;
rect->y -= rect->height;
}
}
void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) { void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) {
MwPoint p[4]; MwPoint p[4];
MwRect r = *rect; MwRect r = *rect;
if(r.width < 0) { MwFixRect(&r);
r.width *= -1;
r.x -= r.width;
}
if(r.height < 0) {
r.height *= -1;
r.y -= r.height;
}
p[0].x = r.x; p[0].x = r.x;
p[0].y = r.y; p[0].y = r.y;
@ -132,15 +136,7 @@ void MwDrawRectLine(MwWidget handle, MwRect* rect, MwLLColor color) {
MwPoint p[5]; MwPoint p[5];
MwRect r = *rect; MwRect r = *rect;
if(r.width < 0) { MwFixRect(&r);
r.width *= -1;
r.x -= r.width;
}
if(r.height < 0) {
r.height *= -1;
r.y -= r.height;
}
p[0].x = r.x; p[0].x = r.x;
p[0].y = r.y; p[0].y = r.y;

View file

@ -27,6 +27,8 @@ static int wcreate(MwWidget handle) {
MwSetDefault(handle); MwSetDefault(handle);
MwSetInteger(handle, MwNtype, MwCHART_BAR);
return 0; return 0;
} }
@ -35,6 +37,35 @@ static void destroy(MwWidget handle) {
free(handle->internal); free(handle->internal);
} }
static void draw_line(MwWidget handle, const char* text, double x, double y, double width, double height, MwLLColor color) {
MwPoint p[2];
int type = MwGetInteger(handle, MwNtype);
p[0].x = x;
p[0].y = y;
p[1].x = x + width;
p[1].y = p[0].y;
MwDrawText(handle, NULL, p, text, MwALIGNMENT_END, color);
if(type == MwCHART_3D_BAR) {
MwPoint p2[2];
p2[0] = p[0];
p2[1] = p[0];
p2[1].x += height;
p2[1].y -= height;
MwLLLine(handle->lowlevel, &p2[0], color);
p[0].x += height;
p[0].y -= height;
p[1].y -= height;
}
MwLLLine(handle->lowlevel, &p[0], color);
}
static void draw(MwWidget handle) { static void draw(MwWidget handle) {
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
MwLLColor border = MwParseColor(handle, MwGetText(handle, MwNforeground)); MwLLColor border = MwParseColor(handle, MwGetText(handle, MwNforeground));
@ -46,47 +77,62 @@ static void draw(MwWidget handle) {
int gap; int gap;
int width; int width;
MwRect node; MwRect node;
double min = 0xffffffff; double vmin = 0xffffffff;
double max = -0xffffffff; double vmax = -0xffffffff;
int space = MwTextHeight(handle, NULL, "M"); int space = MwTextHeight(handle, NULL, "M");
MwPoint p[2]; MwPoint p[2];
int type = MwGetInteger(handle, MwNtype);
for(n = 0; colors[n] != NULL; n++); for(n = 0; colors[n] != NULL; n++);
for(i = 0; i < arrlen(c->entries); i++) { for(i = 0; i < arrlen(c->entries); i++) {
if(min > c->entries[i].value) min = c->entries[i].value; if(vmin > c->entries[i].value) vmin = c->entries[i].value;
if(max < c->entries[i].value) max = c->entries[i].value; if(vmax < c->entries[i].value) vmax = c->entries[i].value;
} }
if(MwGetInteger(handle, MwNminValue) != MwDEFAULT) vmin = MwGetInteger(handle, MwNminValue);
if(MwGetInteger(handle, MwNmaxValue) != MwDEFAULT) vmax = MwGetInteger(handle, MwNmaxValue);
r.x = 0; r.x = 0;
r.y = 0; r.y = 0;
r.width = MwGetInteger(handle, MwNwidth); r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight); r.height = MwGetInteger(handle, MwNheight);
MwDrawRect(handle, &r, base); MwDrawRect(handle, &r, base);
if(min > 0) { if(type == MwCHART_BAR || type == MwCHART_3D_BAR) {
min = 0; double s = 1.5;
} else if(min < 0) { double ovmin = vmin;
min -= r.height / 10; double ovmax = vmax;
} double twidth;
char buf[128];
node.x = 16; node.x = 128;
node.y = 0; node.y = 0;
width = (r.width - node.x) * 2 / (arrlen(c->entries) * 3 + 1); width = (r.width - node.x) * s / (arrlen(c->entries) * (1 + s) + 1);
gap = width / 2; gap = width / s;
p[0].x = node.x; twidth = (width + gap) * arrlen(c->entries) + gap;
p[0].y = r.height - space;
p[1].x = node.x + (width + gap) * arrlen(c->entries) + gap; if(vmin > 0) {
p[1].y = p[0].y; vmin = 0;
MwLLLine(handle->lowlevel, &p[0], border); } else if(vmin < 0) {
vmin -= (double)width / r.height * (vmax - vmin);
}
p[0].y = r.height - space - abs(min / (max - min) * (r.height - space)); if(vmax < 0) {
p[1].y = p[0].y; vmax = 0;
MwLLLine(handle->lowlevel, &p[0], border); } else if(vmax > 0) {
MwDrawText(handle, NULL, p, "0", MwALIGNMENT_END, border); vmax += (double)width / r.height * (vmax - vmin);
}
sprintf(buf, "%.2f", ovmax);
draw_line(handle, buf, node.x, (r.height - space) - (ovmax - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
draw_line(handle, "0", node.x, (r.height - space) - (0 - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
sprintf(buf, "%.2f", ovmin);
draw_line(handle, buf, node.x, (r.height - space) - (ovmin - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
p[0].x = node.x; p[0].x = node.x;
p[0].y = 0; p[0].y = 0;
@ -95,18 +141,87 @@ static void draw(MwWidget handle) {
p[1].y = r.height - space; p[1].y = r.height - space;
MwLLLine(handle->lowlevel, &p[0], border); MwLLLine(handle->lowlevel, &p[0], border);
p[0].x = node.x;
p[0].y = r.height - space;
p[1].x = node.x + twidth;
p[1].y = p[0].y;
MwLLLine(handle->lowlevel, &p[0], border);
node.width = width; node.width = width;
for(i = 0; i < arrlen(c->entries); i++) { for(i = 0; i < arrlen(c->entries); i++) {
int ColorDiff = MwGetColorDifference(handle);
MwLLColor color = MwParseColor(handle, c->entries[i].color == NULL ? colors[i % n] : c->entries[i].color); MwLLColor color = MwParseColor(handle, c->entries[i].color == NULL ? colors[i % n] : c->entries[i].color);
MwLLColor colorl = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
MwLLColor colord = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
MwPoint persp_top[5];
MwPoint persp_right[5];
node.x += gap; node.x += gap;
node.height = c->entries[i].value / (max - min) * (r.height - space); node.height = -c->entries[i].value / (vmax - vmin) * (r.height - space);
node.y = r.height - space - node.height - abs(min / (max - min) * (r.height - space)); node.y = (r.height - space) - (0 - vmin) / (vmax - vmin) * (r.height - space);
MwDrawRect(handle, &node, color); MwDrawRect(handle, &node, color);
if(type == MwCHART_3D_BAR) {
MwRect node2 = node;
MwFixRect(&node2);
persp_top[0] = *(MwPoint*)&node2;
persp_top[1] = *(MwPoint*)&node2;
persp_top[1].x += node2.width;
persp_top[2] = persp_top[1];
persp_top[3] = persp_top[0];
persp_top[2].x += node2.width / 2;
persp_top[2].y -= node2.width / 2;
persp_top[3].x += node2.width / 2;
persp_top[3].y -= node2.width / 2;
persp_top[4] = persp_top[0];
MwLLPolygon(handle->lowlevel, persp_top, 4, colorl);
persp_right[0] = *(MwPoint*)&node2;
persp_right[1] = *(MwPoint*)&node2;
persp_right[0].x += node2.width;
persp_right[1].x += node2.width;
persp_right[1].y += node2.height;
persp_right[2] = persp_right[1];
persp_right[3] = persp_right[0];
persp_right[2].x += node2.width / 2;
persp_right[2].y -= node2.width / 2;
persp_right[3].x += node2.width / 2;
persp_right[3].y -= node2.width / 2;
persp_right[4] = persp_right[0];
MwLLPolygon(handle->lowlevel, persp_right, 4, colord);
}
if(!MwGetInteger(handle, MwNmodernLook)) {
MwDrawRectLine(handle, &node, border); MwDrawRectLine(handle, &node, border);
if(type == MwCHART_3D_BAR) {
MwLLLine(handle->lowlevel, &persp_top[0], border);
MwLLLine(handle->lowlevel, &persp_top[1], border);
MwLLLine(handle->lowlevel, &persp_top[2], border);
MwLLLine(handle->lowlevel, &persp_top[3], border);
MwLLLine(handle->lowlevel, &persp_right[0], border);
MwLLLine(handle->lowlevel, &persp_right[1], border);
MwLLLine(handle->lowlevel, &persp_right[2], border);
MwLLLine(handle->lowlevel, &persp_right[3], border);
}
}
p[0].x = node.x + node.width / 2; p[0].x = node.x + node.width / 2;
p[0].y = r.height - space / 2; p[0].y = r.height - space / 2;
@ -114,8 +229,11 @@ static void draw(MwWidget handle) {
node.x += node.width; node.x += node.width;
MwLLFreeColor(colord);
MwLLFreeColor(colorl);
MwLLFreeColor(color); MwLLFreeColor(color);
} }
}
MwLLFreeColor(border); MwLLFreeColor(border);
MwLLFreeColor(base); MwLLFreeColor(base);