From 406452391be922de04dbf9a9e50c9e1ae9f64259 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Wed, 8 Oct 2025 10:09:10 +0000 Subject: [PATCH] add label git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@213 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 8 ++--- include/Mw/Constants.h | 9 ++++++ include/Mw/Milsko.h | 1 + include/Mw/StringDefs.h | 1 + include/Mw/Widget/Button.h | 2 +- include/Mw/Widget/CheckBox.h | 2 +- include/Mw/Widget/Label.h | 26 +++++++++++++++++ include/Mw/Widget/Window.h | 1 + include/MwOO/Widget/Button.h | 6 ++-- include/MwOO/Widget/CheckBox.h | 4 +-- include/MwOO/Widget/Label.h | 18 ++++++++++++ include/MwOO/Widget/Window.h | 2 ++ oosrc/deps.mk | 2 +- oosrc/widget/button.cc | 8 +++++ oosrc/widget/checkbox.cc | 8 ++--- oosrc/widget/label.cc | 23 +++++++++++++++ oosrc/widget/window.cc | 8 +++++ src/widget/label.c | 53 ++++++++++++++++++++++++++++++++++ 18 files changed, 167 insertions(+), 15 deletions(-) create mode 100644 include/Mw/Widget/Label.h create mode 100644 include/MwOO/Widget/Label.h create mode 100644 oosrc/widget/label.cc create mode 100644 src/widget/label.c diff --git a/GNUmakefile b/GNUmakefile index a8d41fe..5bd8131 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 src/widget/checkbox.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 src/widget/label.o L_OBJS += src/cursor/default.o src/cursor/cross.o OOL_CFLAGS = $(DEPINC) $(CFLAGS) -std=c++98 -fPIC -D_MILSKO @@ -151,7 +151,7 @@ endif all: lib examples lib: src/$(LIB)Mw$(SO) -oolib: src/$(LIB)MwOO$(SO) +oolib: oosrc/$(LIB)MwOO$(SO) examples: $(EXAMPLES) format: @@ -161,7 +161,7 @@ format: src/$(LIB)Mw$(SO): $(L_OBJS) $(CC) $(L_LDFLAGS) $(SHARED) -o $@ $^ $(L_LIBS) -src/$(LIB)MwOO$(SO): $(OOL_OBJS) src/$(LIB)Mw$(SO) +oosrc/$(LIB)MwOO$(SO): $(OOL_OBJS) src/$(LIB)Mw$(SO) $(CC) $(OOL_LDFLAGS) $(SHARED) -o $@ $(OOL_OBJS) $(OOL_LIBS) examples/gl%$(EXEC): examples/gl%.o src/$(LIB)Mw$(SO) @@ -183,4 +183,4 @@ examples/%.o: examples/%.c $(CC) $(E_CFLAGS) -c -o $@ $< clean: - rm -f src/*.dll src/*.so src/*.a */*.o */*/*.o external/*/src/*.o examples/*.exe $(EXAMPLES) examples/opengl examples/vulkan + rm -f */*.dll */*.so */*.a */*.o */*/*.o external/*/src/*.o examples/*.exe $(EXAMPLES) examples/opengl examples/vulkan diff --git a/include/Mw/Constants.h b/include/Mw/Constants.h index f3a205e..8c49d75 100644 --- a/include/Mw/Constants.h +++ b/include/Mw/Constants.h @@ -24,4 +24,13 @@ enum MwORIENTATION { MwHORIZONTAL }; +/*! + * %brief Alignment + */ +enum MwALIGNMENT { + MwALIGNMENT_CENTER = 0, + MwALIGNMENT_BEGINNING, + MwALIGNMENT_END, +}; + #endif diff --git a/include/Mw/Milsko.h b/include/Mw/Milsko.h index 23a9e70..9cd5e38 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 7854717..2264917 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -16,6 +16,7 @@ #define MwNvalue "Ivalue" #define MwNareaShown "IareaShown" #define MwNchecked "Ichecked" +#define MwNalignment "Ialignment" #define MwNtitle "Stitle" #define MwNtext "Stext" diff --git a/include/Mw/Widget/Button.h b/include/Mw/Widget/Button.h index a3f8459..0a781b5 100644 --- a/include/Mw/Widget/Button.h +++ b/include/Mw/Widget/Button.h @@ -2,7 +2,7 @@ /*! * %file Mw/Widget/Button.h * %brief Button widget - * %prop MwNpixmap + * %prop MwNpixmap MwNtext */ #ifndef __MW_WIDGET_BUTTON_H__ #define __MW_WIDGET_BUTTON_H__ diff --git a/include/Mw/Widget/CheckBox.h b/include/Mw/Widget/CheckBox.h index 038a8b0..927be2c 100644 --- a/include/Mw/Widget/CheckBox.h +++ b/include/Mw/Widget/CheckBox.h @@ -2,7 +2,7 @@ /*! * %file Mw/Widget/CheckBox.h * %brief CheckBox widget - * %prop MwNpixmap + * %prop MwNchecked */ #ifndef __MW_WIDGET_CHECKBOX_H__ #define __MW_WIDGET_CHECKBOX_H__ diff --git a/include/Mw/Widget/Label.h b/include/Mw/Widget/Label.h new file mode 100644 index 0000000..a1a31b9 --- /dev/null +++ b/include/Mw/Widget/Label.h @@ -0,0 +1,26 @@ +/* $Id$ */ +/*! + * %file Mw/Widget/Label.h + * %brief Label widget + * %prop MwNtext MwNalignment + */ +#ifndef __MW_WIDGET_LABEL_H__ +#define __MW_WIDGET_LABEL_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * %brief Label widget class + */ +MWDECL MwClass MwLabelClass; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/Mw/Widget/Window.h b/include/Mw/Widget/Window.h index 9e81bf6..a229c95 100644 --- a/include/Mw/Widget/Window.h +++ b/include/Mw/Widget/Window.h @@ -2,6 +2,7 @@ /*! * %file Mw/Widget/Window.h * %brief Window widget + * %prop MwNtitle */ #ifndef __MW_WIDGET_WINDOW_H__ #define __MW_WIDGET_WINDOW_H__ diff --git a/include/MwOO/Widget/Button.h b/include/MwOO/Widget/Button.h index e4cad8e..44c5131 100644 --- a/include/MwOO/Widget/Button.h +++ b/include/MwOO/Widget/Button.h @@ -8,8 +8,10 @@ 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); + void SetPixmap(void* value); + void* GetPixmap(void); + void SetText(const char* value); + const char* GetText(void); }; } // namespace MwOO diff --git a/include/MwOO/Widget/CheckBox.h b/include/MwOO/Widget/CheckBox.h index 9dd4662..ed922ff 100644 --- a/include/MwOO/Widget/CheckBox.h +++ b/include/MwOO/Widget/CheckBox.h @@ -8,8 +8,8 @@ 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); + void SetChecked(int value); + int GetChecked(void); }; } // namespace MwOO diff --git a/include/MwOO/Widget/Label.h b/include/MwOO/Widget/Label.h new file mode 100644 index 0000000..8098b2e --- /dev/null +++ b/include/MwOO/Widget/Label.h @@ -0,0 +1,18 @@ +/* $Id$ */ +#ifndef __MWOO_WIDGET_LABEL_H__ +#define __MWOO_WIDGET_LABEL_H__ + +#include + +namespace MwOO { +class Label : public MwOO::Base { + public: + Label(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void SetText(const char* value); + const char* GetText(void); + void SetAlignment(int value); + int GetAlignment(void); +}; +} // namespace MwOO + +#endif diff --git a/include/MwOO/Widget/Window.h b/include/MwOO/Widget/Window.h index 0d07a21..53fe888 100644 --- a/include/MwOO/Widget/Window.h +++ b/include/MwOO/Widget/Window.h @@ -8,6 +8,8 @@ namespace MwOO { class Window : public MwOO::Base { public: Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); + void SetTitle(const char* value); + const char* GetTitle(void); }; } // namespace MwOO diff --git a/oosrc/deps.mk b/oosrc/deps.mk index 335340f..cb24f7c 100644 --- a/oosrc/deps.mk +++ b/oosrc/deps.mk @@ -1,2 +1,2 @@ # $Id$ -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 +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 oosrc/widget/checkbox.o oosrc/widget/label.o diff --git a/oosrc/widget/button.cc b/oosrc/widget/button.cc index d042fcb..d70a37a 100644 --- a/oosrc/widget/button.cc +++ b/oosrc/widget/button.cc @@ -13,3 +13,11 @@ void* MwOO::Button::GetPixmap(void){ return MwGetVoid(this->widget, MwNpixmap); } +void MwOO::Button::SetText(const char* value){ + MwSetText(this->widget, MwNtext, value); +} + +const char* MwOO::Button::GetText(void){ + return MwGetText(this->widget, MwNtext); +} + diff --git a/oosrc/widget/checkbox.cc b/oosrc/widget/checkbox.cc index 2a58676..bb066c6 100644 --- a/oosrc/widget/checkbox.cc +++ b/oosrc/widget/checkbox.cc @@ -5,11 +5,11 @@ 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::SetChecked(int value){ + MwSetInteger(this->widget, MwNchecked, value); } -void* MwOO::CheckBox::GetPixmap(void){ - return MwGetVoid(this->widget, MwNpixmap); +int MwOO::CheckBox::GetChecked(void){ + return MwGetInteger(this->widget, MwNchecked); } diff --git a/oosrc/widget/label.cc b/oosrc/widget/label.cc new file mode 100644 index 0000000..2c425e2 --- /dev/null +++ b/oosrc/widget/label.cc @@ -0,0 +1,23 @@ +/* $Id$ */ +#include +#include + +MwOO::Label::Label(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwLabelClass, widget_name, parent, x, y, w, h){ +} + +void MwOO::Label::SetText(const char* value){ + MwSetText(this->widget, MwNtext, value); +} + +const char* MwOO::Label::GetText(void){ + return MwGetText(this->widget, MwNtext); +} + +void MwOO::Label::SetAlignment(int value){ + MwSetInteger(this->widget, MwNalignment, value); +} + +int MwOO::Label::GetAlignment(void){ + return MwGetInteger(this->widget, MwNalignment); +} + diff --git a/oosrc/widget/window.cc b/oosrc/widget/window.cc index a0928a7..8cdf89c 100644 --- a/oosrc/widget/window.cc +++ b/oosrc/widget/window.cc @@ -5,3 +5,11 @@ MwOO::Window::Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h) : MwOO::Base(MwWindowClass, widget_name, parent, x, y, w, h){ } +void MwOO::Window::SetTitle(const char* value){ + MwSetText(this->widget, MwNtitle, value); +} + +const char* MwOO::Window::GetTitle(void){ + return MwGetText(this->widget, MwNtitle); +} + diff --git a/src/widget/label.c b/src/widget/label.c new file mode 100644 index 0000000..50f6a91 --- /dev/null +++ b/src/widget/label.c @@ -0,0 +1,53 @@ +/* $Id$ */ +#include + +static int create(MwWidget handle) { + MwSetDefault(handle); + MwSetInteger(handle, MwNalignment, MwALIGNMENT_CENTER); + + return 0; +} + +static void draw(MwWidget handle) { + MwRect r; + MwPoint p; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground)); + int align; + const char* str = MwGetText(handle, MwNtext); + + if(str == NULL) str = ""; + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + + MwDrawRect(handle, &r, base); + + align = MwGetInteger(handle, MwNalignment); + 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, 0, text); + + MwLLFreeColor(text); + MwLLFreeColor(base); +} + +MwClassRec MwLabelClassRec = { + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL /* mouse_down */ +}; +MwClass MwLabelClass = &MwLabelClassRec;