From 8532ac96eca2f465df1b795bab90e2c99b0af4ba Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sat, 11 Oct 2025 15:03:56 +0000 Subject: [PATCH] viewport seems to work git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@275 b9cfdab3-6d41-4d17-bbe4-086880011989 --- doc/index.html | 56 +++++++++++++++ include/Mw/Widget/Viewport.h | 15 +++- include/MwOO/Widget/Viewport.h | 1 + oosrc/widget/viewport.cc | 3 + resource/icon/error.png | Bin 663 -> 663 bytes resource/icon/info.png | Bin 434 -> 434 bytes resource/icon/news.png | Bin 542 -> 542 bytes resource/icon/note.png | Bin 594 -> 594 bytes resource/icon/question.png | Bin 529 -> 529 bytes resource/icon/warning.png | Bin 498 -> 498 bytes src/widget/scrollbar.c | 3 + src/widget/viewport.c | 125 ++++++++++++++++++++++++++++++--- 12 files changed, 191 insertions(+), 12 deletions(-) diff --git a/doc/index.html b/doc/index.html index c2cdfcf..487a837 100644 --- a/doc/index.html +++ b/doc/index.html @@ -398,6 +398,12 @@
MwViewportClass
+
+ MwViewportGetViewport +
+
+ MwViewportSetSize +
Mw/Widget/Vulkan.h
@@ -2518,6 +2524,56 @@
+
MWDECL MwWidget MwViewportGetViewport (
+	MwWidget handle
+);
+
+
+ Get parent widget where widgets should be placed. +
+
+ Parameter handle +
+
+ Widget. +
+
+ Returns +
+
+ Widget. +
+
+
+
MWDECL void MwViewportSetSize (
+	MwWidget handle,
+	int w,
+	int h
+);
+
+
+ Set viewport size. +
+
+ Parameter handle +
+
+ Widget. +
+
+ Parameter w +
+
+ Width. +
+
+ Parameter h +
+
+ Height. +
+
+

Mw/Widget/Vulkan.h

diff --git a/include/Mw/Widget/Viewport.h b/include/Mw/Widget/Viewport.h index f9bb928..5a006d6 100644 --- a/include/Mw/Widget/Viewport.h +++ b/include/Mw/Widget/Viewport.h @@ -18,7 +18,20 @@ extern "C" { */ MWDECL MwClass MwViewportClass; -MWDECL MwWidget MwViewportGetViewport(MwWidget widget); +/*! + * %brief Get parent widget where widgets should be placed + * %param handle Widget + * %return Widget + */ +MWDECL MwWidget MwViewportGetViewport(MwWidget handle); + +/*! + * %brief Set viewport size + * %param handle Widget + * %param w Width + * %param h Height + */ +MWDECL void MwViewportSetSize(MwWidget handle, int w, int h); #ifdef __cplusplus } diff --git a/include/MwOO/Widget/Viewport.h b/include/MwOO/Widget/Viewport.h index f015866..ac1b482 100644 --- a/include/MwOO/Widget/Viewport.h +++ b/include/MwOO/Widget/Viewport.h @@ -9,6 +9,7 @@ class Viewport : public MwOO::Base { public: Viewport(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h); MwOO::Base GetViewport(void); + void SetSize(int w, int h); void SetBackground(const char* value); const char* GetBackground(void); void SetForeground(const char* value); diff --git a/oosrc/widget/viewport.cc b/oosrc/widget/viewport.cc index 33cf916..0fcb25d 100644 --- a/oosrc/widget/viewport.cc +++ b/oosrc/widget/viewport.cc @@ -8,6 +8,9 @@ MwOO::Viewport::Viewport(const char* widget_name, MwOO::Base* parent, int x, int MwOO::Base MwOO::Viewport::GetViewport(void){ return MwOO::Base(MwViewportGetViewport(this->widget)); } +void MwOO::Viewport::SetSize(int w, int h){ + MwViewportSetSize(this->widget, w, h); +} void MwOO::Viewport::SetBackground(const char* value){ MwSetText(this->widget, MwNbackground, value); } diff --git a/resource/icon/error.png b/resource/icon/error.png index 60fd8e6da98fc5a874fc5dfc194cd587cb1cbb5d..cca34c5363a2b278e9cf704e6516e982e6a5dcf1 100644 GIT binary patch delta 48 zcmbQvI-PaGbasAbt=Uf&C2gE{hf&tl%D~vl#7Nt~z{G14|Lure?RHJe|+00f?{elF{r5}E*J CUJcU# delta 48 zcmdnQyoq^2H#?uAaMDD!+KrQ#8D&kZjE$`fEwv2{tPBjImsVvl0D-5gpUXO@geCw* C$_*R< diff --git a/resource/icon/news.png b/resource/icon/news.png index 92c912147e354b4b7e2b65d52b0b60b968355205..e635340a7a508096a7e8d03da0fc81847f30bb0c 100644 GIT binary patch delta 48 zcmbQoGLL1#M0S2=t=Uf&C2gFM$tY`TWngS&Vx(&}T51~@SQ!{ZFRjXA00K`}KbLh*2~7Y^ CRt;zX diff --git a/resource/icon/note.png b/resource/icon/note.png index 5f60cf7940bdba92e55d4fe3d6a4b0fc44ec2078..cda117293a17037b07f4a08a5e76b5002bae7027 100644 GIT binary patch delta 48 zcmcb_a*1WabasAbt=Uf&C2gEHol(}*%D~vl#7Nt~z{8xu delta 48 zcmcb_a*1Wabap;P;iQRdwHxP6XOuOuGB&m{wA3~*ure@+URssK00f?{elF{r5}E*K C_6`aF diff --git a/resource/icon/question.png b/resource/icon/question.png index 3ed1f94010578443cfabb1bae03b6ec228ea145a..8954a0dc01ec4d67c9681a54807fc6ca28716dd5 100644 GIT binary patch delta 48 zcmbQpGLdD%M0S2=t=Uf&C2gD$!zgQNWngS&Vx(&}T51~@SQ!{ZFRjXA00K`}KbLh*2~7Y- C@C`u# diff --git a/resource/icon/warning.png b/resource/icon/warning.png index d655c07d2a16b1dd4f474f5391eb2bac4aa89e1a..1aa596dd7c4ca98f0c8aaa2738864001fd217595 100644 GIT binary patch delta 48 zcmeyw{E2zOM0S2=t=Uf&C2gEx%P4DVWngS&Vx(&}T51~@SQ!{ZFRjXA00K`}KbLh*2~7ZI CQVrq& diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index e0596f4..c377eb9 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -32,6 +32,7 @@ static int calc_length(MwWidget handle) { int max = MwScrollBarGetVisibleLength(handle); int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue); int area = MwGetInteger(handle, MwNareaShown); + if(area > MwGetInteger(handle, MwNmaxValue)) area = MwGetInteger(handle, MwNmaxValue); return max * (double)area / len; } @@ -55,6 +56,7 @@ static void add_value(MwWidget handle, int mul) { if(val > max) val = max; MwSetInteger(handle, MwNvalue, val); + MwDispatchUserHandler(handle, MwNchangedHandler, NULL); } static void draw(MwWidget handle) { @@ -151,6 +153,7 @@ static void mouse_move(MwWidget handle) { if(len < 0) len = 0; if(len > 1) len = 1; MwSetInteger(handle, MwNvalue, (int)((max - min) * len - min)); + MwDispatchUserHandler(handle, MwNchangedHandler, NULL); MwForceRender(handle); } diff --git a/src/widget/viewport.c b/src/widget/viewport.c index f46c2c3..dff85dc 100644 --- a/src/widget/viewport.c +++ b/src/widget/viewport.c @@ -1,9 +1,88 @@ /* $Id$ */ #include +typedef struct viewport { + MwWidget vscroll; + MwWidget hscroll; + MwWidget frame; + MwWidget inframe; +} viewport_t; + +static void vscroll_changed(MwWidget handle, void* user, void* call) { + viewport_t* vp = user; + int v = MwGetInteger(handle, MwNvalue); + MwVaApply(vp->inframe, + MwNy, -v, + NULL); +} + +static void hscroll_changed(MwWidget handle, void* user, void* call) { + viewport_t* vp = user; + int v = MwGetInteger(handle, MwNvalue); + MwVaApply(vp->inframe, + MwNx, -v, + NULL); +} + +static void resize(MwWidget handle) { + viewport_t* vp = handle->internal; + int w = MwGetInteger(handle, MwNwidth); + int h = MwGetInteger(handle, MwNheight); + if(vp->vscroll == NULL) { + vp->vscroll = MwVaCreateWidget(MwScrollBarClass, "vscroll", handle, w - 16, 0, 16, h - 16, NULL); + MwAddUserHandler(vp->vscroll, MwNchangedHandler, vscroll_changed, vp); + } else { + MwVaApply(vp->vscroll, + MwNx, w - 16, + MwNy, 0, + MwNwidth, 16, + MwNheight, h - 16, + NULL); + } + if(vp->hscroll == NULL) { + vp->hscroll = MwVaCreateWidget(MwScrollBarClass, "hscroll", handle, 0, h - 16, w - 16, 16, MwNorientation, MwHORIZONTAL, NULL); + MwAddUserHandler(vp->hscroll, MwNchangedHandler, hscroll_changed, vp); + } else { + MwVaApply(vp->hscroll, + MwNx, 0, + MwNy, h - 16, + MwNwidth, w - 16, + MwNheight, 16, + NULL); + } + if(vp->frame == NULL) { + vp->frame = MwCreateWidget(MwFrameClass, "frame", handle, 0, 0, w - 16, h - 16); + } else { + MwVaApply(vp->frame, + MwNx, 0, + MwNy, 0, + MwNwidth, w - 16, + MwNheight, h - 16, + NULL); + } + if(vp->inframe == NULL) { + vp->inframe = MwCreateWidget(MwFrameClass, "inframe", vp->frame, 0, 0, w - 16, h - 16); + } + + MwVaApply(vp->vscroll, + MwNareaShown, h - 16, + NULL); + + MwVaApply(vp->hscroll, + MwNareaShown, w - 16, + NULL); +} + static int create(MwWidget handle) { + viewport_t* vp = malloc(sizeof(*vp)); + memset(vp, 0, sizeof(*vp)); + + handle->internal = vp; + MwSetDefault(handle); + resize(handle); + return 0; } @@ -21,23 +100,47 @@ static void draw(MwWidget handle) { MwLLFreeColor(base); } -MwWidget MwViewportGetViewport(MwWidget widget) { +static void prop_change(MwWidget handle, const char* prop) { + if(strcmp(prop, MwNwidth) == 0 || strcmp(prop, MwNheight) == 0) resize(handle); } MwClassRec MwViewportClassRec = { - create, /* create */ - NULL, /* destroy */ - draw, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - NULL, /* mouse_move */ - NULL, /* mouse_up */ - NULL, /* mouse_down */ - NULL, /* key */ + create, /* create */ + NULL, /* destroy */ + draw, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL, /* mouse_down */ + NULL, /* key */ NULL, NULL, NULL, NULL, NULL}; MwClass MwViewportClass = &MwViewportClassRec; + +MwWidget MwViewportGetViewport(MwWidget handle) { + viewport_t* vp = handle->internal; + + return vp->inframe; +} + +void MwViewportSetSize(MwWidget handle, int w, int h) { + viewport_t* vp = handle->internal; + + MwVaApply(vp->vscroll, + MwNmaxValue, h, + NULL); + + MwVaApply(vp->hscroll, + MwNmaxValue, w, + NULL); + + MwVaApply(vp->inframe, + MwNwidth, w, + MwNheight, h, + NULL); +}