Difference between revisions of "Control created using the GUI Package"

From wiki.visual-prolog.com

m (Categorized)
(category)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
In this tutorial, we will show you how to create a new control in the GUI package of Visual Prolog step by step. First we will create a simple control, which will have some drawing in it. And then we will create a control as a container control, which will have a button and a drawing inside.
In this tutorial, we will show you how to create a new control in the GUI package of Visual Prolog step by step. First we will create a simple control, which will have some drawing in it. And then we will create a control as a container control, which will have a button and a drawing inside.


'''Download: ''Source files''''' of the example project used in this tutorial.
'''Download''' source files of the example project used in this tutorial:
 
* Visual Prolog 7.4 and 7.3 install examples in the IDE:
*:'''Help -> Install Examples...'''
* [http://download.pdc.dk/vip/72/tutorial_examples/newCustomControl.zip Visual Prolog 7.2 version].
* [http://download.pdc.dk/vip/71/examples/tutorial_examples/newCustomControl.zip Visual Prolog 7.1 version].


==New Control==
==New Control==
Line 25: Line 30:
clauses
clauses
     onPaint(_, Rectangle, GdiObject) :-
     onPaint(_, Rectangle, GdiObject) :-
         GdiObject:drawTextInRect(Rectangle,"Hello",
         GdiObject:drawTextInRect(Rectangle,"Hello", [vpiDomains::dtext_Center]).</vip>
          [vpiDomains::dtext_Center]).</vip>


Finally you can add the control to the form '' testForm''. You can recall how to add a control here.
Finally you can add the control to the form '' testForm''. You can recall how to add a control here.
Line 46: Line 50:
clauses
clauses
     onPushButton(Source) = button::defaultAction() :-
     onPushButton(Source) = button::defaultAction() :-
         stdIO::write("Button ",Source:getText(),
         stdIO::write("Button ",Source:getText(), " has been clicked\n").</vip>
            " has been clicked\n").</vip>


The second control is ready and we can add it to the form ''testForm''. You can recall, how to add a control here.
The second control is ready and we can add it to the form ''testForm''. You can recall, how to add a control here.
Line 53: Line 56:
==References==
==References==


[[Category:Tutorials]]
[[Category:Controls]]
[[Category:Controls]]

Latest revision as of 10:44, 4 March 2016

In this tutorial, we will show you how to create a new control in the GUI package of Visual Prolog step by step. First we will create a simple control, which will have some drawing in it. And then we will create a control as a container control, which will have a button and a drawing inside.

Download source files of the example project used in this tutorial:

New Control

Let us create a new project with the name newCustomControl. We also create a new form testForm and we will enter invocation of this form on FileNew. You can see more details about how to add a form here.

We need to create a new control. We can use the following steps:

  • Select a package in the project tree, where a new control will be created.
  • Run command File|New and choose Control as item, which will be created.
  • Type some name for the control. In our case the name is firstCustomControl
  • Click Create button, you will see attributes of new control. It is worth to keep them unchanged for the first time.

IDE will generate default code.

Now we can do some drawing in it. Please select in the project tree firstCustomControl.ctl, run command View|Code Expert and add onPaint event responder. IDE will generate default code, so we can insert some drawing in it. For example, the code can be:

predicates
    onPaint : drawWindow::paintResponder.
clauses
    onPaint(_, Rectangle, GdiObject) :-
        GdiObject:drawTextInRect(Rectangle,"Hello", [vpiDomains::dtext_Center]).

Finally you can add the control to the form testForm. You can recall how to add a control here.

New Compound Control

Let us create a new control secondCustomControl using File|New command. In IDE Dialog Editor we can add a button inside the control. Thus the new control becomes a compound control. Actually we can add any other control inside the new control.

We will also add onPaint responder to add some drawing and add onPushButton responder to add some handing of the button click. For example, the code can be:

predicates
    onPaint : drawWindow::paintResponder.
clauses
    onPaint(_, Rectangle, GdiObject) :-
        GdiObject:drawTextInRect(Rectangle,"Hello2",
           [vpiDomains::dtext_Center]).
predicates
    onPushButton : button::clickResponder.
clauses
    onPushButton(Source) = button::defaultAction() :-
        stdIO::write("Button ",Source:getText(), " has been clicked\n").

The second control is ready and we can add it to the form testForm. You can recall, how to add a control here.

References