comp.lang.ada
 help / color / mirror / Atom feed
* How to get the mouse position with JEWL?
@ 2010-10-20  9:04 tolkamp
  2010-10-20 11:42 ` Manuel Collado
  2010-10-21 21:50 ` Manuel Collado
  0 siblings, 2 replies; 23+ messages in thread
From: tolkamp @ 2010-10-20  9:04 UTC (permalink / raw)


I use JEWL in several of my applications.
Now I try to get the mouse position within a JEWL canvas by using the
function "End_Point(Canavas)".
The resulting mouse position (x,y) is always zero. What is going wrong?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20  9:04 How to get the mouse position with JEWL? tolkamp
@ 2010-10-20 11:42 ` Manuel Collado
  2010-10-20 17:20   ` tolkamp
  2010-10-21 21:50 ` Manuel Collado
  1 sibling, 1 reply; 23+ messages in thread
From: Manuel Collado @ 2010-10-20 11:42 UTC (permalink / raw)


El 20/10/2010 11:04, tolkamp escribi�:
> I use JEWL in several of my applications.
> Now I try to get the mouse position within a JEWL canvas by using the
> function "End_Point(Canavas)".
> The resulting mouse position (x,y) is always zero. What is going wrong?

Please try:

  point := Start_Point( canvas );

It works for me.

-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 11:42 ` Manuel Collado
@ 2010-10-20 17:20   ` tolkamp
  2010-10-20 22:22     ` Manuel Collado
  0 siblings, 1 reply; 23+ messages in thread
From: tolkamp @ 2010-10-20 17:20 UTC (permalink / raw)


On 20 okt, 13:42, Manuel Collado <m.coll...@domain.invalid> wrote:
> El 20/10/2010 11:04, tolkamp escribió:
>
> > I use JEWL in several of my applications.
> > Now I try to get the mouse position within a JEWL canvas by using the
> > function "End_Point(Canavas)".
> > The resulting mouse position (x,y) is always zero. What is going wrong?
>
> Please try:
>
>   point := Start_Point( canvas );
>
> It works for me.
>
> --
> Manuel Collado -http://lml.ls.fi.upm.es/~mcollado

Also when I try:
 point := Start_Point( canvas );
the x and y position remains zero.

Here is the code:

task body Task_2Hz is
My_Frame  : Frame_Type;
My_Canvas : Canvas_Type;
My_Mouse_Position : Point_Type;
begin
    accept Start do
       My_Frame   := Frame (1200, 500, "", 0);
       My_Canvas  := Canvas (Frame, (850,10),      300, 300);
loop
       My_Mouse_Position := Start_Point(My_Canvas);
       Put("Mouse-x = "); Int_Io.Put(My_Mouse_Position.x); New_Line;
       Put("Mouse-y = "); Int_Io.Put(My_Mouse_Position.y); New_Line;
   delay 0.5;
end loop;
end Task_2Hz;



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 17:20   ` tolkamp
@ 2010-10-20 22:22     ` Manuel Collado
  2010-10-20 22:51       ` tmoran
  2010-10-22 13:55       ` tolkamp
  0 siblings, 2 replies; 23+ messages in thread
From: Manuel Collado @ 2010-10-20 22:22 UTC (permalink / raw)


El 20/10/2010 19:20, tolkamp escribi�:
> On 20 okt, 13:42, Manuel Collado<m.coll...@domain.invalid>  wrote:
>> El 20/10/2010 11:04, tolkamp escribi�:
>>
>>> I use JEWL in several of my applications.
>>> Now I try to get the mouse position within a JEWL canvas by using the
>>> function "End_Point(Canavas)".
>>> The resulting mouse position (x,y) is always zero. What is going wrong?
>>
>> Please try:
>>
>>    point := Start_Point( canvas );
>>
>> It works for me.
>>
>
> Also when I try:
>   point := Start_Point( canvas );
> the x and y position remains zero.
>
> Here is the code:
>
> task body Task_2Hz is
> My_Frame  : Frame_Type;
> My_Canvas : Canvas_Type;
> My_Mouse_Position : Point_Type;
> begin
>      accept Start do
>         My_Frame   := Frame (1200, 500, "", 0);
>         My_Canvas  := Canvas (Frame, (850,10),      300, 300);
> loop
>         My_Mouse_Position := Start_Point(My_Canvas);
>         Put("Mouse-x = "); Int_Io.Put(My_Mouse_Position.x); New_Line;
>         Put("Mouse-y = "); Int_Io.Put(My_Mouse_Position.y); New_Line;
>     delay 0.5;
> end loop;
> end Task_2Hz;

IIRC, you must wait for a mouse event before reading the coordinates. 
Here is a code fragment of a real program that uses a canvas. You may 
figure how to adapt it to your needs:

    function Get_Point return Point_Type is
       Here: Point_Type;
    begin
       loop
          case Next_Command is
             when Cmd_Mouse =>
                exit;
             when Cmd_Quit =>
                raise Program_Aborted;
             when others =>
                null;
          end case;
       end loop;
       Here := Start_Point( Main_Canvas );
       return Logical( Here );
    end Get_Point;

Hope it helps.
-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 22:22     ` Manuel Collado
@ 2010-10-20 22:51       ` tmoran
  2010-10-21  2:59         ` Jeffrey Carter
                           ` (3 more replies)
  2010-10-22 13:55       ` tolkamp
  1 sibling, 4 replies; 23+ messages in thread
From: tmoran @ 2010-10-20 22:51 UTC (permalink / raw)


This works for me for Windows
    type Points is record
      x,y : interfaces.c.int;
    end record;
    type bool is new interfaces.c.int;
    function GetCursorPos(point : access points) return bool;
    pragma import(stdcall,GetCursorPos, "GetCursorPos");
    current : aliased points;
    ...
      if getcursorpos(current'access) = 0 then
        -- current now has mouse position
      else -- Windows error



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 22:51       ` tmoran
@ 2010-10-21  2:59         ` Jeffrey Carter
  2010-10-21  4:08           ` tmoran
  2010-10-21  7:31         ` Dmitry A. Kazakov
                           ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: Jeffrey Carter @ 2010-10-21  2:59 UTC (permalink / raw)


On 10/20/2010 03:51 PM, tmoran@acm.org wrote:
> This works for me for Windows
>      type Points is record
>        x,y : interfaces.c.int;
>      end record;

I'd add

pragma Convention (C, Points);

just to be safe.

>      type bool is new interfaces.c.int;
>      function GetCursorPos(point : access points) return bool;

(Point : in Points)

should work just as well, and has the advantages that

>      pragma import(stdcall,GetCursorPos, "GetCursorPos");
>      current : aliased points;

you don't need "aliased"

>      ...
>        if getcursorpos(current'access) = 0 then

and you don't need 'access.

This works because of ARM B.3: "An Ada parameter of a record type T, of any 
mode, other than an in parameter of a type of convention C_Pass_By_Copy, is 
passed as a t* argument to a C function, where t is the C struct corresponding 
to the Ada type T."

It is a little confusing because an "in" parameter is modified.

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail
04



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21  2:59         ` Jeffrey Carter
@ 2010-10-21  4:08           ` tmoran
  0 siblings, 0 replies; 23+ messages in thread
From: tmoran @ 2010-10-21  4:08 UTC (permalink / raw)


> I'd add
>
> pragma Convention (C, Points);
>
> just to be safe.
  Yes, I should have specified the layout.

Personally I'd use a record representation clause that says exactly what I
need.  Saying to the Ada compiler "use the 'C' convention - and I hope you
are thinking of the same C compiler I am", always seems to me less certain
of getting the correct result.

> (Point : in Points)
>
> should work just as well, and has the advantages that
> you don't need "aliased"
>
> >      ...
> >        if getcursorpos(current'access) = 0 then
>
> and you don't need 'access.
>
> It is a little confusing because an "in" parameter is modified.
  I'm inclined to be straightforward unless there's some awfully good
reason for being devious.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 22:51       ` tmoran
  2010-10-21  2:59         ` Jeffrey Carter
@ 2010-10-21  7:31         ` Dmitry A. Kazakov
  2010-10-21 19:10           ` tmoran
  2010-10-21 15:23         ` tolkamp
  2010-10-21 20:34         ` tolkamp
  3 siblings, 1 reply; 23+ messages in thread
From: Dmitry A. Kazakov @ 2010-10-21  7:31 UTC (permalink / raw)


On Wed, 20 Oct 2010 22:51:00 +0000 (UTC), tmoran@acm.org wrote:

> This works for me for Windows
>     type Points is record
>       x,y : interfaces.c.int;
>     end record;
>     type bool is new interfaces.c.int;
>     function GetCursorPos(point : access points) return bool;
>     pragma import(stdcall,GetCursorPos, "GetCursorPos");
>     current : aliased points;
>     ...
>       if getcursorpos(current'access) = 0 then
>         -- current now has mouse position
>       else -- Windows error

Surely it is better to use it from win32ada than making own binding.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 22:51       ` tmoran
  2010-10-21  2:59         ` Jeffrey Carter
  2010-10-21  7:31         ` Dmitry A. Kazakov
@ 2010-10-21 15:23         ` tolkamp
  2010-10-21 16:47           ` Georg Bauhaus
  2010-10-21 20:34         ` tolkamp
  3 siblings, 1 reply; 23+ messages in thread
From: tolkamp @ 2010-10-21 15:23 UTC (permalink / raw)


On 21 okt, 00:51, tmo...@acm.org wrote:
> This works for me for Windows
>     type Points is record
>       x,y : interfaces.c.int;
>     end record;
>     type bool is new interfaces.c.int;
>     function GetCursorPos(point : access points) return bool;
>     pragma import(stdcall,GetCursorPos, "GetCursorPos");
>     current : aliased points;
>     ...
>       if getcursorpos(current'access) = 0 then
>         -- current now has mouse position
>       else -- Windows error

When I include "with interfaces.c.int" the compilation results in
error:
Interface.C.Init is not a predefined library unit.
How can I add this to the library?




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21 15:23         ` tolkamp
@ 2010-10-21 16:47           ` Georg Bauhaus
  2010-10-21 17:09             ` tolkamp
  0 siblings, 1 reply; 23+ messages in thread
From: Georg Bauhaus @ 2010-10-21 16:47 UTC (permalink / raw)


On 21.10.10 17:23, tolkamp wrote:
> On 21 okt, 00:51, tmo...@acm.org wrote:
>> This works for me for Windows
>>     type Points is record
>>       x,y : interfaces.c.int;
>>     end record;
>>     type bool is new interfaces.c.int;
>>     function GetCursorPos(point : access points) return bool;
>>     pragma import(stdcall,GetCursorPos, "GetCursorPos");
>>     current : aliased points;
>>     ...
>>       if getcursorpos(current'access) = 0 then
>>         -- current now has mouse position
>>       else -- Windows error
> 
> When I include "with interfaces.c.int" the compilation results in
> error:
> Interface.C.Init is not a predefined library unit.

"int" is the name of a type in package Interface.C.
"With" that.


Georg



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21 16:47           ` Georg Bauhaus
@ 2010-10-21 17:09             ` tolkamp
  2010-10-21 17:24               ` Niklas Holsti
  0 siblings, 1 reply; 23+ messages in thread
From: tolkamp @ 2010-10-21 17:09 UTC (permalink / raw)


On 21 okt, 18:47, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
> On 21.10.10 17:23, tolkamp wrote:
>
>
>
>
>
> > On 21 okt, 00:51, tmo...@acm.org wrote:
> >> This works for me for Windows
> >>     type Points is record
> >>       x,y : interfaces.c.int;
> >>     end record;
> >>     type bool is new interfaces.c.int;
> >>     function GetCursorPos(point : access points) return bool;
> >>     pragma import(stdcall,GetCursorPos, "GetCursorPos");
> >>     current : aliased points;
> >>     ...
> >>       if getcursorpos(current'access) = 0 then
> >>         -- current now has mouse position
> >>       else -- Windows error
>
> > When I include "with interfaces.c.int" the compilation results in
> > error:
> > Interface.C.Init is not a predefined library unit.
>
> "int" is the name of a type in package Interface.C.
> "With" that.
>
> Georg- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Yes, I understand, but how to make the compilation error free?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21 17:09             ` tolkamp
@ 2010-10-21 17:24               ` Niklas Holsti
  0 siblings, 0 replies; 23+ messages in thread
From: Niklas Holsti @ 2010-10-21 17:24 UTC (permalink / raw)


tolkamp wrote:
> On 21 okt, 18:47, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
>> On 21.10.10 17:23, tolkamp wrote:
>>
>>
>>
>>
>>
>>> On 21 okt, 00:51, tmo...@acm.org wrote:
>>>> This works for me for Windows
>>>>     type Points is record
>>>>       x,y : interfaces.c.int;
>>>>     end record;
>>>>     type bool is new interfaces.c.int;
>>>>     function GetCursorPos(point : access points) return bool;
>>>>     pragma import(stdcall,GetCursorPos, "GetCursorPos");
>>>>     current : aliased points;
>>>>     ...
>>>>       if getcursorpos(current'access) = 0 then
>>>>         -- current now has mouse position
>>>>       else -- Windows error
>>> When I include "with interfaces.c.int" the compilation results in
>>> error:
>>> Interface.C.Init is not a predefined library unit.
>> "int" is the name of a type in package Interface.C.
>> "With" that.
>>
>> Georg- Tekst uit oorspronkelijk bericht niet weergeven -
>>
>> - Tekst uit oorspronkelijk bericht weergeven -
> 
> Yes, I understand, 

I suspect not...

> but how to make the compilation error free?

You should write, as Georg no doubt meant:

   with Interfaces.C;

not "with Interfaces.C.Int". You always "with" a package or some other 
library unit (stand-alone subprogram), you do not "with" a type, even 
though that type is defined in a package.

HTH,

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21  7:31         ` Dmitry A. Kazakov
@ 2010-10-21 19:10           ` tmoran
  2010-10-21 19:38             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 23+ messages in thread
From: tmoran @ 2010-10-21 19:10 UTC (permalink / raw)


> Surely it is better to use it from win32ada than making own binding.
There are several reasons:
1. The program that polled for mouse position is a console mode
program, not an event driven Windows program (which of course would
have watched for a WM_MOUSEMOVE event instead).  The call to GetCursorPos
is the only inported function it uses, so win32ada would be overkill.
2. The win32ada I have is dated 2002.  Much of my Windows code predates
that (it uses CLAW) so I never started using win32ada.
3. My copy of win32.ads declares
  subtype PVOID is System.Address;
System.Address is not the same as an access value to my preferred Ada
compiler.
4. I also note that my copy of win32-windef.ads says, in the private part,
  pragma Convention(C_Pass_By_Copy, POINT);
which would of course make Jeffrey Carter's suggestion fail.  The
possibility of surprises like that makes me leary.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21 19:10           ` tmoran
@ 2010-10-21 19:38             ` Dmitry A. Kazakov
  2010-10-22  0:39               ` tmoran
  0 siblings, 1 reply; 23+ messages in thread
From: Dmitry A. Kazakov @ 2010-10-21 19:38 UTC (permalink / raw)


On Thu, 21 Oct 2010 19:10:37 +0000 (UTC), tmoran@acm.org wrote:

>> Surely it is better to use it from win32ada than making own binding.
> There are several reasons:
> 1. The program that polled for mouse position is a console mode
> program, not an event driven Windows program (which of course would
> have watched for a WM_MOUSEMOVE event instead).  The call to GetCursorPos
> is the only inported function it uses, so win32ada would be overkill.

I don't think so. win32ada is a maintained library, it is better to rely on
other people's work. Especially because of the 64 vs. 32 bit issue.

> 2. The win32ada I have is dated 2002.  Much of my Windows code predates
> that (it uses CLAW) so I never started using win32ada.

Yes, if you are using CLAW. However then, I would expect a call to a CLAW's
equivalent of the function.

> 3. My copy of win32.ads declares
>   subtype PVOID is System.Address;
> System.Address is not the same as an access value to my preferred Ada
> compiler.

But PVOID is an address, if an Ada's access type is not, then it cannot be
used for PVOID.

> 4. I also note that my copy of win32-windef.ads says, in the private part,
>   pragma Convention(C_Pass_By_Copy, POINT);
> which would of course make Jeffrey Carter's suggestion fail.
> The possibility of surprises like that makes me leary.

It only means that this win32ada (the AdaCore's one?) cannot be used with
your compiler. Win32 bindings are not necessarily portable across different
Ada compilers. You need win32ada for your compiler and if you don't have it
then, yes, you must roll up your own.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 22:51       ` tmoran
                           ` (2 preceding siblings ...)
  2010-10-21 15:23         ` tolkamp
@ 2010-10-21 20:34         ` tolkamp
  3 siblings, 0 replies; 23+ messages in thread
From: tolkamp @ 2010-10-21 20:34 UTC (permalink / raw)


On 21 okt, 00:51, tmo...@acm.org wrote:
> This works for me for Windows
>     type Points is record
>       x,y : interfaces.c.int;
>     end record;
>     type bool is new interfaces.c.int;
>     function GetCursorPos(point : access points) return bool;
>     pragma import(stdcall,GetCursorPos, "GetCursorPos");
>     current : aliased points;
>     ...
>       if getcursorpos(current'access) = 0 then
>         -- current now has mouse position
>       else -- Windows error

I have implemented your solution in my application.
The compilation is error free.
When I build an executable the following error occurs:
c:/gnat/2009/bin/../libexec/gcc/i686-pc-mingw32/4.3.4/ld.exe: cannot
find -lwin32ada
collect2: ld returned 1 exit status
gnatlink: error when calling C:\GNAT\2009\bin\gcc.exe
gnatmake: *** link failed.

winada is available in C:GNAT/2009/include/winada.
What is missing?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20  9:04 How to get the mouse position with JEWL? tolkamp
  2010-10-20 11:42 ` Manuel Collado
@ 2010-10-21 21:50 ` Manuel Collado
  2010-10-22 10:40   ` tolkamp
  1 sibling, 1 reply; 23+ messages in thread
From: Manuel Collado @ 2010-10-21 21:50 UTC (permalink / raw)


Back to the original posting !!

El 20/10/2010 11:04, tolkamp escribi�:
> I use JEWL in several of my applications.
> Now I try to get the mouse position within a JEWL canvas by using the
> function "End_Point(Canavas)".
> The resulting mouse position (x,y) is always zero. What is going wrong?

You must keep the mouse button pressed while moving. See:

   http://www.it.brighton.ac.uk/staff/je/jewl/docs/windows.htm#5.4

-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21 19:38             ` Dmitry A. Kazakov
@ 2010-10-22  0:39               ` tmoran
  2010-10-22  7:35                 ` Dmitry A. Kazakov
  2010-10-22 10:10                 ` Frank J. Lhota
  0 siblings, 2 replies; 23+ messages in thread
From: tmoran @ 2010-10-22  0:39 UTC (permalink / raw)


> > 3. My copy of win32.ads declares
> >   subtype PVOID is System.Address;
> > System.Address is not the same as an access value to my preferred Ada
> > compiler.
>
> But PVOID is an address, if an Ada's access type is not, then it cannot be
> used for PVOID.
   An "address" on a Wintel architecture is a segment and an offset.
(remember memory models?)  So Janus Ada's System.Address is a segment
and an offset.  PVOID is a C pointer, which is only an offset, the same as
an Ada access value in Janus Ada.

> > 4. I also note that my copy of win32-windef.ads says, in the private part,
> >   pragma Convention(C_Pass_By_Copy, POINT);
> > which would of course make Jeffrey Carter's suggestion fail.
> > The possibility of surprises like that makes me leary.
>
> It only means that this win32ada (the AdaCore's one?) cannot be used with
> your compiler. Win32 bindings are not necessarily portable across different
> Ada compilers.
  The C_Pass_By_Copy on POINT would make a function call with an "in"
parameter of Point pass in the POINT data, not a pointer to the data
as Carter's suggestion assumes.  That should be true of any Ada compiler.

But your main point, that win32ada is not portable and locks you into
certain compilers, is definitely true.  (I recall that making CLAW
portable across multiple Ada compilers required significant care.)



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-22  0:39               ` tmoran
@ 2010-10-22  7:35                 ` Dmitry A. Kazakov
  2010-10-22 10:10                 ` Frank J. Lhota
  1 sibling, 0 replies; 23+ messages in thread
From: Dmitry A. Kazakov @ 2010-10-22  7:35 UTC (permalink / raw)


On Fri, 22 Oct 2010 00:39:22 +0000 (UTC), tmoran@acm.org wrote:

>>> 3. My copy of win32.ads declares
>>>   subtype PVOID is System.Address;
>>> System.Address is not the same as an access value to my preferred Ada
>>> compiler.
>>
>> But PVOID is an address, if an Ada's access type is not, then it cannot be
>> used for PVOID.
>    An "address" on a Wintel architecture is a segment and an offset.
> (remember memory models?)

Yes. But Win32 has flat memory model, so PVOID is must be a far pointer at
least. [ BTW, it is not certain what is "address", virtual? physical? The
OS API may remap process addresses to the kernel ones etc. ]

>  So Janus Ada's System.Address is a segment
> and an offset.  PVOID is a C pointer, which is only an offset, the same as
> an Ada access value in Janus Ada.

There is no reason why Ada access type (without the Convention pragma)
should be equivalent to C pointer.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-22  0:39               ` tmoran
  2010-10-22  7:35                 ` Dmitry A. Kazakov
@ 2010-10-22 10:10                 ` Frank J. Lhota
  1 sibling, 0 replies; 23+ messages in thread
From: Frank J. Lhota @ 2010-10-22 10:10 UTC (permalink / raw)


On 10/21/2010 8:39 PM, tmoran@acm.org wrote:
>     An "address" on a Wintel architecture is a segment and an offset.
> (remember memory models?)  So Janus Ada's System.Address is a segment
> and an offset.  PVOID is a C pointer, which is only an offset, the same as
> an Ada access value in Janus Ada.

In Win16, an address is a segment and an offset. Win32 has a flat memory 
model, where an address is simply a 32 bit offset into a virtual space.

-- 
"All things extant in this world,
Gods of Heaven, gods of Earth,
Let everything be as it should be;
Thus shall it be!"
- Magical chant from "Magical Shopping Arcade Abenobashi"

"Drizzle, Drazzle, Drozzle, Drome,
Time for this one to come home!"
- Mr. Wizard from "Tooter Turtle"



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-21 21:50 ` Manuel Collado
@ 2010-10-22 10:40   ` tolkamp
  0 siblings, 0 replies; 23+ messages in thread
From: tolkamp @ 2010-10-22 10:40 UTC (permalink / raw)


On 21 okt, 23:50, Manuel Collado <m.coll...@domain.ivalid> wrote:
> Back to the original posting !!
>
> El 20/10/2010 11:04, tolkamp escribió:
>
> > I use JEWL in several of my applications.
> > Now I try to get the mouse position within a JEWL canvas by using the
> > function "End_Point(Canavas)".
> > The resulting mouse position (x,y) is always zero. What is going wrong?
>
> You must keep the mouse button pressed while moving. See:
>
>    http://www.it.brighton.ac.uk/staff/je/jewl/docs/windows.htm#5.4
>
> --
> Manuel Collado -http://lml.ls.fi.upm.es/~mcollado

When the left or right mouse button is keeping pressed the mouse
position remains zero.



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-20 22:22     ` Manuel Collado
  2010-10-20 22:51       ` tmoran
@ 2010-10-22 13:55       ` tolkamp
  2010-10-22 22:15         ` Manuel Collado
  1 sibling, 1 reply; 23+ messages in thread
From: tolkamp @ 2010-10-22 13:55 UTC (permalink / raw)


On 21 okt, 00:22, Manuel Collado <m.coll...@domain.ivalid> wrote:
> El 20/10/2010 19:20, tolkamp escribi :
>
>
>
>
>
> > On 20 okt, 13:42, Manuel Collado<m.coll...@domain.invalid>  wrote:
> >> El 20/10/2010 11:04, tolkamp escribi :
>
> >>> I use JEWL in several of my applications.
> >>> Now I try to get the mouse position within a JEWL canvas by using the
> >>> function "End_Point(Canavas)".
> >>> The resulting mouse position (x,y) is always zero. What is going wrong?
>
> >> Please try:
>
> >>    point := Start_Point( canvas );
>
> >> It works for me.
>
> > Also when I try:
> >   point := Start_Point( canvas );
> > the x and y position remains zero.
>
> > Here is the code:
>
> > task body Task_2Hz is
> > My_Frame  : Frame_Type;
> > My_Canvas : Canvas_Type;
> > My_Mouse_Position : Point_Type;
> > begin
> >      accept Start do
> >         My_Frame   := Frame (1200, 500, "", 0);
> >         My_Canvas  := Canvas (Frame, (850,10),      300, 300);
> > loop
> >         My_Mouse_Position := Start_Point(My_Canvas);
> >         Put("Mouse-x = "); Int_Io.Put(My_Mouse_Position.x); New_Line;
> >         Put("Mouse-y = "); Int_Io.Put(My_Mouse_Position.y); New_Line;
> >     delay 0.5;
> > end loop;
> > end Task_2Hz;
>
> IIRC, you must wait for a mouse event before reading the coordinates.
> Here is a code fragment of a real program that uses a canvas. You may
> figure how to adapt it to your needs:
>
>     function Get_Point return Point_Type is
>        Here: Point_Type;
>     begin
>        loop
>           case Next_Command is
>              when Cmd_Mouse =>
>                 exit;
>              when Cmd_Quit =>
>                 raise Program_Aborted;
>              when others =>
>                 null;
>           end case;
>        end loop;
>        Here := Start_Point( Main_Canvas );
>        return Logical( Here );
>     end Get_Point;
>
> Hope it helps.
> --
> Manuel Collado -http://lml.ls.fi.upm.es/~mcollado- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

What is the type of the following variables:
Next_Command, Cmd_Mouse, Program_Aborted?
What means Logical?



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-22 13:55       ` tolkamp
@ 2010-10-22 22:15         ` Manuel Collado
  2010-10-23 15:26           ` tolkamp
  0 siblings, 1 reply; 23+ messages in thread
From: Manuel Collado @ 2010-10-22 22:15 UTC (permalink / raw)


El 22/10/2010 15:55, tolkamp escribi�:
[sinipped]
>>>          My_Frame   := Frame (1200, 500, "", 0);
>>>          My_Canvas  := Canvas (Frame, (850,10),      300, 300);

This declares a non-interactive canvas.

>>> loop
>>>          My_Mouse_Position := Start_Point(My_Canvas);

I assume Start_Point()/End_Point() are not available for My_Canvas in 
this particular case.

Please RTFM:

- http://www.it.brighton.ac.uk/staff/je/jewl/docs/windows.htm#5
- http://www.it.brighton.ac.uk/staff/je/jewl/docs/windows.htm#5.4

Quoting them:

-----------------------------------
5. Canvases
...
- Canvas (Parent, Origin, Width, Height, Font)
   Construct a canvas... MOUSE CLICKS AND KEY PRESSES ARE BOTH IGNORED...

- Canvas (Parent, Origin, Width, Height, Command, Font)
   Construct a canvas as above. The additional Command parameter 
specifies the command to be generated when the mouse button is pressed. 
Key presses are ignored....

- Canvas (Parent, Origin, Width, Height, Command, Keypress, Font)
   Construct a canvas as above. The additional Keypress parameter is 
optional, and specifies the command to be generated when a key is pressed...

------------------------------------
5.4 Handling user interaction

A canvas can generate a command when the mouse button is pressed within 
its boundaries. This can be used to implement interactive drawing 
programs. There are several operations available to let the program 
track the mouse WHILE THE BUTTON IS DOWN:

Start_Point (Canvas)
End_Point (Canvas)
Mouse_Down (Canvas)
Mouse_Moved (Canvas)
------------------------------------

>>
>> IIRC, you must wait for a mouse event before reading the coordinates.
>> Here is a code fragment of a real program that uses a canvas. You may
>> figure how to adapt it to your needs:
>>
>>      function Get_Point return Point_Type is
>>         Here: Point_Type;
>>      begin
>>         loop
>>            case Next_Command is
>>               when Cmd_Mouse =>
>>                  exit;
>>               when Cmd_Quit =>
>>                  raise Program_Aborted;
>>               when others =>
>>                  null;
>>            end case;
>>         end loop;
>>         Here := Start_Point( Main_Canvas );
>>         return Logical( Here );
>>      end Get_Point;
>>
>
> What is the type of the following variables:
> Next_Command, Cmd_Mouse, Program_Aborted?

The type is the user-defined Command_Type (a generic parameter of 
JEWL.Windows). I usually use JEWL.Simple_Windows, which defines 
Command_Type => Character.

My canvas is created as:

    Cmd_Quit  : constant Character := 'Q';  -- for frame
    Cmd_Mouse : constant Character := 'M';  -- for canvas
    Cmd_Key   : constant Character := 'K';  -- for canvas

    Main_Canvas := Canvas(
       Main_Frame, (0,0), 0, 0, Cmd_Mouse, Cmd_Key, ... );

> What means Logical?

It is just a scale conversion from the screen coordinates (pixels) to 
the logical coordinates of my application.

Hint: the JEWL.Windows User Manual contains a lot of code samples.
-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: How to get the mouse position with JEWL?
  2010-10-22 22:15         ` Manuel Collado
@ 2010-10-23 15:26           ` tolkamp
  0 siblings, 0 replies; 23+ messages in thread
From: tolkamp @ 2010-10-23 15:26 UTC (permalink / raw)


On 23 okt, 00:15, Manuel Collado <m.coll...@domain.ivalid> wrote:
> El 22/10/2010 15:55, tolkamp escribió:
> [sinipped]
>
> >>>          My_Frame   := Frame (1200, 500, "", 0);
> >>>          My_Canvas  := Canvas (Frame, (850,10),      300, 300);
>
> This declares a non-interactive canvas.
>
> >>> loop
> >>>          My_Mouse_Position := Start_Point(My_Canvas);
>
> I assume Start_Point()/End_Point() are not available for My_Canvas in
> this particular case.
>
> Please RTFM:
>
> -http://www.it.brighton.ac.uk/staff/je/jewl/docs/windows.htm#5
> -http://www.it.brighton.ac.uk/staff/je/jewl/docs/windows.htm#5.4
>
> Quoting them:
>
> -----------------------------------
> 5. Canvases
> ...
> - Canvas (Parent, Origin, Width, Height, Font)
>    Construct a canvas... MOUSE CLICKS AND KEY PRESSES ARE BOTH IGNORED...
>
> - Canvas (Parent, Origin, Width, Height, Command, Font)
>    Construct a canvas as above. The additional Command parameter
> specifies the command to be generated when the mouse button is pressed.
> Key presses are ignored....
>
> - Canvas (Parent, Origin, Width, Height, Command, Keypress, Font)
>    Construct a canvas as above. The additional Keypress parameter is
> optional, and specifies the command to be generated when a key is pressed...
>
> ------------------------------------
> 5.4 Handling user interaction
>
> A canvas can generate a command when the mouse button is pressed within
> its boundaries. This can be used to implement interactive drawing
> programs. There are several operations available to let the program
> track the mouse WHILE THE BUTTON IS DOWN:
>
> Start_Point (Canvas)
> End_Point (Canvas)
> Mouse_Down (Canvas)
> Mouse_Moved (Canvas)
> ------------------------------------
>
>
>
>
>
>
>
> >> IIRC, you must wait for a mouse event before reading the coordinates.
> >> Here is a code fragment of a real program that uses a canvas. You may
> >> figure how to adapt it to your needs:
>
> >>      function Get_Point return Point_Type is
> >>         Here: Point_Type;
> >>      begin
> >>         loop
> >>            case Next_Command is
> >>               when Cmd_Mouse =>
> >>                  exit;
> >>               when Cmd_Quit =>
> >>                  raise Program_Aborted;
> >>               when others =>
> >>                  null;
> >>            end case;
> >>         end loop;
> >>         Here := Start_Point( Main_Canvas );
> >>         return Logical( Here );
> >>      end Get_Point;
>
> > What is the type of the following variables:
> > Next_Command, Cmd_Mouse, Program_Aborted?
>
> The type is the user-defined Command_Type (a generic parameter of
> JEWL.Windows). I usually use JEWL.Simple_Windows, which defines
> Command_Type => Character.
>
> My canvas is created as:
>
>     Cmd_Quit  : constant Character := 'Q';  -- for frame
>     Cmd_Mouse : constant Character := 'M';  -- for canvas
>     Cmd_Key   : constant Character := 'K';  -- for canvas
>
>     Main_Canvas := Canvas(
>        Main_Frame, (0,0), 0, 0, Cmd_Mouse, Cmd_Key, ... );
>
> > What means Logical?
>
> It is just a scale conversion from the screen coordinates (pixels) to
> the logical coordinates of my application.
>
> Hint: the JEWL.Windows User Manual contains a lot of code samples.
> --
> Manuel Collado -http://lml.ls.fi.upm.es/~mcollado- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Hello Manuel,

Implementing your solution works now perfect. Thank you very much for
your help.



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2010-10-23 15:26 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-20  9:04 How to get the mouse position with JEWL? tolkamp
2010-10-20 11:42 ` Manuel Collado
2010-10-20 17:20   ` tolkamp
2010-10-20 22:22     ` Manuel Collado
2010-10-20 22:51       ` tmoran
2010-10-21  2:59         ` Jeffrey Carter
2010-10-21  4:08           ` tmoran
2010-10-21  7:31         ` Dmitry A. Kazakov
2010-10-21 19:10           ` tmoran
2010-10-21 19:38             ` Dmitry A. Kazakov
2010-10-22  0:39               ` tmoran
2010-10-22  7:35                 ` Dmitry A. Kazakov
2010-10-22 10:10                 ` Frank J. Lhota
2010-10-21 15:23         ` tolkamp
2010-10-21 16:47           ` Georg Bauhaus
2010-10-21 17:09             ` tolkamp
2010-10-21 17:24               ` Niklas Holsti
2010-10-21 20:34         ` tolkamp
2010-10-22 13:55       ` tolkamp
2010-10-22 22:15         ` Manuel Collado
2010-10-23 15:26           ` tolkamp
2010-10-21 21:50 ` Manuel Collado
2010-10-22 10:40   ` tolkamp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox