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 60fd8e6..cca34c5 100644 Binary files a/resource/icon/error.png and b/resource/icon/error.png differ diff --git a/resource/icon/info.png b/resource/icon/info.png index 79bee5a..f4ce4c4 100644 Binary files a/resource/icon/info.png and b/resource/icon/info.png differ diff --git a/resource/icon/news.png b/resource/icon/news.png index 92c9121..e635340 100644 Binary files a/resource/icon/news.png and b/resource/icon/news.png differ diff --git a/resource/icon/note.png b/resource/icon/note.png index 5f60cf7..cda1172 100644 Binary files a/resource/icon/note.png and b/resource/icon/note.png differ diff --git a/resource/icon/question.png b/resource/icon/question.png index 3ed1f94..8954a0d 100644 Binary files a/resource/icon/question.png and b/resource/icon/question.png differ diff --git a/resource/icon/warning.png b/resource/icon/warning.png index d655c07..1aa596d 100644 Binary files a/resource/icon/warning.png and b/resource/icon/warning.png differ 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); +}