mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-10 11:23:29 +00:00
add MwNlength
This commit is contained in:
@@ -14,6 +14,7 @@ int main() {
|
|||||||
MwNtext, " 123456:78.90 abcdef",
|
MwNtext, " 123456:78.90 abcdef",
|
||||||
MwNsevenSegment, 1,
|
MwNsevenSegment, 1,
|
||||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||||
|
MwNlength, 8,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
MwLabelSetSevenSegment(label, 0, (1 << 0) | (1 << 3) | (1 << 6));
|
MwLabelSetSevenSegment(label, 0, (1 << 0) | (1 << 3) | (1 << 6));
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#define MwNmargin "Imargin"
|
#define MwNmargin "Imargin"
|
||||||
#define MwNbitmapFont "IbitmapFont"
|
#define MwNbitmapFont "IbitmapFont"
|
||||||
#define MwNsevenSegment "IsevenSegment"
|
#define MwNsevenSegment "IsevenSegment"
|
||||||
|
#define MwNlength "Ilength"
|
||||||
|
|
||||||
#define MwNtitle "Stitle"
|
#define MwNtitle "Stitle"
|
||||||
#define MwNtext "Stext"
|
#define MwNtext "Stext"
|
||||||
|
|||||||
@@ -90,6 +90,7 @@
|
|||||||
<integer name="margin" />
|
<integer name="margin" />
|
||||||
<integer name="bitmapFont" />
|
<integer name="bitmapFont" />
|
||||||
<integer name="sevenSegment" />
|
<integer name="sevenSegment" />
|
||||||
|
<integer name="length" />
|
||||||
|
|
||||||
<string name="title" />
|
<string name="title" />
|
||||||
<string name="text" />
|
<string name="text" />
|
||||||
@@ -538,6 +539,7 @@
|
|||||||
<property name="alignment" />
|
<property name="alignment" />
|
||||||
<property name="bold" />
|
<property name="bold" />
|
||||||
<property name="sevenSegment" />
|
<property name="sevenSegment" />
|
||||||
|
<property name="length" />
|
||||||
</properties>
|
</properties>
|
||||||
<functions>
|
<functions>
|
||||||
<function name="SetSevenSegment">
|
<function name="SetSevenSegment">
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
#include "../../external/stb_ds.h"
|
#include "../../external/stb_ds.h"
|
||||||
|
|
||||||
#define ShortOne 5
|
#define Spacing 1
|
||||||
#define LongOne 10
|
|
||||||
#define Spacing 2
|
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
MwLabel lab = malloc(sizeof(*lab));
|
MwLabel lab = malloc(sizeof(*lab));
|
||||||
@@ -16,6 +14,7 @@ static int create(MwWidget handle) {
|
|||||||
MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER);
|
MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER);
|
||||||
MwSetInteger(handle, MwNbold, 0);
|
MwSetInteger(handle, MwNbold, 0);
|
||||||
MwSetInteger(handle, MwNsevenSegment, 0);
|
MwSetInteger(handle, MwNsevenSegment, 0);
|
||||||
|
MwSetInteger(handle, MwNlength, 4);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -28,10 +27,14 @@ static void destroy(MwWidget handle) {
|
|||||||
free(handle->internal);
|
free(handle->internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_v(unsigned char* raw, int x, int y, int stride, MwLLColor text) {
|
static void draw_v(MwWidget handle, unsigned char* raw, int x, int y, int stride, MwLLColor text) {
|
||||||
int cy, cx, b;
|
int cy, cx, b;
|
||||||
for(cy = y; cy < y + LongOne; cy++) {
|
|
||||||
for(cx = x; cx < x + ShortOne; cx++) {
|
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
|
||||||
|
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
|
||||||
|
|
||||||
|
for(cy = y; cy < y + l_one; cy++) {
|
||||||
|
for(cx = x; cx < x + s_one; cx++) {
|
||||||
unsigned char* px = &raw[(cy * stride + cx) * 4];
|
unsigned char* px = &raw[(cy * stride + cx) * 4];
|
||||||
px[0] = text->common.red;
|
px[0] = text->common.red;
|
||||||
px[1] = text->common.green;
|
px[1] = text->common.green;
|
||||||
@@ -40,10 +43,10 @@ static void draw_v(unsigned char* raw, int x, int y, int stride, MwLLColor text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b = y - (ShortOne - 1) / 2;
|
b = y - (s_one - 1) / 2;
|
||||||
for(cy = b; cy < b + (ShortOne - 1) / 2; cy++) {
|
for(cy = b; cy < b + (s_one - 1) / 2; cy++) {
|
||||||
int w = (cy - b) * 2 + 1;
|
int w = (cy - b) * 2 + 1;
|
||||||
int b2 = x + (ShortOne - w) / 2;
|
int b2 = x + (s_one - w) / 2;
|
||||||
for(cx = b2; cx < b2 + w; cx++) {
|
for(cx = b2; cx < b2 + w; cx++) {
|
||||||
unsigned char* px;
|
unsigned char* px;
|
||||||
|
|
||||||
@@ -55,10 +58,10 @@ static void draw_v(unsigned char* raw, int x, int y, int stride, MwLLColor text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b = y + LongOne;
|
b = y + l_one;
|
||||||
for(cy = b; cy < b + (ShortOne - 1) / 2; cy++) {
|
for(cy = b; cy < b + (s_one - 1) / 2; cy++) {
|
||||||
int w = ((ShortOne - 1) / 2 - 1 - (cy - b)) * 2 + 1;
|
int w = ((s_one - 1) / 2 - 1 - (cy - b)) * 2 + 1;
|
||||||
int b2 = x + (ShortOne - w) / 2;
|
int b2 = x + (s_one - w) / 2;
|
||||||
for(cx = b2; cx < b2 + w; cx++) {
|
for(cx = b2; cx < b2 + w; cx++) {
|
||||||
unsigned char* px;
|
unsigned char* px;
|
||||||
|
|
||||||
@@ -71,10 +74,14 @@ static void draw_v(unsigned char* raw, int x, int y, int stride, MwLLColor text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_h(unsigned char* raw, int x, int y, int stride, MwLLColor text) {
|
static void draw_h(MwWidget handle, unsigned char* raw, int x, int y, int stride, MwLLColor text) {
|
||||||
int cy, cx, b;
|
int cy, cx, b;
|
||||||
for(cx = x; cx < x + LongOne; cx++) {
|
|
||||||
for(cy = y; cy < y + ShortOne; cy++) {
|
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
|
||||||
|
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
|
||||||
|
|
||||||
|
for(cx = x; cx < x + l_one; cx++) {
|
||||||
|
for(cy = y; cy < y + s_one; cy++) {
|
||||||
unsigned char* px = &raw[(cy * stride + cx) * 4];
|
unsigned char* px = &raw[(cy * stride + cx) * 4];
|
||||||
px[0] = text->common.red;
|
px[0] = text->common.red;
|
||||||
px[1] = text->common.green;
|
px[1] = text->common.green;
|
||||||
@@ -83,10 +90,10 @@ static void draw_h(unsigned char* raw, int x, int y, int stride, MwLLColor text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b = x - (ShortOne - 1) / 2;
|
b = x - (s_one - 1) / 2;
|
||||||
for(cx = b; cx < b + (ShortOne - 1) / 2; cx++) {
|
for(cx = b; cx < b + (s_one - 1) / 2; cx++) {
|
||||||
int w = (cx - b) * 2 + 1;
|
int w = (cx - b) * 2 + 1;
|
||||||
int b2 = y + (ShortOne - w) / 2;
|
int b2 = y + (s_one - w) / 2;
|
||||||
for(cy = b2; cy < b2 + w; cy++) {
|
for(cy = b2; cy < b2 + w; cy++) {
|
||||||
unsigned char* px;
|
unsigned char* px;
|
||||||
|
|
||||||
@@ -98,10 +105,10 @@ static void draw_h(unsigned char* raw, int x, int y, int stride, MwLLColor text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b = x + LongOne;
|
b = x + l_one;
|
||||||
for(cx = b; cx < b + (ShortOne - 1) / 2; cx++) {
|
for(cx = b; cx < b + (s_one - 1) / 2; cx++) {
|
||||||
int w = ((ShortOne - 1) / 2 - 1 - (cx - b)) * 2 + 1;
|
int w = ((s_one - 1) / 2 - 1 - (cx - b)) * 2 + 1;
|
||||||
int b2 = y + (ShortOne - w) / 2;
|
int b2 = y + (s_one - w) / 2;
|
||||||
for(cy = b2; cy < b2 + w; cy++) {
|
for(cy = b2; cy < b2 + w; cy++) {
|
||||||
unsigned char* px;
|
unsigned char* px;
|
||||||
|
|
||||||
@@ -117,12 +124,15 @@ static void draw_h(unsigned char* raw, int x, int y, int stride, MwLLColor text)
|
|||||||
static void draw(MwWidget handle) {
|
static void draw(MwWidget handle) {
|
||||||
MwRect r;
|
MwRect r;
|
||||||
MwPoint p;
|
MwPoint p;
|
||||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||||
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||||
|
MwLLColor shadow = MwLightenColor(handle, base, -32, -32, -32);
|
||||||
int align;
|
int align;
|
||||||
const char* str = MwGetText(handle, MwNtext);
|
const char* str = MwGetText(handle, MwNtext);
|
||||||
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
|
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
|
||||||
MwLabel lab = handle->internal;
|
MwLabel lab = handle->internal;
|
||||||
|
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
|
||||||
|
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
|
||||||
|
|
||||||
if(str == NULL) str = "";
|
if(str == NULL) str = "";
|
||||||
|
|
||||||
@@ -138,7 +148,7 @@ static void draw(MwWidget handle) {
|
|||||||
if(MwGetInteger(handle, MwNsevenSegment)) {
|
if(MwGetInteger(handle, MwNsevenSegment)) {
|
||||||
MwLLPixmap px;
|
MwLLPixmap px;
|
||||||
unsigned char* raw;
|
unsigned char* raw;
|
||||||
int w = 0, h = ShortOne * 3 + LongOne * 2, i;
|
int w = 0, h = s_one * 3 + l_one * 2, i;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
||||||
/* so - this mode cannot do unicode.
|
/* so - this mode cannot do unicode.
|
||||||
@@ -159,18 +169,22 @@ static void draw(MwWidget handle) {
|
|||||||
for(i = 0; (hmgeti(lab->segment, i) != -1) || str[i] != 0; i++) {
|
for(i = 0; (hmgeti(lab->segment, i) != -1) || str[i] != 0; i++) {
|
||||||
if(i > 0 && ((hmgeti(lab->segment, i) != -1) || str[i] != '.')) w += Spacing;
|
if(i > 0 && ((hmgeti(lab->segment, i) != -1) || str[i] != '.')) w += Spacing;
|
||||||
if(hmgeti(lab->segment, i) != -1 || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
|
if(hmgeti(lab->segment, i) != -1 || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
|
||||||
w += LongOne + ShortOne * 2;
|
w += l_one + s_one * 2;
|
||||||
} else if(str[i] == ':' || str[i] == ' ') {
|
} else if(str[i] == ':' || str[i] == ' ') {
|
||||||
w += ShortOne;
|
w += s_one;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w++;
|
||||||
|
h++;
|
||||||
|
|
||||||
raw = malloc(w * h * 4);
|
raw = malloc(w * h * 4);
|
||||||
memset(raw, 0, w * h * 4);
|
memset(raw, 0, w * h * 4);
|
||||||
|
|
||||||
for(i = 0; (hmgeti(lab->segment, i) != -1) || str[i] != 0; i++) {
|
for(i = 0; (hmgeti(lab->segment, i) != -1) || str[i] != 0; i++) {
|
||||||
if((hmgeti(lab->segment, i) != -1) || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
|
if((hmgeti(lab->segment, i) != -1) || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
|
||||||
int la = 0, lb = 0, lc = 0, ld = 0, le = 0, lf = 0, lg = 0;
|
int la = 0, lb = 0, lc = 0, ld = 0, le = 0, lf = 0, lg = 0;
|
||||||
|
int j;
|
||||||
|
|
||||||
/* https://en.wikipedia.org/wiki/File:7_Segment_Display_with_Labeled_Segments.svg */
|
/* https://en.wikipedia.org/wiki/File:7_Segment_Display_with_Labeled_Segments.svg */
|
||||||
|
|
||||||
@@ -220,45 +234,57 @@ static void draw(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(la) draw_h(raw, x + ShortOne, 0, w, text);
|
for(j = 1; j >= 0; j--) {
|
||||||
if(lb) draw_v(raw, x + ShortOne + LongOne, ShortOne, w, text);
|
MwLLColor cl = j == 1 ? shadow : text;
|
||||||
if(lc) draw_v(raw, x + ShortOne + LongOne, ShortOne * 2 + LongOne, w, text);
|
|
||||||
if(ld) draw_h(raw, x + ShortOne, ShortOne * 2 + LongOne * 2, w, text);
|
|
||||||
if(le) draw_v(raw, x, ShortOne * 2 + LongOne, w, text);
|
|
||||||
if(lf) draw_v(raw, x, ShortOne, w, text);
|
|
||||||
if(lg) draw_h(raw, x + ShortOne, ShortOne + LongOne, w, text);
|
|
||||||
|
|
||||||
x += LongOne + ShortOne * 2;
|
if(la) draw_h(handle, raw, x + s_one + j, j, w, cl);
|
||||||
|
if(lb) draw_v(handle, raw, x + s_one + l_one + j, s_one + j, w, cl);
|
||||||
|
if(lc) draw_v(handle, raw, x + s_one + l_one + j, s_one * 2 + l_one + j, w, cl);
|
||||||
|
if(ld) draw_h(handle, raw, x + s_one + j, s_one * 2 + l_one * 2 + j, w, cl);
|
||||||
|
if(le) draw_v(handle, raw, x + j, s_one * 2 + l_one + j, w, cl);
|
||||||
|
if(lf) draw_v(handle, raw, x + j, s_one + j, w, cl);
|
||||||
|
if(lg) draw_h(handle, raw, x + s_one + j, s_one + l_one + j, w, cl);
|
||||||
|
}
|
||||||
|
|
||||||
|
x += l_one + s_one * 2;
|
||||||
} else if(str[i] == ':') {
|
} else if(str[i] == ':') {
|
||||||
int cy, cx;
|
int cy, cx;
|
||||||
for(cy = 1; cy < h - 1; cy++) {
|
int j;
|
||||||
int c = (LongOne - ShortOne) / 2 + ShortOne;
|
for(j = 1; j >= 0; j--) {
|
||||||
|
MwLLColor cl = j == 1 ? shadow : text;
|
||||||
|
for(cy = 1; cy < h - 1; cy++) {
|
||||||
|
int c = (l_one - s_one) / 2 + s_one;
|
||||||
|
|
||||||
int c1 = (c <= cy && cy <= (c + ShortOne)) ? 1 : 0;
|
int c1 = (c <= cy && cy <= (c + s_one)) ? 1 : 0;
|
||||||
int c2 = ((ShortOne + LongOne + c) <= cy && cy <= (ShortOne + LongOne + c + ShortOne)) ? 1 : 0;
|
int c2 = ((s_one + l_one + c) <= cy && cy <= (s_one + l_one + c + s_one)) ? 1 : 0;
|
||||||
|
|
||||||
if(c1 || c2) {
|
if(c1 || c2) {
|
||||||
for(cx = x; cx < x + ShortOne; cx++) {
|
for(cx = x; cx < x + s_one; cx++) {
|
||||||
unsigned char* px = &raw[(cy * w + cx) * 4];
|
unsigned char* px = &raw[((cy + j) * w + (cx + j)) * 4];
|
||||||
px[0] = text->common.red;
|
px[0] = cl->common.red;
|
||||||
px[1] = text->common.green;
|
px[1] = cl->common.green;
|
||||||
px[2] = text->common.blue;
|
px[2] = cl->common.blue;
|
||||||
px[3] = 255;
|
px[3] = 255;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x += ShortOne;
|
x += s_one;
|
||||||
} else if(str[i] == ' ') {
|
} else if(str[i] == ' ') {
|
||||||
x += ShortOne;
|
x += s_one;
|
||||||
} else if(str[i] == '.') {
|
} else if(str[i] == '.') {
|
||||||
int cy, cx;
|
int cy, cx;
|
||||||
for(cy = h - (ShortOne - 1) / 2 - 1; cy < h; cy++) {
|
int j;
|
||||||
for(cx = x - Spacing - (ShortOne - 1) / 2 - 1; cx < (x - Spacing); cx++) {
|
for(j = 1; j >= 0; j--) {
|
||||||
unsigned char* px = &raw[(cy * w + cx) * 4];
|
MwLLColor cl = j == 1 ? shadow : text;
|
||||||
px[0] = text->common.red;
|
for(cy = h - (s_one - 1) / 2 - 1; cy < h; cy++) {
|
||||||
px[1] = text->common.green;
|
for(cx = x - Spacing - (s_one - 1) / 2 - 1; cx < (x - Spacing); cx++) {
|
||||||
px[2] = text->common.blue;
|
unsigned char* px = &raw[((cy + j) * w + (cx + j)) * 4];
|
||||||
px[3] = 255;
|
px[0] = cl->common.red;
|
||||||
|
px[1] = cl->common.green;
|
||||||
|
px[2] = cl->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -294,6 +320,7 @@ static void draw(MwWidget handle) {
|
|||||||
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
|
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MwLLFreeColor(shadow);
|
||||||
MwLLFreeColor(text);
|
MwLLFreeColor(text);
|
||||||
MwLLFreeColor(base);
|
MwLLFreeColor(base);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user