Commit b2e509d48f6aad1ed3a3f03d9a1a70aa8fba5d1b

[pt_BR] Translated more of the Morphic chapter

Commit diff

PortugueseBook/Morphic/Morphic.tex

 
3333%Then we need a cookbook of how to do simple things in Morphic.
3434%The observer pattern and its implementation with changed: and update: messages could go here. Or in ``Idiomatic design patterns'' later.}
3535
36\indmain{Morphic} is the name given to \sq's graphical interface.
37Morphic is written in \st, so it is fully portable between operating systems; as a consequence, \sq looks exactly the same on Unix, MacOS and Windows.
38What distinguishes Morphic from most other user interface toolkits is that it does not have separate modes for ``composing'' and ``running'' the interface: all the graphical elements can be assembled and disassembled by the user, at any time.\footnote{We thank Hilaire Fernandes for permission to base this chapter on his original article in French.}
36\indmain{Morphic} é o nome dado à interface gráfica do \sq.
37O Morphic é escrito em \st, e, sendo assim, é totalmente portável entre os sistemas operacionais onde o \sq roda; como conseqüência, o \sq tem a mesma aparência no Unix, Mac e Windows.
38O que distingue o Morphic da maioria das outras bibliotecas de interface é que ele não possui modelos separados para ``composição'' e ``execução'': todos os elementos gráficos pode ser montados e desmontados pelo usuário, a qualquer momento.\footnote{Agradecemo a Hilaire Fernandes pela permissão de basear esse capítulo em seu original em francês}.
3939
40\ab{After the first printing, I took an editing pass, correcting some errors and grammatical infelicities.}
41
42\on{I have commented out the LabelstickerMorph and PyramidMorph examples, as they do not really add much over the other examples we have already. The source code is now available in the example subdirectory, in case someone would like to try and use them after all.}
40\on{Comentei os exemplos de LabelstickerMorph e PyramidMorph examples, já que eles não adicionam muito aos exemplos que temos. O código fonte está no sub-diretório de exemplo caso alguém queria usá-los para outra coisa.}
4341
4442%=================================================================
45\section{The history of Morphic}
43\section{A história do Morphic}
44
45O Morphic foi desenvolvido por John Maloney e Randy Smith para a linguagem de programação \ind{Self}, começando por volta de 1993.
46Maloney mais tarde escreveu uma versão do Morphic para \sq, mas as idéias básicas da versão em Self ainda estão vivas e saudáveis no Morphic do \sq: \emph{transparência} e \emph{imediatismo}.
4647
47Morphic was developed by John Maloney and Randy Smith for the \ind{Self} programming language, staring around 1993.
48Maloney later wrote a new version of Morphic for \sq, but the basic ideas behind the Self version are still alive and well in \sq Morphic: \emph{directness} and \emph{liveness}.
49Directness means that the shapes on the screen are objects that can be examined or changed directly, that is, by pointing at them using the mouse.
50Liveness means that the user interface is always able to respond to user actions: information on the screen is continuously updated as the world that it describes changes.
51A simple example of this is that you can detach a menu item and keep it as a button.
48Transparência significa que as formas na tela são objetos que podem ser examinados ou alterados diretamente, isto é, operando sobre os mesmos usando o \foreign{mouse}.
49Imediatismo significa que a interface é sempre capaz de responder a ações do usuário: a informação na tela é continuamente atualizada à medida que o mundo que ela descreve muda.
50Um exemplo simples disso é que você pode destacar um item de um menu e mantê-lo como um botão.
5251
53\dothis{Bring up the world menu. Blue-click once on the world menu to bring up its morphic halo, then blue-click again on the menu item you want to detach to bring up its halo. Now drag that item elsewhere on the screen by grabbing the black handle \grabHandle, as shown in \figref{detachingMenu}.}
52\dothis{Abra o \foreign{menu} \foreign{World} e clique com o botão azul sobre o mesmo para acessar o seu halo. Depois, clique sobre um item de \foreign{menu} que você deseja destacar para exibir o halo do mesmo. Agora, arraste esse item para outra posição na tela usando o ícone \grabHandle, como mostrado na \figref{detachingMenu}.}
5453\index{Morphic!halo}
5554\index{blue button}
5655
5757 \ifluluelse
5858 {\centerline{\includegraphics[width=0.6\textwidth]{detachingMenu}}}
5959 {\centerline{\includegraphics[width=0.4\textwidth]{detachingMenu}}}
60 \caption{Detaching a morph, here the \menu{new morph} menu item, to make it an independent button.
60 \caption{Destacando um \foreign{morph}, aqui o \foreign{menu} \menu{new morph}, e transformando-o em um botão independente.
6161 \label{fig:detachingMenu}}
6262\end{figure}
6363
64All of the objects that you see on the screen when you run \sq are \emph{Morphs}, that is, they are instances of subclasses of class \ct{Morph}.
65\mbox{\ct{Morph}} itself is a large class with many methods; this makes it possible for subclasses to implement interesting behaviour with little code.
66You can create a morph to represent any object, although how good a representation you get depends on the object!
64Todos os objetos que você vê na tela quando roda o \sq são \emph{Morphs}, isto é, instâncias de subclasses da classe \ct{Morph}.
65\mbox{\ct{Morph}} é uma classe grande, com muitos métodos; com isso, suas subclasses podem implementar comportamento bastante interessante com relativamente pouco código. Você pode criar um \foreign{morph} para representar qualquer objeto, embora quão boa a representação vai depender do objeto em si!
6766
68\dothis{To create a morph to represent a string object, execute the following code in a workspace, one line at a time.}
67\dothis{Para criar um \foreign{morph} que representa um objeto \ct{String}, execute o seguinte código em um \foreign{workspace}, uma linha de cada vez.}
6968\begin{code}{}
7069s := 'Morph' asMorph openInWorld.
7170s openViewerForArgument
7271\end{code}
7372\cmindex{Morph}{openInWorld}
7473
75The first line creates a Morph to represent the string \ct{'Morph'}, and then opens it (that is, displays it) in the ``world'', which is the name that \sq gives to the screen.
76You should obtain a graphical element\,---\,a Morph\,---\,which you can manipulate by blue-clicking.
77The second line opens a ``viewer'' that shows you attributes of this Morph, such as its \ct{x} and \ct{y} coordinates on the screen. Clicking on one of the yellow exclamation marks sends a message to the Morph, which responds appropriately.
74A primeira linha criar um \foreign{morph} para representar o texto \ct{'Morph'}, e então o abre (isto é, exibe o mesmo) no ``mundo'', que é o nome que o \sq dá para a tela.
75Você obterá um elemento gráfico\,---\,um Morph\,---\,que você pode manipular com o botão azul.
76A segunda linha abre um visualizador que mostra atributos do seu \foreign{morph}, como suas coordenadas \ct{x} e \ct{y} na tela. Se você clicar em um dos pontos de exclamação amarelos, uma mensagem é enviada ao objeto, que responderá apropriadamente.
7877
79Of course, it is possible to define morphs that are more interesting graphical representations than the one that you have just seen.
80The method \mthind{Object}{asMorph} has a default implementation in class \ct{Object} class that just creates a StringMorph.
81So, for example, \ct{Color tan asMorph} returns a StringMorph labeled with the result of \clsind{Color} \ct{tan printString}.
82Let's change this so that we get a coloured rectangle instead.
78Obviamente, é possível definir objetos que são graficamente mais interessantes do que o que você acabou de ver. O método \mthind{Object}{asMorph} tem uma implementação padrão na classe \ct{Object} que cria uma StringMorph. Assim por exemplo, \ct{Color tan asMorph} retorna um StringMorph cujo título é \clsind{Color} \ct{printString}. Vamos mudar isso de modo que obtenhamos um retângulo colorido.
8379
84\dothis{Open a browser on the \ct{Color} class and add the following method to it:}
85\begin{method}{Getting a morph for an instance of \ct{Color}.}
80\dothis{Abra um navegador na classe \ct{Color} e adicione o seguinte método à mesma:}
81\begin{method}{Obtendo um \foreign{morph} para uma instância de \ct{Color}.}
8682Color>>>asMorph
8783 ^ Morph new color: self
8884\end{method}
8985\noindent
90Now execute \ct{Color orange asMorph} \mthind{Morph}{openInWorld} in a workspace. Instead of the string-like morph, you get an orange rectangle!
91
86Agora execute \ct{Color orange asMorph} \mthind{Morph}{openInWorld} em um \foreign{workspace}. Ao invés de um \foreign{morph} representando um texto, você verá um retângulo laranja!
9287
9388%=================================================================
94\section{Manipulating morphs}
89\section{Manipulando \foreign{morphs}}
90
91\foreign{Morphs} são objetos, e podemos manipulá-los como qualquer objeto em \st: enviando mensagens, mudando suas propriedades, riando novas subclasses de Morph e assim por diante.
9592
96Morphs are objects, so we can manipulate them like any other object in \st: by sending messages, we can change their properties, create new subclasses of Morph, and so on.
93Cada \foreign{morph}, mesmo aqueles que não abertos da tela no momento, tem uma posição e um tamanho.
94Por conveniência, todos os \foreign{morphs} ocupam uma região retangular na tela; se possuem uma forma irregular, sua posição e tamanho são as do menor retângulo capaz de rodeá-los; esse retângulo é conhecido como o retângulo limite do \foreign{morph}.
95O método \mthind{Morph}{position} retorna um ponto \ct{Point} que descreve a localização do canto superior esquerdo do \foreign{morph} (ou seja, o canto superior esquerdo de seu retângulo limite).
96A origem do sistemas de coordenadas é o canto superior esquerdo da tela, com a coordenada $y$ aumentando para baixo na tela, e a coordenada $x$ aumentando para a direita.
97O método \ct{extent} também retorna um ponto, mas esse ponto indica a largura e altura do \foreign{morph} e não a sua localização.
9798
9899Every morph, even if it is not currently open on the screen, has a position and a size.
99100For convenience, all morphs are considered to occupy a rectangular region of the screen; if they are irregularly shaped, their position and size are those of the smallest rectangular ``box'' that surrounds them, which is known as the morph's bounding box, or just its ``bounds''.
102102The origin of the coordinate system is the screen's upper left corner, with $y$ coordinates increasing \emph{down} the screen and $x$ coordinates increasing to the right.
103103The \ct{extent} method also returns a point, but this point specifies the width and height of the morph rather than a location.
104104
105\dothis{Type the following code into a workspace and \menu{do it}:}
105\dothis{Digite o seguinte código em um \foreign{workspace} e execute-o:}
106106\begin{code}{}
107107joe := Morph new color: Color blue.
108108joe openInWorld.
110110bill openInWorld.
111111\end{code}
112112\noindent
113Then type \ct{joe position} and \menu{print it}.
114To move joe, execute \ct{joe position: (joe position + (10@3))} repeatedly.
113Agora digite \ct{joe position} e imprima iso. Para mover \ct{joe}, execute repetidamente \ct{joe position: (joe position + (10@3))}.
115114
116It is possible to do a similar thing with size.
117\ct{joe} \mthind{Morph}{extent} answers joe's size; to have joe grow, execute \ct{joe extent: (joe extent * 1.1)}.
118To change the color of a morph, send it the \mthind{Morph}{color:} message with the desired \ct{Color} object as argument, for instance, \ct{joe color: Color orange}.
119To add transparency, try \ct{joe color: (Color orange alpha: 0.5)}.
115É possível fazer algo similar com o tamanho:
116\ct{joe} \mthind{Morph}{extent} responde o tamanho do objeto; para aumentá-lo, use \ct{joe extent: (joe extent * 1.1)}.
117Para mudar a cor de um \foreign{morph}, envie \mthind{Morph}{color:} com a cor desejada como um argumento. Por exemplo, \ct{joe color: Color orange}.
118Por fim, para adicionar transparência, use algo como \ct{joe color: (Color orange alpha: 0.5)}.
120119
121\dothis{To make bill follow joe, you can repeatedly execute this code:}
120\dothis{Para fazer com que \ct{bill} acompanhe \ct{joe}, execute este código repetidamente:}
122121\begin{code}{}
123122bill position: (joe position + (100@0))
124123\end{code}
125124\noindent
126If you move joe using the mouse and then execute this code, bill will move so that it is 100 pixels to the right of joe.
127\ab{It would seem that this would be a good place to introduce the \ct{step} method}.
125Se você mover \ct{joe} usando o \foreign{mouse} e então executar o código, verá que \ct{bill} se move para uma posição 100 pixels à direta e \ct{joe}.
128126
129127%=================================================================
130128\section{Composing morphs}
toggle raw diff