viewport seems to work
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@275 b9cfdab3-6d41-4d17-bbe4-086880011989
@@ -398,6 +398,12 @@
|
|||||||
<dd>
|
<dd>
|
||||||
<a href="#Mw_Widget_Viewport_h__MwViewportClass">MwViewportClass</a>
|
<a href="#Mw_Widget_Viewport_h__MwViewportClass">MwViewportClass</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
<dd>
|
||||||
|
<a href="#Mw_Widget_Viewport_h__MwViewportGetViewport">MwViewportGetViewport</a>
|
||||||
|
</dd>
|
||||||
|
<dd>
|
||||||
|
<a href="#Mw_Widget_Viewport_h__MwViewportSetSize">MwViewportSetSize</a>
|
||||||
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a href="#Mw_Widget_Vulkan_h">Mw/Widget/Vulkan.h</a>
|
<a href="#Mw_Widget_Vulkan_h">Mw/Widget/Vulkan.h</a>
|
||||||
</dt>
|
</dt>
|
||||||
@@ -2518,6 +2524,56 @@
|
|||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<hr>
|
<hr>
|
||||||
|
<pre id="Mw_Widget_Viewport_h__MwViewportGetViewport">MWDECL MwWidget <B><FONT COLOR="#0000FF">MwViewportGetViewport</FONT></B> (
|
||||||
|
MwWidget handle
|
||||||
|
);</pre>
|
||||||
|
<dl>
|
||||||
|
<dd>
|
||||||
|
Get parent widget where widgets should be placed.
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
Parameter <code>handle</code>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Widget.
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
Returns
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Widget.
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<hr>
|
||||||
|
<pre id="Mw_Widget_Viewport_h__MwViewportSetSize">MWDECL <B><FONT COLOR="#228B22">void</FONT></B> <B><FONT COLOR="#0000FF">MwViewportSetSize</FONT></B> (
|
||||||
|
MwWidget handle,
|
||||||
|
<B><FONT COLOR="#228B22">int</FONT></B> w,
|
||||||
|
<B><FONT COLOR="#228B22">int</FONT></B> h
|
||||||
|
);</pre>
|
||||||
|
<dl>
|
||||||
|
<dd>
|
||||||
|
Set viewport size.
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
Parameter <code>handle</code>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Widget.
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
Parameter <code>w</code>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Width.
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
Parameter <code>h</code>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Height.
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
<hr>
|
||||||
<h2 align="center" id="Mw_Widget_Vulkan_h">Mw/Widget/Vulkan.h</h2>
|
<h2 align="center" id="Mw_Widget_Vulkan_h">Mw/Widget/Vulkan.h</h2>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
|
|||||||
@@ -18,7 +18,20 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
MWDECL MwClass MwViewportClass;
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class Viewport : public MwOO::Base {
|
|||||||
public:
|
public:
|
||||||
Viewport(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h);
|
Viewport(const char* widget_name, MwOO::Base* parent, int x, int y, int w, int h);
|
||||||
MwOO::Base GetViewport(void);
|
MwOO::Base GetViewport(void);
|
||||||
|
void SetSize(int w, int h);
|
||||||
void SetBackground(const char* value);
|
void SetBackground(const char* value);
|
||||||
const char* GetBackground(void);
|
const char* GetBackground(void);
|
||||||
void SetForeground(const char* value);
|
void SetForeground(const char* value);
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ MwOO::Viewport::Viewport(const char* widget_name, MwOO::Base* parent, int x, int
|
|||||||
MwOO::Base MwOO::Viewport::GetViewport(void){
|
MwOO::Base MwOO::Viewport::GetViewport(void){
|
||||||
return MwOO::Base(MwViewportGetViewport(this->widget));
|
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){
|
void MwOO::Viewport::SetBackground(const char* value){
|
||||||
MwSetText(this->widget, MwNbackground, value);
|
MwSetText(this->widget, MwNbackground, value);
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 663 B After Width: | Height: | Size: 663 B |
|
Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 434 B |
|
Before Width: | Height: | Size: 542 B After Width: | Height: | Size: 542 B |
|
Before Width: | Height: | Size: 594 B After Width: | Height: | Size: 594 B |
|
Before Width: | Height: | Size: 529 B After Width: | Height: | Size: 529 B |
|
Before Width: | Height: | Size: 498 B After Width: | Height: | Size: 498 B |
@@ -32,6 +32,7 @@ static int calc_length(MwWidget handle) {
|
|||||||
int max = MwScrollBarGetVisibleLength(handle);
|
int max = MwScrollBarGetVisibleLength(handle);
|
||||||
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
|
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
|
||||||
int area = MwGetInteger(handle, MwNareaShown);
|
int area = MwGetInteger(handle, MwNareaShown);
|
||||||
|
if(area > MwGetInteger(handle, MwNmaxValue)) area = MwGetInteger(handle, MwNmaxValue);
|
||||||
|
|
||||||
return max * (double)area / len;
|
return max * (double)area / len;
|
||||||
}
|
}
|
||||||
@@ -55,6 +56,7 @@ static void add_value(MwWidget handle, int mul) {
|
|||||||
if(val > max) val = max;
|
if(val > max) val = max;
|
||||||
|
|
||||||
MwSetInteger(handle, MwNvalue, val);
|
MwSetInteger(handle, MwNvalue, val);
|
||||||
|
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw(MwWidget handle) {
|
static void draw(MwWidget handle) {
|
||||||
@@ -151,6 +153,7 @@ static void mouse_move(MwWidget handle) {
|
|||||||
if(len < 0) len = 0;
|
if(len < 0) len = 0;
|
||||||
if(len > 1) len = 1;
|
if(len > 1) len = 1;
|
||||||
MwSetInteger(handle, MwNvalue, (int)((max - min) * len - min));
|
MwSetInteger(handle, MwNvalue, (int)((max - min) * len - min));
|
||||||
|
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
|
||||||
|
|
||||||
MwForceRender(handle);
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,88 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
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) {
|
static int create(MwWidget handle) {
|
||||||
|
viewport_t* vp = malloc(sizeof(*vp));
|
||||||
|
memset(vp, 0, sizeof(*vp));
|
||||||
|
|
||||||
|
handle->internal = vp;
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
||||||
|
resize(handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,23 +100,47 @@ static void draw(MwWidget handle) {
|
|||||||
MwLLFreeColor(base);
|
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 = {
|
MwClassRec MwViewportClassRec = {
|
||||||
create, /* create */
|
create, /* create */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
draw, /* draw */
|
draw, /* draw */
|
||||||
NULL, /* click */
|
NULL, /* click */
|
||||||
NULL, /* parent_resize */
|
NULL, /* parent_resize */
|
||||||
NULL, /* prop_change */
|
prop_change, /* prop_change */
|
||||||
NULL, /* mouse_move */
|
NULL, /* mouse_move */
|
||||||
NULL, /* mouse_up */
|
NULL, /* mouse_up */
|
||||||
NULL, /* mouse_down */
|
NULL, /* mouse_down */
|
||||||
NULL, /* key */
|
NULL, /* key */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL};
|
NULL};
|
||||||
MwClass MwViewportClass = &MwViewportClassRec;
|
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);
|
||||||
|
}
|
||||||
|
|||||||