mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-04 08:30:51 +00:00
Compare commits
5 Commits
a67a0c11f8
...
188da6803e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
188da6803e | ||
|
|
2304b493d1 | ||
|
|
91d9677bf7 | ||
|
|
f09960195f | ||
|
|
ab9d0ffc5f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,4 +11,5 @@ examples/*/*.exe
|
|||||||
*.lib
|
*.lib
|
||||||
*.a
|
*.a
|
||||||
/Makefile
|
/Makefile
|
||||||
|
/build
|
||||||
compile_flags.txt
|
compile_flags.txt
|
||||||
|
|||||||
23
examples/basic/sevensegment.c
Normal file
23
examples/basic/sevensegment.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
MwWidget wnd, label;
|
||||||
|
int W = 480, H = 40;
|
||||||
|
|
||||||
|
MwLibraryInit();
|
||||||
|
|
||||||
|
wnd = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, W, H,
|
||||||
|
MwNtitle, "seven segment",
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
label = MwVaCreateWidget(MwLabelClass, "label", wnd, 0, 0, W, H,
|
||||||
|
MwNtext, " 123456:78.90 abcdef",
|
||||||
|
MwNsevenSegment, 1,
|
||||||
|
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||||
|
MwNlength, 8,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
MwLabelSetSevenSegment(label, 0, (1 << 0) | (1 << 3) | (1 << 6));
|
||||||
|
|
||||||
|
MwLoop(wnd);
|
||||||
|
}
|
||||||
@@ -36,6 +36,8 @@
|
|||||||
#define MwNfixedSize "IfixedSize"
|
#define MwNfixedSize "IfixedSize"
|
||||||
#define MwNmargin "Imargin"
|
#define MwNmargin "Imargin"
|
||||||
#define MwNbitmapFont "IbitmapFont"
|
#define MwNbitmapFont "IbitmapFont"
|
||||||
|
#define MwNsevenSegment "IsevenSegment"
|
||||||
|
#define MwNlength "Ilength"
|
||||||
|
|
||||||
#define MwNtitle "Stitle"
|
#define MwNtitle "Stitle"
|
||||||
#define MwNtext "Stext"
|
#define MwNtext "Stext"
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ typedef struct _MwViewport* MwViewport;
|
|||||||
typedef struct _MwListBox* MwListBox;
|
typedef struct _MwListBox* MwListBox;
|
||||||
typedef struct _MwComboBox* MwComboBox;
|
typedef struct _MwComboBox* MwComboBox;
|
||||||
typedef struct _MwTreeView* MwTreeView;
|
typedef struct _MwTreeView* MwTreeView;
|
||||||
|
typedef struct _MwScrollBar* MwScrollBar;
|
||||||
|
typedef struct _MwLabel* MwLabel;
|
||||||
|
typedef struct _MwLabelSegment MwLabelSegment;
|
||||||
typedef struct _MwListBoxEntry MwListBoxEntry;
|
typedef struct _MwListBoxEntry MwListBoxEntry;
|
||||||
typedef struct _MwTreeViewEntry MwTreeViewEntry;
|
typedef struct _MwTreeViewEntry MwTreeViewEntry;
|
||||||
typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
||||||
@@ -164,6 +167,21 @@ struct _MwTreeView {
|
|||||||
MwPoint pressed;
|
MwPoint pressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _MwScrollBar {
|
||||||
|
MwPoint point;
|
||||||
|
int drag;
|
||||||
|
int pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _MwLabel {
|
||||||
|
MwLabelSegment* segment;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _MwLabelSegment {
|
||||||
|
int key;
|
||||||
|
unsigned char value;
|
||||||
|
};
|
||||||
|
|
||||||
struct _MwDirectoryEntry {
|
struct _MwDirectoryEntry {
|
||||||
char* name;
|
char* name;
|
||||||
int type;
|
int type;
|
||||||
|
|||||||
@@ -17,6 +17,17 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
MWDECL MwClass MwLabelClass;
|
MWDECL MwClass MwLabelClass;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets the custom data for seven segment
|
||||||
|
* @param handle Widget
|
||||||
|
* @param index Index
|
||||||
|
* @param data Data, `GFEDCBA` as 7-bit value
|
||||||
|
* @note See https://en.wikipedia.org/wiki/File:7_Segment_Display_with_Labeled_Segments.svg for what alphabets mean here
|
||||||
|
* */
|
||||||
|
MwInline void MwLabelSetSevenSegment(MwWidget handle, int index, int data) {
|
||||||
|
MwVaWidgetExecute(handle, "mwLabelSetSevenSegment", NULL, index, data);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,8 +18,15 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
MWDECL MwClass MwSubMenuClass;
|
MWDECL MwClass MwSubMenuClass;
|
||||||
|
|
||||||
MwInline void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) {
|
/*!
|
||||||
MwVaWidgetExecute(handle, "mwSubMenuAppear", NULL, menu, point);
|
* @brief Makes submenu appear
|
||||||
|
* @param handle Handle
|
||||||
|
* @param menu Menu
|
||||||
|
* @param point Point
|
||||||
|
* @param diff_calc Toggles different way to calculate positiion
|
||||||
|
*/
|
||||||
|
MwInline void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point, int diff_calc) {
|
||||||
|
MwVaWidgetExecute(handle, "mwSubMenuAppear", NULL, menu, point, diff_calc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
14
milsko.xml
14
milsko.xml
@@ -89,6 +89,8 @@
|
|||||||
<integer name="fixedSize" />
|
<integer name="fixedSize" />
|
||||||
<integer name="margin" />
|
<integer name="margin" />
|
||||||
<integer name="bitmapFont" />
|
<integer name="bitmapFont" />
|
||||||
|
<integer name="sevenSegment" />
|
||||||
|
<integer name="length" />
|
||||||
|
|
||||||
<string name="title" />
|
<string name="title" />
|
||||||
<string name="text" />
|
<string name="text" />
|
||||||
@@ -495,6 +497,8 @@
|
|||||||
<property name="orientation" />
|
<property name="orientation" />
|
||||||
<property name="margin" />
|
<property name="margin" />
|
||||||
<property name="padding" />
|
<property name="padding" />
|
||||||
|
<property name="hasBorder" />
|
||||||
|
<property name="inverted" />
|
||||||
</properties>
|
</properties>
|
||||||
</widget>
|
</widget>
|
||||||
<widget name="Button">
|
<widget name="Button">
|
||||||
@@ -536,7 +540,17 @@
|
|||||||
<property name="text" />
|
<property name="text" />
|
||||||
<property name="alignment" />
|
<property name="alignment" />
|
||||||
<property name="bold" />
|
<property name="bold" />
|
||||||
|
<property name="sevenSegment" />
|
||||||
|
<property name="length" />
|
||||||
</properties>
|
</properties>
|
||||||
|
<functions>
|
||||||
|
<function name="SetSevenSegment">
|
||||||
|
<arguments>
|
||||||
|
<integer name="index" />
|
||||||
|
<integer name="data" />
|
||||||
|
</arguments>
|
||||||
|
</function>
|
||||||
|
</functions>
|
||||||
</widget>
|
</widget>
|
||||||
<widget name="ListBox">
|
<widget name="ListBox">
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ add_incdir("-I/usr/X11R7/include -I/usr/pkg/include");
|
|||||||
add_libdir(
|
add_libdir(
|
||||||
"-L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/pkg/lib");
|
"-L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/pkg/lib");
|
||||||
use_backend("x11");
|
use_backend("x11");
|
||||||
add_libs("pthread");
|
add_libs("-lpthread");
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ new_example("examples/basic/combobox");
|
|||||||
new_example("examples/basic/treeview");
|
new_example("examples/basic/treeview");
|
||||||
new_example("examples/basic/box");
|
new_example("examples/basic/box");
|
||||||
new_example("examples/basic/clipboard");
|
new_example("examples/basic/clipboard");
|
||||||
|
new_example("examples/basic/sevensegment");
|
||||||
|
|
||||||
if (param_get("opengl")) {
|
if (param_get("opengl")) {
|
||||||
new_example("examples/gldemos/boing", $gl_libs);
|
new_example("examples/gldemos/boing", $gl_libs);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ static int create(MwWidget handle) {
|
|||||||
MwSetInteger(handle, MwNorientation, MwHORIZONTAL);
|
MwSetInteger(handle, MwNorientation, MwHORIZONTAL);
|
||||||
MwSetInteger(handle, MwNmargin, 0);
|
MwSetInteger(handle, MwNmargin, 0);
|
||||||
MwSetInteger(handle, MwNpadding, 0);
|
MwSetInteger(handle, MwNpadding, 0);
|
||||||
|
MwSetInteger(handle, MwNhasBorder, 0);
|
||||||
|
MwSetInteger(handle, MwNinverted, 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -20,6 +22,11 @@ static void draw(MwWidget handle) {
|
|||||||
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);
|
||||||
|
|
||||||
|
if(MwGetInteger(handle, MwNhasBorder)) {
|
||||||
|
MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted));
|
||||||
|
}
|
||||||
|
|
||||||
MwDrawRect(handle, &r, base);
|
MwDrawRect(handle, &r, base);
|
||||||
|
|
||||||
MwLLFreeColor(base);
|
MwLLFreeColor(base);
|
||||||
@@ -31,9 +38,9 @@ static void layout(MwWidget handle) {
|
|||||||
int i;
|
int i;
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int horiz = MwGetInteger(handle, MwNorientation) == MwHORIZONTAL ? 1 : 0;
|
int horiz = MwGetInteger(handle, MwNorientation) == MwHORIZONTAL ? 1 : 0;
|
||||||
int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - MwGetInteger(handle, MwNpadding) * 2;
|
int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - (MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0)) * 2;
|
||||||
int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - MwGetInteger(handle, MwNpadding) * 2;
|
int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - (MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0)) * 2;
|
||||||
int sk = MwGetInteger(handle, MwNpadding);
|
int sk = MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0);
|
||||||
|
|
||||||
for(i = 0; i < arrlen(handle->children); i++) {
|
for(i = 0; i < arrlen(handle->children); i++) {
|
||||||
int n = MwGetInteger(handle->children[i], MwNratio);
|
int n = MwGetInteger(handle->children[i], MwNratio);
|
||||||
@@ -60,10 +67,10 @@ static void layout(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MwVaApply(handle->children[i],
|
MwVaApply(handle->children[i],
|
||||||
horiz ? MwNx : MwNy, sk, /* this is what gets changed */
|
horiz ? MwNx : MwNy, sk, /* this is what gets changed */
|
||||||
horiz ? MwNy : MwNx, MwGetInteger(handle, MwNpadding), /* fixed between widgets */
|
horiz ? MwNy : MwNx, MwGetInteger(handle, MwNpadding) + (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0), /* fixed between widgets */
|
||||||
horiz ? MwNwidth : MwNheight, wsz, /* this is what gets changed */
|
horiz ? MwNwidth : MwNheight, wsz, /* this is what gets changed */
|
||||||
horiz ? MwNheight : MwNwidth, fsz, /* fixed between widgets */
|
horiz ? MwNheight : MwNwidth, fsz, /* fixed between widgets */
|
||||||
NULL);
|
NULL);
|
||||||
sk += wsz + Margin;
|
sk += wsz + Margin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
#include "../../external/stb_ds.h"
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,138 @@
|
|||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
#include "../../external/stb_ds.h"
|
||||||
|
|
||||||
|
#define Spacing 1
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
|
MwLabel lab = malloc(sizeof(*lab));
|
||||||
|
|
||||||
|
lab->segment = NULL;
|
||||||
|
handle->internal = lab;
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(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, MwNlength, 4);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destroy(MwWidget handle) {
|
||||||
|
MwLabel lab = handle->internal;
|
||||||
|
|
||||||
|
hmfree(lab->segment);
|
||||||
|
|
||||||
|
free(handle->internal);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_v(MwWidget handle, unsigned char* raw, int x, int y, int stride, MwLLColor text) {
|
||||||
|
int cy, cx, b;
|
||||||
|
|
||||||
|
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];
|
||||||
|
px[0] = text->common.red;
|
||||||
|
px[1] = text->common.green;
|
||||||
|
px[2] = text->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b = y - (s_one - 1) / 2;
|
||||||
|
for(cy = b; cy < b + (s_one - 1) / 2; cy++) {
|
||||||
|
int w = (cy - b) * 2 + 1;
|
||||||
|
int b2 = x + (s_one - w) / 2;
|
||||||
|
for(cx = b2; cx < b2 + w; cx++) {
|
||||||
|
unsigned char* px;
|
||||||
|
|
||||||
|
px = &raw[(cy * stride + cx) * 4];
|
||||||
|
px[0] = text->common.red;
|
||||||
|
px[1] = text->common.green;
|
||||||
|
px[2] = text->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b = y + l_one;
|
||||||
|
for(cy = b; cy < b + (s_one - 1) / 2; cy++) {
|
||||||
|
int w = ((s_one - 1) / 2 - 1 - (cy - b)) * 2 + 1;
|
||||||
|
int b2 = x + (s_one - w) / 2;
|
||||||
|
for(cx = b2; cx < b2 + w; cx++) {
|
||||||
|
unsigned char* px;
|
||||||
|
|
||||||
|
px = &raw[(cy * stride + cx) * 4];
|
||||||
|
px[0] = text->common.red;
|
||||||
|
px[1] = text->common.green;
|
||||||
|
px[2] = text->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_h(MwWidget handle, unsigned char* raw, int x, int y, int stride, MwLLColor text) {
|
||||||
|
int cy, cx, b;
|
||||||
|
|
||||||
|
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];
|
||||||
|
px[0] = text->common.red;
|
||||||
|
px[1] = text->common.green;
|
||||||
|
px[2] = text->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b = x - (s_one - 1) / 2;
|
||||||
|
for(cx = b; cx < b + (s_one - 1) / 2; cx++) {
|
||||||
|
int w = (cx - b) * 2 + 1;
|
||||||
|
int b2 = y + (s_one - w) / 2;
|
||||||
|
for(cy = b2; cy < b2 + w; cy++) {
|
||||||
|
unsigned char* px;
|
||||||
|
|
||||||
|
px = &raw[(cy * stride + cx) * 4];
|
||||||
|
px[0] = text->common.red;
|
||||||
|
px[1] = text->common.green;
|
||||||
|
px[2] = text->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b = x + l_one;
|
||||||
|
for(cx = b; cx < b + (s_one - 1) / 2; cx++) {
|
||||||
|
int w = ((s_one - 1) / 2 - 1 - (cx - b)) * 2 + 1;
|
||||||
|
int b2 = y + (s_one - w) / 2;
|
||||||
|
for(cy = b2; cy < b2 + w; cy++) {
|
||||||
|
unsigned char* px;
|
||||||
|
|
||||||
|
px = &raw[(cy * stride + cx) * 4];
|
||||||
|
px[0] = text->common.red;
|
||||||
|
px[1] = text->common.green;
|
||||||
|
px[2] = text->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
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 = "";
|
||||||
|
|
||||||
@@ -28,40 +145,223 @@ static void draw(MwWidget handle) {
|
|||||||
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
|
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
|
||||||
|
|
||||||
align = MwGetInteger(handle, MwNalignment);
|
align = MwGetInteger(handle, MwNalignment);
|
||||||
if(align == MwALIGNMENT_CENTER) {
|
if(MwGetInteger(handle, MwNsevenSegment)) {
|
||||||
p.x = r.width / 2;
|
MwLLPixmap px;
|
||||||
} else if(align == MwALIGNMENT_BEGINNING) {
|
unsigned char* raw;
|
||||||
p.x = MwTextWidth(handle, str) / 2;
|
int w = 0, h = s_one * 3 + l_one * 2, i;
|
||||||
} else if(align == MwALIGNMENT_END) {
|
int x = 0;
|
||||||
p.x = r.width - MwTextWidth(handle, str) / 2;
|
|
||||||
}
|
|
||||||
p.y = r.height / 2;
|
|
||||||
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
|
|
||||||
|
|
||||||
|
/* so - this mode cannot do unicode.
|
||||||
|
* but you wouldn't show unicode on 7 segment anyways
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* L
|
||||||
|
* S <--->
|
||||||
|
*
|
||||||
|
* S
|
||||||
|
* ^
|
||||||
|
* |
|
||||||
|
* L |
|
||||||
|
* |
|
||||||
|
* v
|
||||||
|
*/
|
||||||
|
|
||||||
|
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(hmgeti(lab->segment, i) != -1 || ('0' <= str[i] && str[i] <= '9') || ('A' <= str[i] && str[i] <= 'F') || ('a' <= str[i] && str[i] <= 'f')) {
|
||||||
|
w += l_one + s_one * 2;
|
||||||
|
} else if(str[i] == ':' || str[i] == ' ') {
|
||||||
|
w += s_one;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w++;
|
||||||
|
h++;
|
||||||
|
|
||||||
|
raw = malloc(w * h * 4);
|
||||||
|
memset(raw, 0, w * h * 4);
|
||||||
|
|
||||||
|
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')) {
|
||||||
|
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 */
|
||||||
|
|
||||||
|
if(hmgeti(lab->segment, i) != -1) {
|
||||||
|
unsigned char c = hmget(lab->segment, i);
|
||||||
|
|
||||||
|
if(c & (1 << 0)) la = 1;
|
||||||
|
if(c & (1 << 1)) lb = 1;
|
||||||
|
if(c & (1 << 2)) lc = 1;
|
||||||
|
if(c & (1 << 3)) ld = 1;
|
||||||
|
if(c & (1 << 4)) le = 1;
|
||||||
|
if(c & (1 << 5)) lf = 1;
|
||||||
|
if(c & (1 << 6)) lg = 1;
|
||||||
|
} else {
|
||||||
|
if(str[i] == '0') {
|
||||||
|
la = lb = lc = ld = le = lf = 1;
|
||||||
|
} else if(str[i] == '1') {
|
||||||
|
lb = lc = 1;
|
||||||
|
} else if(str[i] == '2') {
|
||||||
|
la = lb = ld = le = lg = 1;
|
||||||
|
} else if(str[i] == '3') {
|
||||||
|
la = lb = lc = ld = lg = 1;
|
||||||
|
} else if(str[i] == '4') {
|
||||||
|
lb = lc = lf = lg = 1;
|
||||||
|
} else if(str[i] == '5') {
|
||||||
|
la = lc = ld = lf = lg = 1;
|
||||||
|
} else if(str[i] == '6') {
|
||||||
|
la = lc = ld = le = lf = lg = 1;
|
||||||
|
} else if(str[i] == '7') {
|
||||||
|
la = lb = lc = 1;
|
||||||
|
} else if(str[i] == '8') {
|
||||||
|
la = lb = lc = ld = le = lf = lg = 1;
|
||||||
|
} else if(str[i] == '9') {
|
||||||
|
la = lb = lc = ld = lf = lg = 1;
|
||||||
|
} else if(str[i] == 'A' || str[i] == 'a') {
|
||||||
|
la = lb = lc = le = lf = lg = 1;
|
||||||
|
} else if(str[i] == 'B' || str[i] == 'b') {
|
||||||
|
lc = ld = le = lf = lg = 1;
|
||||||
|
} else if(str[i] == 'C' || str[i] == 'c') {
|
||||||
|
ld = le = lg = 1;
|
||||||
|
} else if(str[i] == 'D' || str[i] == 'd') {
|
||||||
|
lb = lc = ld = le = lg = 1;
|
||||||
|
} else if(str[i] == 'E' || str[i] == 'e') {
|
||||||
|
la = ld = le = lf = lg = 1;
|
||||||
|
} else if(str[i] == 'F' || str[i] == 'f') {
|
||||||
|
la = le = lf = lg = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(j = 1; j >= 0; j--) {
|
||||||
|
MwLLColor cl = j == 1 ? shadow : text;
|
||||||
|
|
||||||
|
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] == ':') {
|
||||||
|
int cy, cx;
|
||||||
|
int j;
|
||||||
|
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 + s_one)) ? 1 : 0;
|
||||||
|
int c2 = ((s_one + l_one + c) <= cy && cy <= (s_one + l_one + c + s_one)) ? 1 : 0;
|
||||||
|
|
||||||
|
if(c1 || c2) {
|
||||||
|
for(cx = x; cx < x + s_one; cx++) {
|
||||||
|
unsigned char* px = &raw[((cy + j) * w + (cx + j)) * 4];
|
||||||
|
px[0] = cl->common.red;
|
||||||
|
px[1] = cl->common.green;
|
||||||
|
px[2] = cl->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x += s_one;
|
||||||
|
} else if(str[i] == ' ') {
|
||||||
|
x += s_one;
|
||||||
|
} else if(str[i] == '.') {
|
||||||
|
int cy, cx;
|
||||||
|
int j;
|
||||||
|
for(j = 1; j >= 0; j--) {
|
||||||
|
MwLLColor cl = j == 1 ? shadow : text;
|
||||||
|
for(cy = h - (s_one - 1) / 2 - 1; cy < h; cy++) {
|
||||||
|
for(cx = x - Spacing - (s_one - 1) / 2 - 1; cx < (x - Spacing); cx++) {
|
||||||
|
unsigned char* px = &raw[((cy + j) * w + (cx + j)) * 4];
|
||||||
|
px[0] = cl->common.red;
|
||||||
|
px[1] = cl->common.green;
|
||||||
|
px[2] = cl->common.blue;
|
||||||
|
px[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
x += Spacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
px = MwLoadRaw(handle, raw, w, h);
|
||||||
|
|
||||||
|
r.y = (r.height - h) / 2;
|
||||||
|
r.height = h;
|
||||||
|
if(align == MwALIGNMENT_CENTER) {
|
||||||
|
r.x = (r.width - w) / 2;
|
||||||
|
} else if(align == MwALIGNMENT_BEGINNING) {
|
||||||
|
r.x = 0;
|
||||||
|
} else if(align == MwALIGNMENT_END) {
|
||||||
|
r.x = r.width - w;
|
||||||
|
}
|
||||||
|
r.width = w;
|
||||||
|
MwLLDrawPixmap(handle->lowlevel, &r, px);
|
||||||
|
|
||||||
|
MwLLDestroyPixmap(px);
|
||||||
|
} else {
|
||||||
|
if(align == MwALIGNMENT_CENTER) {
|
||||||
|
p.x = r.width / 2;
|
||||||
|
} else if(align == MwALIGNMENT_BEGINNING) {
|
||||||
|
p.x = MwTextWidth(handle, str) / 2;
|
||||||
|
} else if(align == MwALIGNMENT_END) {
|
||||||
|
p.x = r.width - MwTextWidth(handle, str) / 2;
|
||||||
|
}
|
||||||
|
p.y = r.height / 2;
|
||||||
|
MwDrawText(handle, &p, str, MwGetInteger(handle, MwNbold), MwALIGNMENT_CENTER, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
MwLLFreeColor(shadow);
|
||||||
MwLLFreeColor(text);
|
MwLLFreeColor(text);
|
||||||
MwLLFreeColor(base);
|
MwLLFreeColor(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prop_change(MwWidget handle, const char* key) {
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0) MwForceRender(handle);
|
if(strcmp(key, MwNtext) == 0 || strcmp(key, MwNalignment) == 0 || strcmp(key, MwNsevenSegment) == 0) MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mwLabelSetSevenSegmentImpl(MwWidget handle, int index, unsigned char data) {
|
||||||
|
MwLabel lab = handle->internal;
|
||||||
|
|
||||||
|
hmput(lab->segment, index, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
|
||||||
|
(void)out;
|
||||||
|
|
||||||
|
if(strcmp(name, "mwLabelSetSevenSegment") == 0) {
|
||||||
|
int index = va_arg(va, int);
|
||||||
|
int data = va_arg(va, int);
|
||||||
|
|
||||||
|
mwLabelSetSevenSegmentImpl(handle, index, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MwClassRec MwLabelClassRec = {
|
MwClassRec MwLabelClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
destroy, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
prop_change, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
NULL, /* mouse_move */
|
||||||
NULL, /* mouse_up */
|
NULL, /* mouse_up */
|
||||||
NULL, /* mouse_down */
|
NULL, /* mouse_down */
|
||||||
NULL, /* key */
|
NULL, /* key */
|
||||||
NULL, /* execute */
|
func_handler, /* execute */
|
||||||
NULL, /* tick */
|
NULL, /* tick */
|
||||||
NULL, /* resize */
|
NULL, /* resize */
|
||||||
NULL, /* children_update */
|
NULL, /* children_update */
|
||||||
NULL, /* children_prop_change */
|
NULL, /* children_prop_change */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ static void mouse_down(MwWidget handle, void* ptr) {
|
|||||||
p2.y = p.y + th / 2 + 5;
|
p2.y = p.y + th / 2 + 5;
|
||||||
|
|
||||||
m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
m->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
||||||
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2);
|
MwSubMenuAppear(m->sub[i]->wsub, m->sub[i], &p2, 0);
|
||||||
} else if(m->sub[i]->wsub != NULL && m->sub[i]->keep) {
|
} else if(m->sub[i]->wsub != NULL && m->sub[i]->keep) {
|
||||||
MwDestroyWidget(m->sub[i]->wsub);
|
MwDestroyWidget(m->sub[i]->wsub);
|
||||||
m->sub[i]->wsub = NULL;
|
m->sub[i]->wsub = NULL;
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
typedef struct scrollbar {
|
|
||||||
MwPoint point;
|
|
||||||
int drag;
|
|
||||||
int pos;
|
|
||||||
} scrollbar_t;
|
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
scrollbar_t* scr = malloc(sizeof(*scr));
|
MwScrollBar scr = malloc(sizeof(*scr));
|
||||||
|
|
||||||
handle->internal = scr;
|
handle->internal = scr;
|
||||||
|
|
||||||
@@ -60,10 +54,10 @@ static void add_value(MwWidget handle, int mul) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void draw(MwWidget handle) {
|
static void draw(MwWidget handle) {
|
||||||
MwRect r, rt, rbar;
|
MwRect r, rt, rbar;
|
||||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||||
MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64);
|
MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64);
|
||||||
scrollbar_t* scr = handle->internal;
|
MwScrollBar scr = handle->internal;
|
||||||
int or ;
|
int or ;
|
||||||
int uy, dy, ux, dx;
|
int uy, dy, ux, dx;
|
||||||
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
|
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
|
||||||
@@ -144,8 +138,8 @@ static void draw(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_move(MwWidget handle) {
|
static void mouse_move(MwWidget handle) {
|
||||||
int or = MwGetInteger(handle, MwNorientation);
|
int or = MwGetInteger(handle, MwNorientation);
|
||||||
scrollbar_t* scr = handle->internal;
|
MwScrollBar scr = handle->internal;
|
||||||
|
|
||||||
if(!handle->pressed) return;
|
if(!handle->pressed) return;
|
||||||
|
|
||||||
@@ -172,11 +166,11 @@ static void mouse_move(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_down(MwWidget handle, void* ptr) {
|
static void mouse_down(MwWidget handle, void* ptr) {
|
||||||
int ww = MwGetInteger(handle, MwNwidth);
|
int ww = MwGetInteger(handle, MwNwidth);
|
||||||
int wh = MwGetInteger(handle, MwNheight);
|
int wh = MwGetInteger(handle, MwNheight);
|
||||||
int or = MwGetInteger(handle, MwNorientation);
|
int or = MwGetInteger(handle, MwNorientation);
|
||||||
scrollbar_t* scr = handle->internal;
|
MwScrollBar scr = handle->internal;
|
||||||
MwLLMouse* m = ptr;
|
MwLLMouse* m = ptr;
|
||||||
|
|
||||||
if(m->button == MwLLMouseWheelUp) {
|
if(m->button == MwLLMouseWheelUp) {
|
||||||
int min = MwGetInteger(handle, MwNminValue);
|
int min = MwGetInteger(handle, MwNminValue);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ static void click(MwWidget handle) {
|
|||||||
p.y = rc.y - 3;
|
p.y = rc.y - 3;
|
||||||
|
|
||||||
menu->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
menu->sub[i]->wsub = MwCreateWidget(MwSubMenuClass, "submenu", handle, 0, 0, 0, 0);
|
||||||
MwSubMenuAppear(menu->sub[i]->wsub, menu->sub[i], &p);
|
MwSubMenuAppear(menu->sub[i]->wsub, menu->sub[i], &p, 0);
|
||||||
i = -1;
|
i = -1;
|
||||||
} else if(menu->sub[i]->wsub != NULL && arrlen(menu->sub[i]->sub) > 0) {
|
} else if(menu->sub[i]->wsub != NULL && arrlen(menu->sub[i]->sub) > 0) {
|
||||||
while(w->parent->widget_class != MwMenuClass) w = w->parent;
|
while(w->parent->widget_class != MwMenuClass) w = w->parent;
|
||||||
@@ -159,15 +159,15 @@ static void click(MwWidget handle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point) {
|
static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point, int diff_calc) {
|
||||||
int i, w = 0, h = 0;
|
int i, w = 0, h = 0;
|
||||||
|
MwRect rc;
|
||||||
|
MwPoint p = *point;
|
||||||
|
|
||||||
|
MwGetScreenSize(handle, &rc);
|
||||||
|
|
||||||
handle->internal = menu;
|
handle->internal = menu;
|
||||||
|
|
||||||
MwLLMakeToolWindow(handle->lowlevel);
|
|
||||||
MwLLDetach(handle->lowlevel, point);
|
|
||||||
MwLLEndStateChange(handle->lowlevel);
|
|
||||||
|
|
||||||
for(i = 0; i < arrlen(menu->sub); i++) {
|
for(i = 0; i < arrlen(menu->sub); i++) {
|
||||||
if(strcmp(menu->sub[i]->name, "----") == 0) {
|
if(strcmp(menu->sub[i]->name, "----") == 0) {
|
||||||
h += MwDefaultBorderWidth(handle) * 2 + 2;
|
h += MwDefaultBorderWidth(handle) * 2 + 2;
|
||||||
@@ -183,6 +183,20 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point) {
|
|||||||
w += 10 + 15;
|
w += 10 + 15;
|
||||||
h += 3;
|
h += 3;
|
||||||
|
|
||||||
|
if(diff_calc) {
|
||||||
|
p.y = rc.height - p.y - h;
|
||||||
|
}
|
||||||
|
|
||||||
|
MwLLMakeToolWindow(handle->lowlevel);
|
||||||
|
MwLLDetach(handle->lowlevel, &p);
|
||||||
|
|
||||||
|
if(MwGetInteger(handle, MwNy) + h > rc.height) {
|
||||||
|
MwVaApply(handle,
|
||||||
|
MwNy, rc.height - h,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
MwLLEndStateChange(handle->lowlevel);
|
||||||
|
|
||||||
MwVaApply(handle,
|
MwVaApply(handle,
|
||||||
MwNwidth, w,
|
MwNwidth, w,
|
||||||
MwNheight, h,
|
MwNheight, h,
|
||||||
@@ -193,9 +207,10 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
|
|||||||
(void)out;
|
(void)out;
|
||||||
|
|
||||||
if(strcmp(name, "mwSubMenuAppear") == 0) {
|
if(strcmp(name, "mwSubMenuAppear") == 0) {
|
||||||
MwMenu menu = va_arg(va, MwMenu);
|
MwMenu menu = va_arg(va, MwMenu);
|
||||||
MwPoint* point = va_arg(va, MwPoint*);
|
MwPoint* point = va_arg(va, MwPoint*);
|
||||||
mwSubMenuAppearImpl(handle, menu, point);
|
int diff_calc = va_arg(va, int);
|
||||||
|
mwSubMenuAppearImpl(handle, menu, point, diff_calc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user