From 4452531d90965496481ab5a566181d2001a12ed1 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 4 Oct 2025 16:34:24 +0000 Subject: [PATCH] working on scrollbar, wip git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@163 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 4 ++-- examples/gltriangle.c | 2 +- examples/oldglut.c | 2 +- include/Mw/Draw.h | 21 +++++++++++++++++ include/Mw/Milsko.h | 14 +++++++----- include/Mw/{ => Widget}/Button.h | 6 ++--- include/Mw/{ => Widget}/Frame.h | 6 ++--- include/Mw/{ => Widget}/Image.h | 6 ++--- include/Mw/{ => Widget}/Menu.h | 6 ++--- include/Mw/{ => Widget}/OpenGL.h | 6 ++--- include/Mw/Widget/ScrollBar.h | 25 ++++++++++++++++++++ include/Mw/{ => Widget}/SubMenu.h | 6 ++--- include/Mw/{ => Widget}/Vulkan.h | 6 ++--- include/Mw/{ => Widget}/Window.h | 6 ++--- src/draw.c | 18 +++++++++++++++ src/widget/opengl.c | 2 +- src/widget/scrollbar.c | 38 +++++++++++++++++++++++++++++++ src/widget/vulkan.c | 2 +- 18 files changed, 140 insertions(+), 36 deletions(-) rename include/Mw/{ => Widget}/Button.h (72%) rename include/Mw/{ => Widget}/Frame.h (73%) rename include/Mw/{ => Widget}/Image.h (73%) rename include/Mw/{ => Widget}/Menu.h (83%) rename include/Mw/{ => Widget}/OpenGL.h (88%) create mode 100644 include/Mw/Widget/ScrollBar.h rename include/Mw/{ => Widget}/SubMenu.h (77%) rename include/Mw/{ => Widget}/Vulkan.h (97%) rename include/Mw/{ => Widget}/Window.h (72%) create mode 100644 src/widget/scrollbar.c diff --git a/GNUmakefile b/GNUmakefile index 14f118d..e781d42 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -34,7 +34,7 @@ E_LIBS = $(LIBS) -lMw L_OBJS = src/core.o src/default.o src/draw.o src/lowlevel.o src/font.o src/boldfont.o src/error.o L_OBJS += src/external/ds.o src/external/image.o -L_OBJS += src/widget/window.o src/widget/button.o src/widget/frame.o src/widget/menu.o src/widget/submenu.o src/widget/image.o +L_OBJS += src/widget/window.o src/widget/button.o src/widget/frame.o src/widget/menu.o src/widget/submenu.o src/widget/image.o src/widget/scrollbar.o ifeq ($(TARGET),NetBSD) CFLAGS += -I/usr/X11R7/include -I/usr/pkg/include @@ -66,7 +66,7 @@ endif ifeq ($(UNIX),1) L_CFLAGS += -DUSE_X11 L_OBJS += src/backend/x11.o -L_LIBS += -lX11 -lXrender -lXext +L_LIBS += -lm -lX11 -lXrender -lXext GL = -lGL -lGLU diff --git a/examples/gltriangle.c b/examples/gltriangle.c index 52ba707..ab087ab 100644 --- a/examples/gltriangle.c +++ b/examples/gltriangle.c @@ -1,6 +1,6 @@ /* $Id$ */ #include -#include +#include #include diff --git a/examples/oldglut.c b/examples/oldglut.c index bcdd6c1..85dd844 100644 --- a/examples/oldglut.c +++ b/examples/oldglut.c @@ -1,5 +1,5 @@ #include -#include +#include #include diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index 19b7667..d75b277 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -22,6 +22,17 @@ extern "C" { */ MWDECL MwLLColor MwParseColor(MwWidget handle, const char* text); +/*! + * %brief Lighten a color + * %param handle Widget + * %param color Color + * %param r Red + * %param g Green + * %param b Blue + * %return Color + */ +MWDECL MwLLColor MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b); + /*! * %brief Draws a filled rectangle * %param handle Widget @@ -40,6 +51,16 @@ MWDECL void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color); */ MWDECL void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert); +/*! + * %brief Draws a triangle + * %param handle Widget + * %param rect Rectangle area + * %param color Color + * %param invert Invert the 3D border color or not + * %warning `rect` gets changed to the area of rectangle inside + */ +MWDECL void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction); + /*! * %brief Draws a frame with specified border width * %param handle Widget diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index 08e174b..546e5e4 100644 --- a/include/Mw/Milsko.h +++ b/include/Mw/Milsko.h @@ -15,12 +15,14 @@ #include #include #include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #endif diff --git a/include/Mw/Button.h b/include/Mw/Widget/Button.h similarity index 72% rename from include/Mw/Button.h rename to include/Mw/Widget/Button.h index c57519e..96ec9a3 100644 --- a/include/Mw/Button.h +++ b/include/Mw/Widget/Button.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/Button.h + * %file Mw/Widget/Button.h * %brief Button widget */ -#ifndef __MW_BUTTON_H__ -#define __MW_BUTTON_H__ +#ifndef __MW_WIDGET_BUTTON_H__ +#define __MW_WIDGET_BUTTON_H__ #include #include diff --git a/include/Mw/Frame.h b/include/Mw/Widget/Frame.h similarity index 73% rename from include/Mw/Frame.h rename to include/Mw/Widget/Frame.h index faefe71..dd162c7 100644 --- a/include/Mw/Frame.h +++ b/include/Mw/Widget/Frame.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/Frame.h + * %file Mw/Widget/Frame.h * %brief Frame widget */ -#ifndef __MW_FRAME_H__ -#define __MW_FRAME_H__ +#ifndef __MW_WIDGET_FRAME_H__ +#define __MW_WIDGET_FRAME_H__ #include #include diff --git a/include/Mw/Image.h b/include/Mw/Widget/Image.h similarity index 73% rename from include/Mw/Image.h rename to include/Mw/Widget/Image.h index 87e7a81..478660d 100644 --- a/include/Mw/Image.h +++ b/include/Mw/Widget/Image.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/Image.h + * %file Mw/Widget/Image.h * %brief Image widget */ -#ifndef __MW_IMAGE_H__ -#define __MW_IMAGE_H__ +#ifndef __MW_WIDGET_IMAGE_H__ +#define __MW_WIDGET_IMAGE_H__ #include #include diff --git a/include/Mw/Menu.h b/include/Mw/Widget/Menu.h similarity index 83% rename from include/Mw/Menu.h rename to include/Mw/Widget/Menu.h index 847d4e6..a63f22d 100644 --- a/include/Mw/Menu.h +++ b/include/Mw/Widget/Menu.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/Menu.h + * %file Mw/Widget/Menu.h * %brief Menu widget */ -#ifndef __MW_MENU_H__ -#define __MW_MENU_H__ +#ifndef __MW_WIDGET_MENU_H__ +#define __MW_WIDGET_MENU_H__ #include #include diff --git a/include/Mw/OpenGL.h b/include/Mw/Widget/OpenGL.h similarity index 88% rename from include/Mw/OpenGL.h rename to include/Mw/Widget/OpenGL.h index 3b5a652..f22a43c 100644 --- a/include/Mw/OpenGL.h +++ b/include/Mw/Widget/OpenGL.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/OpenGL.h + * %file Mw/Widget/OpenGL.h * %brief OpenGL widget */ -#ifndef __MW_OPENGL_H__ -#define __MW_OPENGL_H__ +#ifndef __MW_WIDGET_OPENGL_H__ +#define __MW_WIDGET_OPENGL_H__ #include #include diff --git a/include/Mw/Widget/ScrollBar.h b/include/Mw/Widget/ScrollBar.h new file mode 100644 index 0000000..5125a47 --- /dev/null +++ b/include/Mw/Widget/ScrollBar.h @@ -0,0 +1,25 @@ +/* $Id$ */ +/*! + * %file Mw/Widget/ScrollBar.h + * %brief ScrollBar widget + */ +#ifndef __MW_WIDGET_SCROLLBAR_H__ +#define __MW_WIDGET_SCROLLBAR_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * %brief ScrollBar widget class + */ +MWDECL MwClass MwScrollBarClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/Mw/SubMenu.h b/include/Mw/Widget/SubMenu.h similarity index 77% rename from include/Mw/SubMenu.h rename to include/Mw/Widget/SubMenu.h index d7150b8..588a323 100644 --- a/include/Mw/SubMenu.h +++ b/include/Mw/Widget/SubMenu.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/SubMenu.h + * %file Mw/Widget/SubMenu.h * %brief SubMenu widget */ -#ifndef __MW_SUBMENU_H__ -#define __MW_SUBMENU_H__ +#ifndef __MW_WIDGET_SUBMENU_H__ +#define __MW_WIDGET_SUBMENU_H__ #include #include diff --git a/include/Mw/Vulkan.h b/include/Mw/Widget/Vulkan.h similarity index 97% rename from include/Mw/Vulkan.h rename to include/Mw/Widget/Vulkan.h index 57c7ba5..851be64 100644 --- a/include/Mw/Vulkan.h +++ b/include/Mw/Widget/Vulkan.h @@ -1,6 +1,6 @@ /* $Id$ */ /*! - * %file Mw/Vulkan.h + * %file Mw/Widget/Vulkan.h * %brief Vulkan widget * %warning This header is not documented yet */ @@ -9,8 +9,8 @@ * ioixd maintains this file. nishi doesn't know vulkan at all */ -#ifndef __MW_VULKAN_H__ -#define __MW_VULKAN_H__ +#ifndef __MW_WIDGET_VULKAN_H__ +#define __MW_WIDGET_VULKAN_H__ #if !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) #error Vulkan is unsupported on the requested platform. diff --git a/include/Mw/Window.h b/include/Mw/Widget/Window.h similarity index 72% rename from include/Mw/Window.h rename to include/Mw/Widget/Window.h index 6e11144..9e81bf6 100644 --- a/include/Mw/Window.h +++ b/include/Mw/Widget/Window.h @@ -1,10 +1,10 @@ /* $Id$ */ /*! - * %file Mw/Window.h + * %file Mw/Widget/Window.h * %brief Window widget */ -#ifndef __MW_WINDOW_H__ -#define __MW_WINDOW_H__ +#ifndef __MW_WIDGET_WINDOW_H__ +#define __MW_WIDGET_WINDOW_H__ #include #include diff --git a/src/draw.c b/src/draw.c index 020c327..2e56e4a 100644 --- a/src/draw.c +++ b/src/draw.c @@ -48,6 +48,21 @@ MwLLColor MwParseColor(MwWidget handle, const char* text) { return MwLLAllocColor(handle->lowlevel, r, g, b); } +MwLLColor MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b) { + int cr = color->red + r; + int cg = color->green + g; + int cb = color->blue + b; + + if(cr < 0) cr = 0; + if(cg < 0) cg = 0; + if(cb < 0) cb = 0; + if(cr > 255) cr = 255; + if(cg > 255) cg = 255; + if(cb > 255) cb = 255; + + return MwLLAllocColor(handle->lowlevel, cr, cg, cb); +} + void MwDrawRect(MwWidget handle, MwRect* rect, MwLLColor color) { MwPoint p[4]; @@ -177,3 +192,6 @@ MwLLPixmap MwLoadImage(MwWidget handle, const char* path) { return px; } + +void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int direction) { +} diff --git a/src/widget/opengl.c b/src/widget/opengl.c index f589b1c..171f109 100644 --- a/src/widget/opengl.c +++ b/src/widget/opengl.c @@ -1,6 +1,6 @@ /* $Id$ */ #include -#include +#include #ifdef _WIN32 /* nothing */ diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c new file mode 100644 index 0000000..1b2db71 --- /dev/null +++ b/src/widget/scrollbar.c @@ -0,0 +1,38 @@ +/* $Id $*/ +#include + +static int create(MwWidget handle) { + MwSetDefault(handle); + + return 0; +} + +static void draw(MwWidget handle) { + MwRect r, rt; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64); + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + + MwDrawFrame(handle, &r, dark, 1); + MwDrawRect(handle, &r, dark); + + rt = r; + rt.height = rt.width; + MwDrawTriangle(handle, &r, base, 0, MwNORTH); + + MwLLFreeColor(dark); + MwLLFreeColor(base); +} + +MwClassRec MwScrollBarClassRec = { + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL /* parent_resize */ +}; +MwClass MwScrollBarClass = &MwScrollBarClassRec; diff --git a/src/widget/vulkan.c b/src/widget/vulkan.c index 44858ff..02faa83 100644 --- a/src/widget/vulkan.c +++ b/src/widget/vulkan.c @@ -1,6 +1,6 @@ /* $Id$ */ #include -#include +#include #include "../error_internal.h"