简体   繁体   English

图形用户界面窗口的代码

[英]Code for A Graphical User Interface window

How would someone go about coding a 'window'? 有人将如何编码“窗口”? I'm starting to make a GUI, and I want to learn how to code one. 我开始制作GUI,并且我想学习如何编写一个GUI。 One that can be skinnable, and one that actually loops and creates itself at runtime. 一种是可以换肤的,一种实际上是在运行时循环并创建自己的。 I understand that this might be a bit vague, so I'll add details. 我知道这可能有点含糊,所以我将添加详细信息。

One that actually 'creates' itself. 一个真正“创造”自己的人。 Most GUI tutorials I've looked on depends on an 'image' that just gets added on the screen. 我看过的大多数GUI教程都依赖于刚刚添加到屏幕上的“图像”。 I want to be able to use skins in my windows. 我希望能够在我的窗户上使用皮肤。 One where my 'skin' is just a collection of 'borders'. 我的“皮肤”只是一个“边界”的集合。 Then when I insert window.create(50,50) where 50,50 is my height, width, It would just create that window, following the skin. 然后,当我插入window.create(50,50) ,其中50,50是我的高度,宽度时,它将沿着皮肤创建该窗口。

I understand that it probably follows just like when a language draws a rectangle, it just follows a different set of rules (maybe?). 我知道它可能遵循的方式就像一种语言绘制一个矩形一样,它遵循的是一组不同的规则(也许吗?)。 However, for all my Google-fu skills I cannot find a tutorial that teaches me this. 但是,对于我所有的Google-fu技能,我都找不到可以教我这一点的教程。

Please Help. 请帮忙。 I didn't include the language I used as you can see, because I believe I just need to know how to create one. 您没有看到我所用的语言,因为我相信我只需要知道如何创建一种语言即可。 Anyway though, I am using Actionscript 3. A tutorial would be just fine, or even A SINGLE CLASS THAT HAS THIS FUNCTIONALITY, I'll just study the code. 无论如何,我正在使用Actionscript3。一个教程就可以了,甚至一个具有这种功能的单一类,我也只是研究代码。 Or if you know one, maybe a whole book about GUI and programming it :D 或者,如果您知道一本书,也许是一本关于GUI并对其进行编程的整本书:D

Pure As3.0 GUI coding is quite troublesome. 纯As3.0 GUI编码非常麻烦。 I try to Googling, but not come out well. 我尝试使用Google搜索,但效果不佳。 anyway for my case, i generate using a SWC, and Class Mapping and Customizing. 无论如何,我使用SWC以及类映射和自定义生成。 but i'm not sure best way. 但我不确定最好的方法。 in other way i use a bit101 library. 以其他方式,我使用bit101库。 this is gives me want Window , Charts , Componets easily of high abstraction. 这是给我想要高度抽象的WindowChartsComponets的容易。 see the below image. 见下图。

在此处输入图片说明

It can be pretty hard and complicated to do, or very easy, it just depends on how flexible your solution should be. 这可能非常困难,复杂,或者非常容易,这仅取决于解决方案的灵活性。 You need firstly to design a structure of your program and approach to the problem. 您首先需要设计程序的结构和解决问题的方法。

I like to go from the image of how it should look like from API point of view. 我喜欢从API的角度看它的外观。 I think I would create a GUI element like this: 我想我会创建这样的GUI元素:

var wholeGui:MyGUI = new MyGUI();
var window:IGuiElement = new GuiWindow(dataObject, skinObject);
wholeGui.addElement(window);

So what would you need? 那你需要什么?

1) Object that would manage all GUI elements. 1)将管理所有GUI元素的对象。 Why? 为什么? Simply because your GUI elements shouldn't be destroyed by themselves if user will click "X" on your little window. 仅仅是因为如果用户在您的小窗口上单击“ X”,则不应自行破坏您的GUI元素。 The wholeGui object would manage them and listen for any events including those that would destroy them. wholeGui对象将管理它们并侦听任何事件,包括会破坏它们的事件。 You may consider creating custom events for interaction between the wholeGui object and your window object if this interaction is going to be complicated. 如果这种交互将变得很复杂,则可以考虑创建自定义事件,以便在WholeGui对象和window对象之间进行交互。

2) Interface for your GUI objects. 2)GUI对象的接口。 Some problem here is that AS3 actually doesn't have interface for Sprite, and you would like to interact with it like with extended Sprite. 这里的一个问题是AS3实际上没有Sprite的接口,您希望像扩展Sprite一样与之交互。 The workaround here is to have in this interface a declaration like this: 解决方法是在此接口中具有如下声明:

function asSprite():Sprite;

And your implementation in GuiWindow would look like this: 您在GuiWindow中的实现将如下所示:

public function asSprite():Sprite {
    return this;
}

And your GuiWindow class should extend Sprite of course. 当然,您的GuiWindow类应该扩展Sprite。 Then you would have access to it's Sprite properties and methods by writing for example: window.asSprite.startDrag(); 然后,您可以通过编写以下代码来访问其Sprite属性和方法:window.asSprite.startDrag();

This interface should give you abilities that you need to operate on your GUI element. 该界面应为您提供在GUI元素上进行操作所需的功能。

3) Class for your GUI element, in this example GuiWindow. 3)您的GUI元素的类,在此示例GuiWindow中。

4) Class for your data that would be injected into your element. 4)将要插入到元素中的数据的类。 If you would load data dynamically, and from some location, you would need to deal with the situation when no data can be provided - but that logic would be inside your window. 如果要从某个位置动态加载数据,则需要处理无法提供数据的情况-但是该逻辑将在窗口内。

5) Class for your skin - so you would be able to dynamically create a skin object and use it to create your window in a way you want. 5)皮肤的类-这样您就可以动态创建皮肤对象,并使用它以所需的方式创建窗口。

That's just few thoughts to consider. 那只是考虑的几个想法。

PS. PS。 It may be good idea to fill GuiWindow object with data AFTER creating it, and not in constructor, as you would be able to visualize loading process then. 最好在创建GuiWindow对象后用数据填充它,而不是在构造函数中填充,因为这样您就可以看到加载过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM