This commit is contained in:
parent
d1f97c0fa4
commit
6b94ac5db9
8 changed files with 142 additions and 22 deletions
|
|
@ -312,7 +312,7 @@ int main() {
|
||||||
NULL);
|
NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
MwViewportSetSize(w, 512, 512);
|
MwViewportSetSize(w, 512, 512);
|
||||||
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 32, 32, 128, 128,
|
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 32, 32, 256, 128,
|
||||||
MwNtitle, "Sub window",
|
MwNtitle, "Sub window",
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
add(f);
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,16 @@ MWDECL const char* MwDefaultSubBackground;
|
||||||
*/
|
*/
|
||||||
MWDECL const char* MwDefaultSubForeground;
|
MWDECL const char* MwDefaultSubForeground;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Default title background color
|
||||||
|
*/
|
||||||
|
MWDECL const char* MwDefaultTitleBackground;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Default title foreground color
|
||||||
|
*/
|
||||||
|
MWDECL const char* MwDefaultTitleForeground;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Default dark theme background color
|
* @brief Default dark theme background color
|
||||||
*/
|
*/
|
||||||
|
|
@ -52,6 +62,16 @@ MWDECL const char* MwDefaultDarkSubBackground;
|
||||||
*/
|
*/
|
||||||
MWDECL const char* MwDefaultDarkSubForeground;
|
MWDECL const char* MwDefaultDarkSubForeground;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Default dark theme title background color
|
||||||
|
*/
|
||||||
|
MWDECL const char* MwDefaultDarkTitleBackground;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Default dark theme title foreground color
|
||||||
|
*/
|
||||||
|
MWDECL const char* MwDefaultDarkTitleForeground;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Default shadow difference
|
* @brief Default shadow difference
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,10 @@
|
||||||
#define MwNtext "Stext"
|
#define MwNtext "Stext"
|
||||||
#define MwNbackground "Sbackground"
|
#define MwNbackground "Sbackground"
|
||||||
#define MwNsubBackground "SsubBackground"
|
#define MwNsubBackground "SsubBackground"
|
||||||
|
#define MwNtitleBackground "StitleBackground"
|
||||||
#define MwNforeground "Sforeground"
|
#define MwNforeground "Sforeground"
|
||||||
#define MwNsubForeground "SsubForeground"
|
#define MwNsubForeground "SsubForeground"
|
||||||
#define MwNtitleBackground "StitleBackground"
|
#define MwNtitleForeground "StitleForeground"
|
||||||
|
|
||||||
#define MwNvulkanExtension "SEvulkanExtension"
|
#define MwNvulkanExtension "SEvulkanExtension"
|
||||||
#define MwNvulkanLayer "SEvulkanLayer"
|
#define MwNvulkanLayer "SEvulkanLayer"
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ typedef struct _MwListBoxEntry MwListBoxEntry;
|
||||||
typedef struct _MwTreeViewEntry MwTreeViewEntry;
|
typedef struct _MwTreeViewEntry MwTreeViewEntry;
|
||||||
typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
||||||
typedef struct _MwBox* MwBox;
|
typedef struct _MwBox* MwBox;
|
||||||
|
typedef struct _MwSubWindow* MwSubWindow;
|
||||||
typedef struct _MwMouse MwMouse;
|
typedef struct _MwMouse MwMouse;
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
typedef struct _MwWidget* MwWidget;
|
typedef struct _MwWidget* MwWidget;
|
||||||
|
|
@ -207,6 +208,13 @@ struct _MwBox {
|
||||||
int layout;
|
int layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _MwSubWindow {
|
||||||
|
MwWidget frame;
|
||||||
|
MwWidget minimize;
|
||||||
|
MwWidget maximize;
|
||||||
|
MwWidget close;
|
||||||
|
};
|
||||||
|
|
||||||
struct _MwMouse {
|
struct _MwMouse {
|
||||||
MwPoint point;
|
MwPoint point;
|
||||||
int button;
|
int button;
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,10 @@
|
||||||
<string name="text" />
|
<string name="text" />
|
||||||
<string name="background" common="yes" />
|
<string name="background" common="yes" />
|
||||||
<string name="subBackground" common="yes" />
|
<string name="subBackground" common="yes" />
|
||||||
|
<string name="titleBackground" common="yes" />
|
||||||
<string name="foreground" common="yes" />
|
<string name="foreground" common="yes" />
|
||||||
<string name="subForeground" common="yes" />
|
<string name="subForeground" common="yes" />
|
||||||
|
<string name="titleForeground" common="yes" />
|
||||||
|
|
||||||
<!-- Early string properties -->
|
<!-- Early string properties -->
|
||||||
<string name="vulkanExtension" early="yes" />
|
<string name="vulkanExtension" early="yes" />
|
||||||
|
|
@ -876,6 +878,12 @@
|
||||||
<function name="Reset" />
|
<function name="Reset" />
|
||||||
</functions>
|
</functions>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget name="SubWindow">
|
||||||
|
<properties>
|
||||||
|
<property name="iconPixmap" />
|
||||||
|
<property name="title" />
|
||||||
|
</properties>
|
||||||
|
</widget>
|
||||||
|
|
||||||
<!-- They are not alphabetically sorted for reasons -->
|
<!-- They are not alphabetically sorted for reasons -->
|
||||||
<widget name="OpenGL">
|
<widget name="OpenGL">
|
||||||
|
|
|
||||||
10
src/core.c
10
src/core.c
|
|
@ -591,7 +591,7 @@ void MwSetInteger(MwWidget handle, const char* key, int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwSetText(MwWidget handle, const char* key, const char* value) {
|
void MwSetText(MwWidget handle, const char* key, const char* value) {
|
||||||
if(strcmp(key, MwNtitle) == 0) {
|
if(handle->widget_class == MwWindowClass && strcmp(key, MwNtitle) == 0) {
|
||||||
MwLLSetTitle(handle->lowlevel, value);
|
MwLLSetTitle(handle->lowlevel, value);
|
||||||
} else {
|
} else {
|
||||||
char* v = value == NULL ? NULL : MwStringDuplicate(value);
|
char* v = value == NULL ? NULL : MwStringDuplicate(value);
|
||||||
|
|
@ -686,24 +686,30 @@ int MwGetInteger(MwWidget handle, const char* key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* MwGetText(MwWidget handle, const char* key) {
|
const char* MwGetText(MwWidget handle, const char* key) {
|
||||||
if(shgeti(handle->text, key) == -1 && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0)) {
|
if((shgeti(handle->text, key) == -1 || strcmp(shget(handle->text, key), "DEFAULT") == 0) && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0 || strcmp(key, MwNtitleBackground) == 0 || strcmp(key, MwNtitleForeground) == 0)) {
|
||||||
const char* v = NULL;
|
const char* v = NULL;
|
||||||
|
if(shgeti(handle->text, key) != -1 && strcmp(shget(handle->text, key), "DEFAULT") != 0) {
|
||||||
MwWidget h = handle->parent;
|
MwWidget h = handle->parent;
|
||||||
while(h != NULL) {
|
while(h != NULL) {
|
||||||
if((v = MwGetText(h, key)) != NULL) break;
|
if((v = MwGetText(h, key)) != NULL) break;
|
||||||
h = h->parent;
|
h = h->parent;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(v == NULL) {
|
if(v == NULL) {
|
||||||
if(MwGetInteger(handle, MwNdarkTheme)) {
|
if(MwGetInteger(handle, MwNdarkTheme)) {
|
||||||
if(strcmp(key, MwNbackground) == 0) return MwDefaultDarkBackground;
|
if(strcmp(key, MwNbackground) == 0) return MwDefaultDarkBackground;
|
||||||
if(strcmp(key, MwNforeground) == 0) return MwDefaultDarkForeground;
|
if(strcmp(key, MwNforeground) == 0) return MwDefaultDarkForeground;
|
||||||
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultDarkSubBackground;
|
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultDarkSubBackground;
|
||||||
if(strcmp(key, MwNsubForeground) == 0) return MwDefaultDarkSubForeground;
|
if(strcmp(key, MwNsubForeground) == 0) return MwDefaultDarkSubForeground;
|
||||||
|
if(strcmp(key, MwNtitleBackground) == 0) return MwDefaultDarkTitleBackground;
|
||||||
|
if(strcmp(key, MwNtitleForeground) == 0) return MwDefaultDarkTitleForeground;
|
||||||
} else {
|
} else {
|
||||||
if(strcmp(key, MwNbackground) == 0) return MwDefaultBackground;
|
if(strcmp(key, MwNbackground) == 0) return MwDefaultBackground;
|
||||||
if(strcmp(key, MwNforeground) == 0) return MwDefaultForeground;
|
if(strcmp(key, MwNforeground) == 0) return MwDefaultForeground;
|
||||||
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultSubBackground;
|
if(strcmp(key, MwNsubBackground) == 0) return MwDefaultSubBackground;
|
||||||
if(strcmp(key, MwNsubForeground) == 0) return MwDefaultSubForeground;
|
if(strcmp(key, MwNsubForeground) == 0) return MwDefaultSubForeground;
|
||||||
|
if(strcmp(key, MwNtitleBackground) == 0) return MwDefaultTitleBackground;
|
||||||
|
if(strcmp(key, MwNtitleForeground) == 0) return MwDefaultTitleForeground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,15 @@ const char* MwDefaultBackground = "#d2d2d2";
|
||||||
const char* MwDefaultForeground = "#000";
|
const char* MwDefaultForeground = "#000";
|
||||||
const char* MwDefaultSubBackground = "#fff";
|
const char* MwDefaultSubBackground = "#fff";
|
||||||
const char* MwDefaultSubForeground = "#000";
|
const char* MwDefaultSubForeground = "#000";
|
||||||
|
const char* MwDefaultTitleBackground = "#008";
|
||||||
|
const char* MwDefaultTitleForeground = "#fff";
|
||||||
|
|
||||||
const char* MwDefaultDarkBackground = "#333";
|
const char* MwDefaultDarkBackground = "#333";
|
||||||
const char* MwDefaultDarkForeground = "#ddd";
|
const char* MwDefaultDarkForeground = "#ddd";
|
||||||
const char* MwDefaultDarkSubBackground = "#333";
|
const char* MwDefaultDarkSubBackground = "#333";
|
||||||
const char* MwDefaultDarkSubForeground = "#ddd";
|
const char* MwDefaultDarkSubForeground = "#ddd";
|
||||||
|
const char* MwDefaultDarkTitleBackground = "#008";
|
||||||
|
const char* MwDefaultDarkTitleForeground = "#fff";
|
||||||
|
|
||||||
const int MwDefaultShadow = -32;
|
const int MwDefaultShadow = -32;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,82 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#define TitleHeight 20
|
#define TitleHeight 20
|
||||||
|
#define ButtonSize 18
|
||||||
|
|
||||||
|
static void resize(MwWidget handle){
|
||||||
|
MwSubWindow sw = handle->internal;
|
||||||
|
int x, y, w, h;
|
||||||
|
int ww = MwGetInteger(handle, MwNwidth);
|
||||||
|
int wh = MwGetInteger(handle, MwNheight);
|
||||||
|
int bw = MwDefaultBorderWidth(handle);
|
||||||
|
int p;
|
||||||
|
|
||||||
|
x = bw * 2;
|
||||||
|
y = bw * 2 + TitleHeight;
|
||||||
|
w = ww - bw * 4;
|
||||||
|
h = wh - bw * 4 - TitleHeight;
|
||||||
|
if(sw->frame == NULL){
|
||||||
|
sw->frame = MwCreateWidget(MwFrameClass, "frame", handle, x, y, w, h);
|
||||||
|
}else{
|
||||||
|
MwVaApply(sw->frame,
|
||||||
|
MwNx, x,
|
||||||
|
MwNy, y,
|
||||||
|
MwNwidth, w,
|
||||||
|
MwNheight, h,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
p = (TitleHeight - ButtonSize) / 2;
|
||||||
|
x = ww - bw - p;
|
||||||
|
y = bw + p;
|
||||||
|
w = ButtonSize;
|
||||||
|
h = ButtonSize;
|
||||||
|
|
||||||
|
#define BUTTON(name) \
|
||||||
|
x -= ButtonSize; \
|
||||||
|
if(sw->name == NULL){ \
|
||||||
|
sw->name = MwCreateWidget(MwButtonClass, #name, handle, x, y, w, h); \
|
||||||
|
}else{ \
|
||||||
|
MwVaApply(sw->name, \
|
||||||
|
MwNx, x, \
|
||||||
|
MwNy, y, \
|
||||||
|
MwNwidth, w, \
|
||||||
|
MwNheight, h, \
|
||||||
|
NULL); \
|
||||||
|
} \
|
||||||
|
x -= p;
|
||||||
|
|
||||||
|
BUTTON(close);
|
||||||
|
BUTTON(maximize);
|
||||||
|
BUTTON(minimize);
|
||||||
|
|
||||||
|
MwSetText(sw->frame, MwNbackground, "#f00");
|
||||||
|
}
|
||||||
|
|
||||||
static int wcreate(MwWidget handle) {
|
static int wcreate(MwWidget handle) {
|
||||||
MwSetDefault(handle);
|
MwSubWindow sw = malloc(sizeof(*sw));
|
||||||
|
memset(sw, 0, sizeof(*sw));
|
||||||
|
|
||||||
MwSetText(handle, MwNtitleBackground, "#008");
|
handle->internal = sw;
|
||||||
|
|
||||||
|
resize(handle);
|
||||||
|
|
||||||
|
MwSetDefault(handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destroy(MwWidget handle) {
|
||||||
|
MwSubWindow sw = handle->internal;
|
||||||
|
free(handle->internal);
|
||||||
|
}
|
||||||
|
|
||||||
static void draw(MwWidget handle) {
|
static void draw(MwWidget handle) {
|
||||||
MwLLColor c = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
MwLLColor c = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||||
MwLLColor c2 = MwParseColor(handle, MwGetText(handle, MwNtitleBackground));
|
MwLLColor tb = MwParseColor(handle, MwGetText(handle, MwNtitleBackground));
|
||||||
|
MwLLColor tf = MwParseColor(handle, MwGetText(handle, MwNtitleForeground));
|
||||||
MwRect r, r2;
|
MwRect r, r2;
|
||||||
|
const char* title = MwGetText(handle, MwNtitle);
|
||||||
|
|
||||||
r.x = 0;
|
r.x = 0;
|
||||||
r.y = 0;
|
r.y = 0;
|
||||||
|
|
@ -25,13 +88,23 @@ static void draw(MwWidget handle) {
|
||||||
|
|
||||||
r2 = r;
|
r2 = r;
|
||||||
r2.height = TitleHeight;
|
r2.height = TitleHeight;
|
||||||
MwDrawRect(handle, &r2, c2);
|
MwDrawRect(handle, &r2, tb);
|
||||||
|
|
||||||
|
if(title != NULL){
|
||||||
|
MwPoint p;
|
||||||
|
p.x = r2.x + (TitleHeight - ButtonSize);
|
||||||
|
p.y = r2.y + TitleHeight / 2;
|
||||||
|
handle->bgcolor = tb;
|
||||||
|
MwDrawText(handle, NULL, &p, title, MwALIGNMENT_BEGINNING, tf);
|
||||||
|
handle->bgcolor = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
r.y += TitleHeight;
|
r.y += TitleHeight;
|
||||||
r.height -= TitleHeight;
|
r.height -= TitleHeight;
|
||||||
MwDrawFrame(handle, &r, c, 1);
|
MwDrawFrame(handle, &r, c, 1);
|
||||||
|
|
||||||
MwLLFreeColor(c2);
|
MwLLFreeColor(tf);
|
||||||
|
MwLLFreeColor(tb);
|
||||||
MwLLFreeColor(c);
|
MwLLFreeColor(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +118,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
|
||||||
|
|
||||||
MwClassRec MwSubWindowClassRec = {
|
MwClassRec MwSubWindowClassRec = {
|
||||||
wcreate, /* create */
|
wcreate, /* create */
|
||||||
NULL, /* destroy */
|
destroy, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue