diff --git a/GNUmakefile b/GNUmakefile index 4644037..a8d41fe 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -28,7 +28,7 @@ L_LIBS = $(LIBS) 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 src/widget/scrollbar.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 src/widget/checkbox.o L_OBJS += src/cursor/default.o src/cursor/cross.o OOL_CFLAGS = $(DEPINC) $(CFLAGS) -std=c++98 -fPIC -D_MILSKO diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index 2a7eea6..23a9e70 100644 --- a/include/Mw/Milsko.h +++ b/include/Mw/Milsko.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index 7a1af6d..7854717 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -15,6 +15,7 @@ #define MwNmaxValue "ImaxValue" #define MwNvalue "Ivalue" #define MwNareaShown "IareaShown" +#define MwNchecked "Ichecked" #define MwNtitle "Stitle" #define MwNtext "Stext" @@ -30,5 +31,6 @@ #define MwNmenuHandler "Cmenu" #define MwNmouseDownHandler "CmouseDownHandler" #define MwNmouseUpHandler "CmouseUpHandler" +#define MwNchangedHandler "CchangedHandler" #endif diff --git a/include/Mw/Widget/CheckBox.h b/include/Mw/Widget/CheckBox.h new file mode 100644 index 0000000..038a8b0 --- /dev/null +++ b/include/Mw/Widget/CheckBox.h @@ -0,0 +1,26 @@ +/* $Id: CheckBox.h 206 2025-10-07 15:10:46Z nishi $ */ +/*! + * %file Mw/Widget/CheckBox.h + * %brief CheckBox widget + * %prop MwNpixmap + */ +#ifndef __MW_WIDGET_CHECKBOX_H__ +#define __MW_WIDGET_CHECKBOX_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * %brief CheckBox widget class + */ +MWDECL MwClass MwCheckBoxClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/MwOO/Base.h b/include/MwOO/Base.h index cba4ecf..e5bc290 100644 --- a/include/MwOO/Base.h +++ b/include/MwOO/Base.h @@ -26,15 +26,16 @@ class Base { int GetY(void); int GetWidth(void); int GetHeight(void); - /* BEGIN AUTOGENERATE */ - virtual void OnActivate(void*) {}; - virtual void OnResize(void*) {}; - virtual void OnTick(void*) {}; - virtual void OnMenu(void*) {}; - virtual void OnMouseDownHandler(void*) {}; - virtual void OnMouseUpHandler(void*) {}; +/* BEGIN AUTOGENERATE */ + virtual void OnActivate(void*){}; + virtual void OnResize(void*){}; + virtual void OnTick(void*){}; + virtual void OnMenu(void*){}; + virtual void OnMouseDownHandler(void*){}; + virtual void OnMouseUpHandler(void*){}; + virtual void OnChangedHandler(void*){}; - /* END AUTOGENERATE */ +/* END AUTOGENERATE */ Base(MwClass widget_class, const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); ~Base(void); diff --git a/include/MwOO/Widget/Button.h b/include/MwOO/Widget/Button.h index e4cad8e..80f72cd 100644 --- a/include/MwOO/Widget/Button.h +++ b/include/MwOO/Widget/Button.h @@ -5,12 +5,12 @@ #include namespace MwOO { -class Button : public MwOO::Base { - public: - Button(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - void SetPixmap(void* value); - void* GetPixmap(void); -}; -} // namespace MwOO + class Button : public MwOO::Base { + public: + Button(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void SetPixmap(void* value); + void* GetPixmap(void); + }; +} #endif diff --git a/include/MwOO/Widget/CheckBox.h b/include/MwOO/Widget/CheckBox.h new file mode 100644 index 0000000..ec3ee7b --- /dev/null +++ b/include/MwOO/Widget/CheckBox.h @@ -0,0 +1,16 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_CHECKBOX_H__ +#define __MWOO_WIDGET_CHECKBOX_H__ + +#include + +namespace MwOO { + class CheckBox : public MwOO::Base { + public: + CheckBox(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void SetPixmap(void* value); + void* GetPixmap(void); + }; +} + +#endif diff --git a/include/MwOO/Widget/Frame.h b/include/MwOO/Widget/Frame.h index f5d7057..84ddc30 100644 --- a/include/MwOO/Widget/Frame.h +++ b/include/MwOO/Widget/Frame.h @@ -5,10 +5,10 @@ #include namespace MwOO { -class Frame : public MwOO::Base { - public: - Frame(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); -}; -} // namespace MwOO + class Frame : public MwOO::Base { + public: + Frame(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + }; +} #endif diff --git a/include/MwOO/Widget/Image.h b/include/MwOO/Widget/Image.h index 3864020..e9eb8f6 100644 --- a/include/MwOO/Widget/Image.h +++ b/include/MwOO/Widget/Image.h @@ -5,12 +5,12 @@ #include namespace MwOO { -class Image : public MwOO::Base { - public: - Image(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - void SetPixmap(void* value); - void* GetPixmap(void); -}; -} // namespace MwOO + class Image : public MwOO::Base { + public: + Image(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void SetPixmap(void* value); + void* GetPixmap(void); + }; +} #endif diff --git a/include/MwOO/Widget/Menu.h b/include/MwOO/Widget/Menu.h index 5d9d4a1..83c624b 100644 --- a/include/MwOO/Widget/Menu.h +++ b/include/MwOO/Widget/Menu.h @@ -5,11 +5,11 @@ #include namespace MwOO { -class Menu : public MwOO::Base { - public: - Menu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - MwMenu Add(MwMenu menu, const char* name); -}; -} // namespace MwOO + class Menu : public MwOO::Base { + public: + Menu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + MwMenu Add(MwMenu menu, const char* name); + }; +} #endif diff --git a/include/MwOO/Widget/OpenGL.h b/include/MwOO/Widget/OpenGL.h index e2276ae..eb53dd3 100644 --- a/include/MwOO/Widget/OpenGL.h +++ b/include/MwOO/Widget/OpenGL.h @@ -5,13 +5,13 @@ #include namespace MwOO { -class OpenGL : public MwOO::Base { - public: - OpenGL(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - void MakeCurrent(void); - void* GetProcAddress(const char* name); - void SwapBuffer(void); -}; -} // namespace MwOO + class OpenGL : public MwOO::Base { + public: + OpenGL(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void MakeCurrent(void); + void* GetProcAddress(const char* name); + void SwapBuffer(void); + }; +} #endif diff --git a/include/MwOO/Widget/ScrollBar.h b/include/MwOO/Widget/ScrollBar.h index a361a81..7bae3f2 100644 --- a/include/MwOO/Widget/ScrollBar.h +++ b/include/MwOO/Widget/ScrollBar.h @@ -5,21 +5,21 @@ #include namespace MwOO { -class ScrollBar : public MwOO::Base { - public: - ScrollBar(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - int GetVisibleLength(void); - void SetAreaShown(int value); - int GetAreaShown(void); - void SetValue(int value); - int GetValue(void); - void SetMinValue(int value); - int GetMinValue(void); - void SetMaxValue(int value); - int GetMaxValue(void); - void SetOrientation(int value); - int GetOrientation(void); -}; -} // namespace MwOO + class ScrollBar : public MwOO::Base { + public: + ScrollBar(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + int GetVisibleLength(void); + void SetAreaShown(int value); + int GetAreaShown(void); + void SetValue(int value); + int GetValue(void); + void SetMinValue(int value); + int GetMinValue(void); + void SetMaxValue(int value); + int GetMaxValue(void); + void SetOrientation(int value); + int GetOrientation(void); + }; +} #endif diff --git a/include/MwOO/Widget/SubMenu.h b/include/MwOO/Widget/SubMenu.h index 38c24c9..af7f338 100644 --- a/include/MwOO/Widget/SubMenu.h +++ b/include/MwOO/Widget/SubMenu.h @@ -5,11 +5,11 @@ #include namespace MwOO { -class SubMenu : public MwOO::Base { - public: - SubMenu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - void Appear(MwMenu menu, MwPoint* point); -}; -} // namespace MwOO + class SubMenu : public MwOO::Base { + public: + SubMenu(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void Appear(MwMenu menu, MwPoint* point); + }; +} #endif diff --git a/include/MwOO/Widget/Vulkan.h b/include/MwOO/Widget/Vulkan.h index ff74da2..fdab378 100644 --- a/include/MwOO/Widget/Vulkan.h +++ b/include/MwOO/Widget/Vulkan.h @@ -5,15 +5,15 @@ #include namespace MwOO { -class Vulkan : public MwOO::Base { - public: - Vulkan(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); - void EnableExtension(void); - void EnableLayer(void); - void Configure(void); - void* GetField(MwVulkanField field, MwErrorEnum* out); - VkBool32 Supported(void); -}; -} // namespace MwOO + class Vulkan : public MwOO::Base { + public: + Vulkan(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void EnableExtension(void); + void EnableLayer(void); + void Configure(void); + void* GetField(MwVulkanField field, MwErrorEnum* out); + VkBool32 Supported(void); + }; +} #endif diff --git a/include/MwOO/Widget/Window.h b/include/MwOO/Widget/Window.h index 0d07a21..8f96124 100644 --- a/include/MwOO/Widget/Window.h +++ b/include/MwOO/Widget/Window.h @@ -5,10 +5,10 @@ #include namespace MwOO { -class Window : public MwOO::Base { - public: - Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); -}; -} // namespace MwOO + class Window : public MwOO::Base { + public: + Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + }; +} #endif diff --git a/oosrc/base.cc b/oosrc/base.cc index f54334c..a405749 100644 --- a/oosrc/base.cc +++ b/oosrc/base.cc @@ -73,6 +73,10 @@ static void __OnMouseUpHandler(MwWidget widget, void* user, void* call){ MwOO::Base* c = (MwOO::Base*)user; c->OnMouseUpHandler(call); } +static void __OnChangedHandler(MwWidget widget, void* user, void* call){ + MwOO::Base* c = (MwOO::Base*)user; + c->OnChangedHandler(call); +} void MwOO::Base::SetHandler(void){ MwAddUserHandler(this->widget, MwNactivateHandler, __OnActivate, this); @@ -81,5 +85,6 @@ void MwOO::Base::SetHandler(void){ MwAddUserHandler(this->widget, MwNmenuHandler, __OnMenu, this); MwAddUserHandler(this->widget, MwNmouseDownHandler, __OnMouseDownHandler, this); MwAddUserHandler(this->widget, MwNmouseUpHandler, __OnMouseUpHandler, this); + MwAddUserHandler(this->widget, MwNchangedHandler, __OnChangedHandler, this); } /* END AUTOGENERATE */ diff --git a/oosrc/deps.mk b/oosrc/deps.mk index 1c7af34..335340f 100644 --- a/oosrc/deps.mk +++ b/oosrc/deps.mk @@ -1,2 +1,2 @@ # $Id$ -OOL_OBJS += oosrc/widget/button.o oosrc/widget/frame.o oosrc/widget/image.o oosrc/widget/menu.o oosrc/widget/scrollbar.o oosrc/widget/submenu.o oosrc/widget/window.o +OOL_OBJS += oosrc/widget/button.o oosrc/widget/menu.o oosrc/widget/window.o oosrc/widget/image.o oosrc/widget/submenu.o oosrc/widget/frame.o oosrc/widget/scrollbar.o oosrc/widget/checkbox.o diff --git a/oosrc/widget/checkbox.cc b/oosrc/widget/checkbox.cc new file mode 100644 index 0000000..2a58676 --- /dev/null +++ b/oosrc/widget/checkbox.cc @@ -0,0 +1,15 @@ +/* $Id$ */ +#include +#include + +MwOO::CheckBox::CheckBox(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwCheckBoxClass, widget_name, parent, x, y, w, h){ +} + +void MwOO::CheckBox::SetPixmap(void* value){ + MwSetVoid(this->widget, MwNpixmap, value); +} + +void* MwOO::CheckBox::GetPixmap(void){ + return MwGetVoid(this->widget, MwNpixmap); +} + diff --git a/src/widget/checkbox.c b/src/widget/checkbox.c new file mode 100644 index 0000000..cfa146c --- /dev/null +++ b/src/widget/checkbox.c @@ -0,0 +1,46 @@ +/* $Id: button.c 168 2025-10-04 19:30:58Z nishi $ */ +#include + +static int create(MwWidget handle) { + MwSetDefault(handle); + + MwSetInteger(handle, MwNchecked, 0); + + return 0; +} + +static void draw(MwWidget handle) { + MwRect r; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + + MwDrawFrame(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0); + MwDrawRect(handle, &r, base); + if(handle->pressed || MwGetInteger(handle, MwNchecked)){ + /* TODO: write check mark */ + } + + MwLLFreeColor(base); +} + +static void click(MwWidget handle) { + MwSetInteger(handle, MwNchecked, MwGetInteger(handle, MwNchecked) ? 0 : 1); + + MwDispatchUserHandler(handle, MwNchangedHandler, NULL); +} + +MwClassRec MwCheckBoxClassRec = { + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + click, /* click */ + NULL, /* parent_resize */ + NULL, /* mouse_move */ + MwForceRender, /* mouse_up */ + MwForceRender /* mouse_down */ +}; +MwClass MwCheckBoxClass = &MwCheckBoxClassRec;