如何在openlaszlo中针对不同的纵横比以编程方式确定xscale和yscale?

如何在openlaszlo中针对不同的纵横比以编程方式确定xscale和yscale?,openlaszlo,lzx,Openlaszlo,Lzx,我在拉伸视图时遇到了一些问题,所以最后我使用xscale和yscale来缩放视图。这个问题在我的机器上解决了,它有一个解决方案 canvas.width -1280 canvas.height - 1023 在全屏模式下 但是当我在我朋友的机器上检查时 canvas.width -1280 canvas.height - 697 在全屏模式下,部分屏幕被切断 我给出的当前比例因子是xscale=1.33和yscale=1.33。应更改yscale以适应第二个系统。如何以编程方式确定此系数。下

我在拉伸视图时遇到了一些问题,所以最后我使用xscale和yscale来缩放视图。这个问题在我的机器上解决了,它有一个解决方案

canvas.width -1280
canvas.height - 1023
在全屏模式下

但是当我在我朋友的机器上检查时

canvas.width -1280
canvas.height - 697
在全屏模式下,部分屏幕被切断


我给出的当前比例因子是xscale=1.33和yscale=1.33。应更改yscale以适应第二个系统。如何以编程方式确定此系数。

下面是一个示例代码,演示如何根据比率缩放视图。比率由unscaledwidth和unscaledheight属性定义。没有最小宽度或最小高度的实现,但如果需要,可以很容易地添加

这种方法的缺点是所有的资源都会被扩展。在SWF运行时,默认组件的资源是基于向量的,在DHTML运行时,它们被转换为PNG文件,并且在缩放时看起来不会很清晰。我通常不会扩展现有的OpenLaszlo组件,但这是您的决定:

<canvas width="100%" height="100%">
<!-- OpenLaszlo scaled view example by Raju Bitter -->

    <class name="scaledview">
        <attribute name="unscaledwidth" type="number" value="400"/>
        <attribute name="unscaledheight" type="number" value="300"/>
        <attribute name="wratio" type="number" value="${this.unscaledwidth/this.unscaledheight}"/>

        <handler name="oninit">
            this.setAttribute("width", this.unscaledwidth)
            this.setAttribute("height", this.unscaledheight)
            this._setSize();
        </handler>
        <handler name="onwidth" reference="canvas">
            this._setSize();
        </handler>
        <handler name="onheight" reference="canvas">
            this._setSize();
        </handler>
        <method name="_setSize">
            var scale = 1.0;
            if (canvas.width/canvas.height > this.wratio) {
                scale = canvas.height / this.unscaledheight;
                this.setAttribute("x", Math.round((canvas.width-this.width*scale) / 2));
                this.setAttribute("y", 0);
            } else {
                scale = canvas.width / this.unscaledwidth;
                this.setAttribute("x", 0);
                this.setAttribute("y", Math.round((canvas.height-this.height*scale) / 2));
            }
            this.setAttribute("xscale", scale);
            this.setAttribute("yscale", scale);
        </method>
    </class>

    <scaledview id="sv" bgcolor="red">
       <window width="200" height="100" title="Just a window!" align="center" valign="middle"/>
    </scaledview>

    <view>
        <simplelayout axis="y" />
        <text fontsize="12"
              text="${'canvas: ' + canvas.width + ' * ' + canvas.height + '  ratio=' + (canvas.width/canvas.height)}"/>
        <text fontsize="12"
              text="${'scaledview: ' + sv.width + ' * ' + sv.height + '  ratio=' + sv.wratio}" />
        <text fontsize="12"
              text="${'scaledview: xscale=' + sv.xscale + ' / yscale=' + sv.yscale}" />
    </view>

</canvas>

this.setAttribute(“宽度”,this.unscaledwidth)
this.setAttribute(“高度”,this.unscaledheight)
这个;
这个;
这个;
var标度=1.0;
if(canvas.width/canvas.height>this.wratio){
比例=canvas.height/this.unscaledheight;
this.setAttribute(“x”,数学圆((canvas.width this.width*scale)/2);
这个.setAttribute(“y”,0);
}否则{
比例=canvas.width/this.unscaledwidth;
这个.setAttribute(“x”,0);
this.setAttribute(“y”,数学圆((canvas.height this.height*scale)/2);
}
这个.setAttribute(“xscale”,scale);
这个.setAttribute(“yscale”,scale);
检查应用程序的屏幕截图,您可以看到根据定义的比率缩放的红色。窗口组件的大小将随着画布分辨率的增大或减小而增大或缩小


这是否意味着您希望根据画布分辨率的纵横比,将长方体缩放到最小宽度和高度,以及canvas.width或canvas.height?为什么要缩放,因为这会增加屏幕上项目的大小?是的,我想将框缩放到最小宽度和高度,使其根据不同的屏幕大小进行缩放。前面我曾给strength=true,并给width Debug一个类似的公式。write(“width”,canvas.width/canvas.height 1.33?this.width*this.unstretcheight/this.unstretchedth:canvas.height);。这将根据纵横比指定适当的宽度ratio@RajuBitter:但这在最新的5.0或4.9中不起作用,因为拉伸属性未应用于子视图。所以我必须使用xscale或yscale。@RajuBitter:为了支持不同的屏幕,我们采用了这种方法,将主视图分辨率保持为800*600。然后根据canvas.width缩放主视图。800*600是任何pc都绝对支持的最低分辨率。只能在SWF10和DHTML中使用OpenLaszlo 5.0进行测试。记住:并非所有浏览器都支持在DHTML运行时缩放视图!除非您想使用IE9,否则在DHTML运行时,扩展似乎工作得很好。但是你可以用Flash作为后备。