如何在创建的对话框中使用DLGCreateImagePopup选择打开的图像 [英] how to select a opened image with DLGCreateImagePopup in created dialog

查看:147
本文介绍了如何在创建的对话框中使用DLGCreateImagePopup选择打开的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用DLGCreateImagePopup创建一个对话框来选择一个打开的图像.但是,选择图像后,我无法对该图像做任何事情.如何获取所选图像的图像ID或名称?

I creat a dialog with DLGCreateImagePopup to select a opened image. But after I select the image, I cannot do anything for that image. How to get the image ID or name of the selected image?

推荐答案

如果您想将其作为一个摆姿势对话框(即,单击确定"按钮后获取图像),可以按照以下步骤进行操作:

If you want to do it as a posed dialog (i.e. get the image after clicking the OK button), you could do it as follows:

Class CMyDLG : UIframe
{
       TagGroup DLG,DLGItems,imgPop        
       object Init(object self)
       {
              DLG = DLGCreateDialog("Test",DLGItems)
              imgPop = DLGCreateImagePopup()
              DLGItems.DLGAddElement( imgPop )       
              return self.super.init(DLG)
       }

       image GetSelectedImage( object self )
       {
              string selectedImageLabel
              imgPop.DLGGetValue(selectedImageLabel)
              Result("\n" + selectedImageLabel)
              // From the string, get the label
              string label = selectedImageLabel.left( selectedImageLabel.find(":") )
              Result("\n" + label)
              // From label, return image
              return FindImageByLabel(label)
       }
}

// main
{
       object dlg = Alloc(CMyDLG).Init()
       dlg.Pose()
       image selected := dlg.GetSelectedImage()
       if ( selected.ImageIsValid() )
              selected.SetName( "Selected" + random())
       else Throw( "Error, nothing selected." )
}

如果要在对话框仍显示(无模式对话框)的同时对图像做一些事情,则必须将OnChanged类型的方法附加到该项上,如下所示:

If you want to do something with the image while the dialog is still displayed (modeless dialog) you'd have to attach a OnChanged-type method to the item as in:

Class CMyDLG : UIframe
{
       TagGroup DLG,DLGItems,imgPop        
        void FieldChanged(object self, taggroup tg)
        {
              string selectedImageLabel
               tg.DLGGetValue(selectedImageLabel)
              Result("\n" + selectedImageLabel)
              // From the string, get the label
              string label = selectedImageLabel.left( selectedImageLabel.find(":") )
              Result("\n" + label)
              // From label, return image
              image selected := FindImageByLabel(label)
              if ( selected.ImageIsValid() )
                  selected.SetName( "Selected" + random())
              else Throw( "Error, nothing selected." )
       }

        object Init(object self)
       {
              DLG = DLGCreateDialog("Test",DLGItems)
              imgPop = DLGCreateImagePopup().DLGChangedMethod("FieldChanged")
              DLGItems.DLGAddElement( imgPop )       
              return self.super.init(DLG)
       }

}

// main
{
    Alloc(CMyDLG).Init().display("myDialog")   
}


请注意,当我在最新的GMS 3上测试此脚本时,我注意到了一个 bug .仅当第二次访问下拉列表时,才会发生更改方法(以及实际选择).


Note, that when I've tested this script on the latest GMS 3, I've noticed a bug. The Changed-method (and hence the actual selection) seems to happen only when the drop-down is accessed a second time.

这篇关于如何在创建的对话框中使用DLGCreateImagePopup选择打开的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆