pictDraw problem and question

Discussions related to Visual Prolog
daveplummermd
VIP Member
Posts: 56
Joined: 18 Jul 2006 17:18

pictDraw problem and question

Unread post by daveplummermd » 29 Mar 2020 12:58

Hello
I am trying to understand and eliminate an unexpected behavior with the pictDraw predicate.

I have a custom control that is used in standard dialogue. The control has this code:

Code: Select all

  onPaint(_Source, _, Gdiobject) :-         vpi::pictGetSize(pictPlus, XWidth, YHeight, _ImageSize),         This:getClientRect() = rct(L, T, R, B),         Gdiobject:pictDraw(pictPlus, rct(0, 0, R - L, B - T), rct(0, 0, XWidth, YHeight), rop_srcCopy),         !.
This code runs as expected, displaying the pick ONLY when in debug mode.
It works every time while debugging, but never displays the control when running the exe.

Any ideas?
Thnaks in advance.
Dave
Dave Plummer

User avatar
Thomas Linder Puls
VIP Member
Posts: 1174
Joined: 28 Feb 2000 0:01

Re: pictDraw problem and question

Unread post by Thomas Linder Puls » 1 Apr 2020 9:25

I have not been able to reproduce the problem.

Is the control painted if you minimize and restore the application (that will trigger a re-paint)?

You could try to post an invalidate to the control that will also trigger a redraw after "everything has settled".

Code: Select all

clauses     new() :-         pictPlus := createPict(),         userControlSupport::new(),         generatedInitialize(),         postAction(invalidate). % trigger paint after everything is settled
This shouldn't be necessary, but it could indicate that your control is painted in some bad moment.
Regards Thomas Linder Puls
PDC

Erkki Laitila
Posts: 7
Joined: 18 Oct 2013 10:46

Re: pictDraw problem and question

Unread post by Erkki Laitila » 7 May 2020 6:17

Hi,
I perhaps the same problem in showing user defined controls in general.
How can I send to the "MyControl" a signal so that it will paint itself.
Thomas's advice: "postAction(invalidate)" is not necessary.

In my software I can easily create userControlSupport - controls and they exist in my application, but I cannot get any contact for them, for example, for double checking.

I created a simple test to AboutDialog, and earlier for forms.

Is there a communication gap between Predefined UI and self created controls? … or some trick that I don't know?
KuvaruutuKaappausVisualProlog_DiscussionGroup.jpg
MyControl
KuvaruutuKaappausVisualProlog_DiscussionGroup.jpg (112.65 KiB) Viewed 4004 times
Systems thinker, PhD

User avatar
Thomas Linder Puls
VIP Member
Posts: 1174
Joined: 28 Feb 2000 0:01

Re: pictDraw problem and question

Unread post by Thomas Linder Puls » 7 May 2020 9:06

It seems you are having a difficulty with implementing a workaround, and now you want to solve that problem, rather than the real problem.

It was never my intension that the code should invalidate here and there. It was more to try pinpointing the problem.

So why don't we focus on the real problem again. Do you have or can you create a little example that illustrates the problem you have? Because as mentioned I could not reproduce the problem (could be because I don't really understand it).

From the image it seems that you have a working control which is added "statically".

Does the first button add additional controls? How do you do that? Especially, do you also show the added control?

Controls that are added to a dialog, before the dialog is shown will automatically be shown, when the dialog is shown. That will not happen with controls that are added after the dialog has been shown, such controls must "manually" be shown after they have been added.
Regards Thomas Linder Puls
PDC

Erkki Laitila
Posts: 7
Joined: 18 Oct 2013 10:46

Re: pictDraw problem and question

Unread post by Erkki Laitila » 7 May 2020 10:39

Good.
I will send a demo system here, or should I share the demo project somehow?

Obs. In the Sudoku - example there is SudokuDialog and in it SudokuControl, which creates NineSetControl "nineSetControl::new(This)"

There something wrong in my trials compared with Sudoku.

Ok. Now I will make a short demo project for test.
Systems thinker, PhD

Erkki Laitila
Posts: 7
Joined: 18 Oct 2013 10:46

Re: pictDraw problem and question

Unread post by Erkki Laitila » 7 May 2020 12:00

Hi,
this my test for the problem:


http://metayliopisto.fi/wp-content/uplo ... forPDC.zip
b.r.
Systems thinker, PhD

Erkki Laitila
Posts: 7
Joined: 18 Oct 2013 10:46

Re: pictDraw problem and question

Unread post by Erkki Laitila » 8 May 2020 13:05

I found that true:
"Controls that are added to a dialog, before the dialog is shown will automatically be shown, when the dialog is shown."
Setting control creation before generatedInitialize of the container, works:
dialog::new(Parent),
successfulInitializationPlace(This),
generatedInitialize(),

I have a simple question for the dynamic controls for my coming animation work:
"That will not happen with controls that are added after the dialog has been shown, such controls must "manually" be shown after they have been added."

How should "manual showing" be programmed, when it is different from the static code?

Actually the dynamic control (myControl) doesn't get any Show- or Paint-request.

Is this a question about activating some Listeners or sending some message to the dynamic control?
Systems thinker, PhD

User avatar
Thomas Linder Puls
VIP Member
Posts: 1174
Joined: 28 Feb 2000 0:01

Re: pictDraw problem and question

Unread post by Thomas Linder Puls » 10 May 2020 21:56

To show a control you just call show:

Code: Select all

clauses     onAddControl1Click(_Source) = button::defaultAction :-         X = 5 + math::random(100),         Y = 10 + math::random(100),         Pos = pnt(X, Y),         Ticks = time::getTickCount(),         Info = string::format("% ", Ticks),         MyControl = mycontrol::new(This, Info, Pos),         MyControl:setSize(32, 32),         MyControl:setPosition(Pos),         MyControl:show(),         assert(newControl(MyControl, Ticks, Pos)),         stdio::write("\n Control added: ", MyControl:getText(), " ", Info, " ", Pos),         succeed.
Another thing is that colors should be the ones from vpiDomains. color_<color> not color::<color>.

Code: Select all

predicates     onPaint : window::paintResponder. clauses     onPaint(_Source, _Rectangle, GDI) :-         getSize(W, H),         GDI:setBrush(brush(ps_dot, color_blue)),         GDI:drawRect(rct(1, 1, W - 1, H - 1)).
Regards Thomas Linder Puls
PDC

Erkki Laitila
Posts: 7
Joined: 18 Oct 2013 10:46

Re: pictDraw problem and question

Unread post by Erkki Laitila » 11 May 2020 11:54

Oh, thanks.
It was too simple for me :) I am sorry to bother you for that.
The control needs the show - command to become visible the first time (as you wrote).

However, the setPosition command directs the control into a different Place from coordinates of mouse and other draw commands.
Is it a question about dialog base units or LP to DP coordinates or nesting of many controls inside a form?

I found that Y position of a Mycontrol in the upper customcontrol is 2 times bigger than Y coordinate of the mouse in the mouse move message.

MyControl = mycontrol::new(This, Info, Pos),
MyControl:setSize(32, 32),
MyControl:setPosition(Pos),
MyControl:show().

predicates
onMouseMove : window::mouseMoveListener.
clauses
onMouseMove(_Source, Pnt, _ShiftControlAlt, _Buttons) :-
stdio::write(Pnt),
% Pnt is different scale from MyControl's Pos

There must be a explanation for the difference, how to calculate the difference?

-----------
I am sorry to ask so simple questions. I have had many years break and forgotten many principles of the UI. My project is still really interesting.
Systems thinker, PhD

User avatar
Thomas Linder Puls
VIP Member
Posts: 1174
Joined: 28 Feb 2000 0:01

Re: pictDraw problem and question

Unread post by Thomas Linder Puls » 11 May 2020 12:49

In dialogs and forms there are two measurement systems (coordinate systems), pixels and dialog base units.

I think you understand pixels without further explanation.

Dialog base units is a "logical" measurement that depends on the font of the dialog (i.e. the font size at the creation/show time). So if you increase the font size the entire dialog and all controls will become larger.

Predicates on window all works in pixels, so window::getOuterRect returns a rct containing pixels

Code: Select all

predicates     getOuterRect : () -> vpiDomains::rct OuterRectangle.     % @short Returns the outer rectangle of the current window.     % @exception gui_exception::noWindow_exception     % @end
On the other hand predicates on control, dialog and form work in "units":

Code: Select all

predicates     getRect : () -> rct UnitCoordinates.     % @short Returns the dialog layout as a rectangle measured in units.     % @end
Notice that a control (etc) is also a window so it has both the mentioned predicates.

The "unit" depends on the font of the relevant topLevelContainerWindow (i.e. dialog/form) and that interface contains predicates for transforming between the coordinate systems:

Code: Select all

predicates     rectPixel2Unit : (vpiDomains::rct Pixels) -> vpiDomains::rct Units.     % @short Converts the rectangle coordinates measured in pixels     % #Pixels to the rectangle coordinates measured in logical units #Units     % used in the current dialog.     % @detail This predicate can only be used when the dialog is already shown.     % @exception gui_exception::noWindow_exception     % @end   predicates     rectUnit2Pixel : (vpiDomains::rct Units) -> vpiDomains::rct Pixels.     % @short Converts the rectangle coordinates measured in logical units #Units     % (used in the current dialog) to the rectangle coordinates measured in pixels #Pixels.     % @detail This predicate can only be used when the dialog is already shown.     % @exception gui_exception::noWindow_exception     % @end   predicates     pntPixel2Unit : (vpiDomains::pnt Pixels) -> vpiDomains::pnt Units.     % @short Converts the point coordinates measured in pixels     % #Pixels to the point coordinates measured in logical units #Units     % used in the current dialog.     % @detail This predicate can only be used when the dialog is already shown.     % @exception gui_exception::noWindow_exception     % @end   predicates     pntUnit2Pixel : (vpiDomains::pnt Units) -> vpiDomains::pnt Pixels.     % @short Converts the point coordinates measured in logical units #Units     % (used in the current dialog) to the point coordinates measured in pixels #Pixels.     % @detail This predicate can only be used when the dialog is already shown.     % @exception gui_exception::noWindow_exception     % @end
Regards Thomas Linder Puls
PDC

Erkki Laitila
Posts: 7
Joined: 18 Oct 2013 10:46

Re: pictDraw problem and question

Unread post by Erkki Laitila » 12 May 2020 6:02

Thank you, Thomas

This explanation helps me much. I succeeded to make coordinates working.
Systems thinker, PhD

Post Reply