IrvKalb / pygwidgets

A collection of user interface widgets in Python for use in programs using Pygame.
BSD 2-Clause "Simplified" License
11 stars 5 forks source link

ImageCollection's replace method does not work well with rotate method #7

Closed landochan closed 1 year ago

landochan commented 1 year ago
import pygwidgets
import pygame

window = pygame.display.set_mode((600, 600))
FPSCLOCK = pygame.time.Clock()
testImage = pygwidgets.Image(window, (200, 200), 'images/testImage.png')
testImageCollection = pygwidgets.ImageCollection(window, (300, 300), {'test1':'images/testImage.png', 'test2':'images/testImage.png'}, 'test1')

while True:
    window.fill('black')

    testImage.rotate(10)
    testImageCollection.rotate(10)

    testImageCollection.replace('test2')

    testImage.draw()
    testImageCollection.draw()

    pygame.display.update()
    FPSCLOCK.tick(30)
landochan commented 1 year ago

Issue's description: The Image's rotate and ImageCollection's rotate method rotate both images from the center axis of the Image(/ImageCollection).

However, when I try to create a new game, I found out that when you call replace method on ImageCollection, and then try to rotate it, the results are unsatisfying. The ImageCollection will fly out of the window to some unknown space. Now that I remember that Image has replace method as well, I tried the same thing, and the result is the same, the image fly out of the window.

I put up the code above so that you you could compare what is happening when the object does not execute replace method and when the object execute replace method.

Sincerely yours, Lando Chan

landochan commented 1 year ago

Sorry for another late addition about the code,

You should put one image in 'images/testImage.png' to make this code works.

IrvKalb commented 1 year ago

Thanks for pointing this out.

I believe I have a fix for this. I have built a test case based on what you showed. I'll attach a zip file here that includes a test program and an updated version of pygwidgets.py.

The test program starts by showing two (black) cards rotating. The upper left is an Image object, the other one is an ImageCollection object. When you click on the images, the code does a call to the replace() method to switch to a red card.

If this works the way that you expect, would you please try this version of pygwidgets with whatever program you were originally trying to use, and let me know if it works. If not, feel free to send me your program so I can test it with an updated pygwidgets.

Also, you can reach me directly at Irv at furrypants dot com

Irv TestRotateAndReplace.zip

IrvKalb commented 1 year ago

I'm just writing you back to make sure that you have seen my update to your issue on GitHub. I have a modified version of pygwidgets with a test program for you. When you have time, would you please check out the test program and try the new pygwidgets with your code.

Irv


From: Lando Chan @.> Sent: Tuesday, February 28, 2023 4:14 AM To: IrvKalb/pygwidgets @.> Cc: Subscribed @.***> Subject: Re: [IrvKalb/pygwidgets] ImageCollection's replace method does not work well with rotate method (Issue #7)

Sorry for another late addition about the code,

You should put some images in 'images/testImage.png' to make this code works.

— Reply to this email directly, view it on GitHubhttps://github.com/IrvKalb/pygwidgets/issues/7#issuecomment-1448081029, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABXUYSXCGZFSPE6HB5M5FULWZXT3HANCNFSM6AAAAAAVKUIA7Y. You are receiving this because you are subscribed to this thread.Message ID: @.***>

landochan commented 1 year ago

Good morning/afternoon/night

I am sorry for the late reply. Thank you for the reply. It works perfectly fine with replace. But then I found something else. When you scale the picture and rotate it, it will work perfectly fine when I scale it from the center, but the picture won't rotate smoothly, if I scale it not from the center. I give an example using two cars. (in ZIP file) The left car is centered to 80% from the center, while the other car is centered to 80% not from the center.

Best regards, Lando Chan

On Fri, Mar 3, 2023 at 3:10 PM Irv Kalb @.***> wrote:

I'm just writing you back to make sure that you have seen my update to your issue on GitHub. I have a modified version of pygwidgets with a test program for you. When you have time, would you please check out the test program and try the new pygwidgets with your code.

Irv


From: Lando Chan @.> Sent: Tuesday, February 28, 2023 4:14 AM To: IrvKalb/pygwidgets @.> Cc: Subscribed @.***> Subject: Re: [IrvKalb/pygwidgets] ImageCollection's replace method does not work well with rotate method (Issue #7)

Sorry for another late addition about the code,

You should put some images in 'images/testImage.png' to make this code works.

— Reply to this email directly, view it on GitHub< https://github.com/IrvKalb/pygwidgets/issues/7#issuecomment-1448081029>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABXUYSXCGZFSPE6HB5M5FULWZXT3HANCNFSM6AAAAAAVKUIA7Y

. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/IrvKalb/pygwidgets/issues/7#issuecomment-1453027667, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ2S6BSSC5OVIZ3ZKOBAROLW2GDMJANCNFSM6AAAAAAVKUIA7Y . You are receiving this because you authored the thread.Message ID: @.***>

IrvKalb commented 1 year ago

Hi,

I got your message, but I don't see an attachment. I looked on github and I didn't see one there either. You can send it to me directly at Irv at furrypants dot com.

However, I'm not sure if I understand the issue. The rotateFromCenter parameter is a boolean. If True, the image should grow (or shrink) with the center point the same. If False, the code assumes that you want to keep the upper left corner the same and the image should grow (or shrink) from the same location.

I'll check it out when I see your example files.

Irv


From: Lando Chan @.> Sent: Sunday, March 5, 2023 6:41 PM To: IrvKalb/pygwidgets @.> Cc: irv furrypants.com @.>; Comment @.> Subject: Re: [IrvKalb/pygwidgets] ImageCollection's replace method does not work well with rotate method (Issue #7)

Good morning/afternoon/night

I am sorry for the late reply. Thank you for the reply. It works perfectly fine with replace. But then I found something else. When you scale the picture and rotate it, it will work perfectly fine when I scale it from the center, but the picture won't rotate smoothly, if I scale it not from the center. I give an example using two cars. (in ZIP file) The left car is centered to 80% from the center, while the other car is centered to 80% not from the center.

Best regards, Lando Chan

On Fri, Mar 3, 2023 at 3:10 PM Irv Kalb @.***> wrote:

I'm just writing you back to make sure that you have seen my update to your issue on GitHub. I have a modified version of pygwidgets with a test program for you. When you have time, would you please check out the test program and try the new pygwidgets with your code.

Irv


From: Lando Chan @.> Sent: Tuesday, February 28, 2023 4:14 AM To: IrvKalb/pygwidgets @.> Cc: Subscribed @.***> Subject: Re: [IrvKalb/pygwidgets] ImageCollection's replace method does not work well with rotate method (Issue #7)

Sorry for another late addition about the code,

You should put some images in 'images/testImage.png' to make this code works.

— Reply to this email directly, view it on GitHub< https://github.com/IrvKalb/pygwidgets/issues/7#issuecomment-1448081029>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/ABXUYSXCGZFSPE6HB5M5FULWZXT3HANCNFSM6AAAAAAVKUIA7Y

. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/IrvKalb/pygwidgets/issues/7#issuecomment-1453027667, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ2S6BSSC5OVIZ3ZKOBAROLW2GDMJANCNFSM6AAAAAAVKUIA7Y . You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/IrvKalb/pygwidgets/issues/7#issuecomment-1455347204, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABXUYSSI772RM3KE5DN2SR3W2VFHDANCNFSM6AAAAAAVKUIA7Y. You are receiving this because you commented.Message ID: @.***>

IrvKalb commented 1 year ago

Fixed in pygwidgets 1.0.4