Recent Posts

Pages: 1 ... 5 6 [7] 8 9 10
61
EZGUI 5 support forum / Re: Moving Sprites
« Last post by Chris Boss on December 22, 2022, 09:42:09 am »
The Canvas control does not respond to key presses.

You may want to preprocess the keyboard events before they get sent to other controls.

I would venture to say your problem may be more associated with how you handle the keyboard events rather than actually moving the sprite.

62
EZGUI 5 support forum / Re: Moving Sprites
« Last post by Chris Boss on December 22, 2022, 09:36:27 am »
The EZ_MoseSP command works well but you have to have the sprite index rather than a name.
use the EZ_GetFastSPIndex function to get the sprite index.

Code: [Select]
     FOR I&=1 TO 10
          ' move each sprite 8 pixels in both directions
          EZ_MoveSP SpriteIndex&(I&), 8, 8, 1
     NEXT I&
63
EZGUI 5 support forum / Moving Sprites
« Last post by Brian Reynolds on December 22, 2022, 02:16:19 am »
I am trying to move a sprite continuously by holding down one of the four Arrow keys but I can only get the sprite to move one pixel at a time.
Could someone offer a suggestion on how to do it.
I'm sure I did this a few years ago but my memory loss keeps increasing with my age.
Brian Reynolds.
64
EZGUI 5 support forum / Re: Sprite Problem
« Last post by Chris Boss on December 19, 2022, 12:54:42 pm »
EZ_TestSpriteClick does not actually test for an actual click. It simply is passed the coordinates of the last click and it just calculates from that position which sprite the coordinates are on.

You have to get the actual mouse click position for the canvas control first, which is done using the EZ_GetCanvasXY command which you can call in the Canvas controls %EZ_Click event.

EZGUI stores the last X, Y position when the left mouse button is pressed down. It generates the %EZ_Click event so you can process it there.

Now let's say you want to drag a sprite around, you can subclass the Canvas control and then in the %EZ_LButtonDown event get the X,Y position of the mouse and then call EZ_TestSpriteClick and then start a drag process to draw the sprite around.

You can use EZ_GetMouseXY instead of EZ_GetCanvasXY when processing it in the %EZ_LButtonDown event.

Here is some old EZGUI 4.0 code (should work) where I drag a sprite around by processing the %EZ_LButtonDown event and using EZ_TestSpriteClick to figure out which sprite needs to be dragged:

Code: [Select]
UB Form1_Events(CID&, CMsg&, CVal&, Cancel&)
    LOCAL X&, Y&, SX&, SY&
    STATIC SPN$
    SELECT CASE CID&
        CASE %EZ_Window
            IF CMsg&=%EZ_Started THEN
                MakeSprites
            END IF
        CASE  %FORM1_CANVAS1
            IF CMsg&=%EZ_SelectCursor THEN
                IF App_MoveFlag&=0 THEN
                    SPN$ = EZ_TestSpriteClick ("Form1", %FORM1_CANVAS1, App_MouseX&, App_MouseY&)
                    IF SPN$<>"" THEN
                        EZ_SetCursor "", 4
                        Cancel&=1
                    END IF
                END IF
            END IF
            IF CMsg&=%EZ_LButtonDown THEN
                EZ_GetMouseXY CVal&, X&, Y&
                SPN$ = EZ_TestSpriteClick ("Form1", %FORM1_CANVAS1, X&, Y&)
                IF SPN$<>"" THEN
                    IF EZ_GetSpriteXY (SPN$, SX&, SY&) THEN
                        EZ_SetCaptureEx EZ_Handle("Form1", %FORM1_CANVAS1)
                        EZ_SetCursor "", 1
                        App_MoveFlag&=1
                        App_OffsetX&=X&-SX&
                        App_OffsetY&=Y&-SY&
                    END IF
                END IF
            END IF
            IF CMsg&=%EZ_MouseMove THEN
                EZ_GetMouseXY CVal&, X&, Y&
                App_MouseX&=X&
                App_MouseY&=Y&
                IF App_MoveFlag& THEN
                    EZ_MoveSprites SPN$, X&-App_OffsetX&, Y&-App_OffsetY&, 0
                    EZ_UpdateClient "Form1", %FORM1_CANVAS1
                END IF
            END IF
            IF CMsg&=%EZ_LButtonUp THEN
                App_MoveFlag&=0
                EZ_SetCaptureEx 0
            END IF
        CASE ELSE
    END SELECT
END SUB             

Notice when dragging a sprite you need to capture the mouse once you process the %EZ_LButtonDown event. 

65
EZGUI 5 support forum / Re: Sprite Problem
« Last post by Chris Boss on December 19, 2022, 12:30:39 pm »
No, you can get a sprite click. It is demonstrated in the sprite example in the codeclips folder.

Here is the code from that sample app:

Code: [Select]
SUB FORM1_CANVAS1_Click()
     LOCAL X&,Y&
     EZ_GetCanvasXY  "{ME}",  %FORM1_CANVAS1, X&, Y&, 0,0
     MSGBOX "You clicked me:"+STR$(X&)+STR$(Y&)+" "+EZ_TestSpriteClick("{ME}", %FORM1_CANVAS1, X&,Y&)
END SUB

66
EZGUI 5 support forum / Re: Sprite Problem
« Last post by Brian Reynolds on December 17, 2022, 02:18:43 am »
Thank you for your explanation, Chris.
From that as well as reading other "GetSprite" info, I take it there is no way of clicking on a Sprite and retrieving its name or X or Y position.
 
67
EZGUI 5 support forum / Re: Sprite Problem
« Last post by Chris Boss on December 16, 2022, 10:00:22 pm »
EZ_TestSpriteClick does not work the way you think.

The X& and Y& parameters are not return values, but are passed BYVAL telling the function where the coordinates to test are.

In the Canvas control's %EZ_Click event you have to call first:

EZ_GetCanvasXY

to get the coordinates for the last mouse click.

Then you can pass them to EZ_TestSpriteClick to see if the click occurred on a sprite.

68
EZGUI 5 support forum / Sprite Problem
« Last post by Brian Reynolds on December 16, 2022, 02:11:37 am »
I've struck a problem with Sprites. Using the following code, I get nothing for the Sprite name and a zero of each of the X& and Y&.
I am running Windows 11.

      CASE %EZ_Click
         a$ = EZ_TestSpriteClick("Form1", %Form1_Canvas1, X&, Y&)
         MSGBOX a$ +STR$(X&)+STR$(Y& )

Can you offer help?
69
EZGUI 5 support forum / Re: Strange event
« Last post by Brian Reynolds on November 18, 2022, 12:32:24 am »
I have managed to fix this and many other strange events I was experiencing.
I bought a new computer running Windows 11 -- Much faster, nothing strange.
Thanks to all who offered their support.
70
EZGUI 5 support forum / Re: DateTime control
« Last post by Chris Boss on August 27, 2022, 11:49:44 am »
The %EZ_Loading event occurs just "before" the control is created, so you can't use any commands which expect the control to exist in this event.

EZ_DefCalendarExColors

will fail in %EZ_Loading because the control does not exist yet.

The event %EZ_Loaded (ends in ed rather than ing) occurs right after the control is created, but before it is visible, so you can make calls to commands
which expect the control to exist in this event.

EZ_DefCalendarExColors should work fine in the %EZ_Loaded event !

Any command which has parameters for the form name and control ID, must be called only after the control is created and exists.

%EZ_Loading serves the purpose of changing control creation parameters for a control before it is created and for calls to EZGUI commands which have to be called before a control is create (ie. EZ_Color, EZ_UseFont).

Internally in all control creation commands it works this way:

{Control Creation Command}
  • Generate %EZ_Loading event if flagged to do so by a previous EZ_AllowLoadingEvent command
  • Modify any control creation parameters if changing in %EZ_Loading event using EZ_SetLoadStr or EZ_SetLoadVal commands
  • Create Control
  • Generate %EZ_Loaded event

By understand the sequence EZGUI uses when creating controls you will know what you can do in each of the events, %EZ_Loading and %EZ_Loaded

Forms work the same way, but also have a third event called:

%EZ_Started

which occurs after the form is created, all the controls are created and the form is now visible




Pages: 1 ... 5 6 [7] 8 9 10