add label

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@213 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-08 10:09:10 +00:00
parent b07ee601cd
commit 406452391b
18 changed files with 167 additions and 15 deletions

View File

@@ -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/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/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 L_OBJS += src/cursor/default.o src/cursor/cross.o
OOL_CFLAGS = $(DEPINC) $(CFLAGS) -std=c++98 -fPIC -D_MILSKO OOL_CFLAGS = $(DEPINC) $(CFLAGS) -std=c++98 -fPIC -D_MILSKO
@@ -151,7 +151,7 @@ endif
all: lib examples all: lib examples
lib: src/$(LIB)Mw$(SO) lib: src/$(LIB)Mw$(SO)
oolib: src/$(LIB)MwOO$(SO) oolib: oosrc/$(LIB)MwOO$(SO)
examples: $(EXAMPLES) examples: $(EXAMPLES)
format: format:
@@ -161,7 +161,7 @@ format:
src/$(LIB)Mw$(SO): $(L_OBJS) src/$(LIB)Mw$(SO): $(L_OBJS)
$(CC) $(L_LDFLAGS) $(SHARED) -o $@ $^ $(L_LIBS) $(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) $(CC) $(OOL_LDFLAGS) $(SHARED) -o $@ $(OOL_OBJS) $(OOL_LIBS)
examples/gl%$(EXEC): examples/gl%.o src/$(LIB)Mw$(SO) examples/gl%$(EXEC): examples/gl%.o src/$(LIB)Mw$(SO)
@@ -183,4 +183,4 @@ examples/%.o: examples/%.c
$(CC) $(E_CFLAGS) -c -o $@ $< $(CC) $(E_CFLAGS) -c -o $@ $<
clean: 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

View File

@@ -24,4 +24,13 @@ enum MwORIENTATION {
MwHORIZONTAL MwHORIZONTAL
}; };
/*!
* %brief Alignment
*/
enum MwALIGNMENT {
MwALIGNMENT_CENTER = 0,
MwALIGNMENT_BEGINNING,
MwALIGNMENT_END,
};
#endif #endif

View File

@@ -22,6 +22,7 @@
#include <Mw/Widget/Menu.h> #include <Mw/Widget/Menu.h>
#include <Mw/Widget/SubMenu.h> #include <Mw/Widget/SubMenu.h>
#include <Mw/Widget/Button.h> #include <Mw/Widget/Button.h>
#include <Mw/Widget/Label.h>
#include <Mw/Widget/CheckBox.h> #include <Mw/Widget/CheckBox.h>
#include <Mw/Widget/Frame.h> #include <Mw/Widget/Frame.h>
#include <Mw/Widget/Image.h> #include <Mw/Widget/Image.h>

View File

@@ -16,6 +16,7 @@
#define MwNvalue "Ivalue" #define MwNvalue "Ivalue"
#define MwNareaShown "IareaShown" #define MwNareaShown "IareaShown"
#define MwNchecked "Ichecked" #define MwNchecked "Ichecked"
#define MwNalignment "Ialignment"
#define MwNtitle "Stitle" #define MwNtitle "Stitle"
#define MwNtext "Stext" #define MwNtext "Stext"

View File

@@ -2,7 +2,7 @@
/*! /*!
* %file Mw/Widget/Button.h * %file Mw/Widget/Button.h
* %brief Button widget * %brief Button widget
* %prop MwNpixmap * %prop MwNpixmap MwNtext
*/ */
#ifndef __MW_WIDGET_BUTTON_H__ #ifndef __MW_WIDGET_BUTTON_H__
#define __MW_WIDGET_BUTTON_H__ #define __MW_WIDGET_BUTTON_H__

View File

@@ -2,7 +2,7 @@
/*! /*!
* %file Mw/Widget/CheckBox.h * %file Mw/Widget/CheckBox.h
* %brief CheckBox widget * %brief CheckBox widget
* %prop MwNpixmap * %prop MwNchecked
*/ */
#ifndef __MW_WIDGET_CHECKBOX_H__ #ifndef __MW_WIDGET_CHECKBOX_H__
#define __MW_WIDGET_CHECKBOX_H__ #define __MW_WIDGET_CHECKBOX_H__

26
include/Mw/Widget/Label.h Normal file
View File

@@ -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 <Mw/MachDep.h>
#include <Mw/TypeDefs.h>
#ifdef __cplusplus
extern "C" {
#endif
/*!
* %brief Label widget class
*/
MWDECL MwClass MwLabelClass;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -2,6 +2,7 @@
/*! /*!
* %file Mw/Widget/Window.h * %file Mw/Widget/Window.h
* %brief Window widget * %brief Window widget
* %prop MwNtitle
*/ */
#ifndef __MW_WIDGET_WINDOW_H__ #ifndef __MW_WIDGET_WINDOW_H__
#define __MW_WIDGET_WINDOW_H__ #define __MW_WIDGET_WINDOW_H__

View File

@@ -10,6 +10,8 @@ class Button : public MwOO::Base {
Button(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); Button(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h);
void SetPixmap(void* value); void SetPixmap(void* value);
void* GetPixmap(void); void* GetPixmap(void);
void SetText(const char* value);
const char* GetText(void);
}; };
} // namespace MwOO } // namespace MwOO

View File

@@ -8,8 +8,8 @@ namespace MwOO {
class CheckBox : public MwOO::Base { class CheckBox : public MwOO::Base {
public: public:
CheckBox(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); CheckBox(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h);
void SetPixmap(void* value); void SetChecked(int value);
void* GetPixmap(void); int GetChecked(void);
}; };
} // namespace MwOO } // namespace MwOO

View File

@@ -0,0 +1,18 @@
/* $Id$ */
#ifndef __MWOO_WIDGET_LABEL_H__
#define __MWOO_WIDGET_LABEL_H__
#include <MwOO/Base.h>
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

View File

@@ -8,6 +8,8 @@ namespace MwOO {
class Window : public MwOO::Base { class Window : public MwOO::Base {
public: public:
Window(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); 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 } // namespace MwOO

View File

@@ -1,2 +1,2 @@
# $Id$ # $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

View File

@@ -13,3 +13,11 @@ void* MwOO::Button::GetPixmap(void){
return MwGetVoid(this->widget, MwNpixmap); 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);
}

View File

@@ -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){ 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){ void MwOO::CheckBox::SetChecked(int value){
MwSetVoid(this->widget, MwNpixmap, value); MwSetInteger(this->widget, MwNchecked, value);
} }
void* MwOO::CheckBox::GetPixmap(void){ int MwOO::CheckBox::GetChecked(void){
return MwGetVoid(this->widget, MwNpixmap); return MwGetInteger(this->widget, MwNchecked);
} }

23
oosrc/widget/label.cc Normal file
View File

@@ -0,0 +1,23 @@
/* $Id$ */
#include <MwOO/Widget/Label.h>
#include <Mw/Widget/Label.h>
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);
}

View File

@@ -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){ 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);
}

53
src/widget/label.c Normal file
View File

@@ -0,0 +1,53 @@
/* $Id$ */
#include <Mw/Milsko.h>
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;