fszontagh
2024-02-25 5d543bcc0d15b871315a2123aec01041d73c53fb
ui/ImageViewerImageWindow.h
@@ -9,17 +9,87 @@
#include "ImageViewer.h"
//// end generated include
#include <map>
#include <iostream>
#include "../res/app_icon.h"
#include "../utils.h"
/** Implementing ImageWindow */
class ImageViewerImageWindow : public ImageWindow
{
   public:
      /** Constructor */
      ImageViewerImageWindow( wxWindow* parent );
protected:
   // Handlers for ImageWindow events.
   void OnDropFile(wxDropFilesEvent &event);
   void OnWindowKeyUp(wxKeyEvent &event);
   void OnWindowMouseWheel(wxMouseEvent &event);
   void WindowOnSize(wxSizeEvent &event);
   void OnBitmapDoubleLeftClick(wxMouseEvent &event);
   void OnListItemSelected(wxListEvent &event);
   void OnRotateLeftClicked(wxCommandEvent &event);
   void OnRotateRightClicked(wxCommandEvent &event);
   void OnZoomInClicked(wxCommandEvent &event);
   void OnZoomResetClicked(wxCommandEvent &event);
   void OnZoomOutClicked(wxCommandEvent &event);
   void OnShowFullScreenClick(wxCommandEvent &event);
public:
   /** Constructor */
   ImageViewerImageWindow(wxWindow *parent);
   //// end generated class members
private:
   wxString windowTitle;
   /// @brief int imagelist id, wxImage the image
   std::map<int, ImageUtils::ImageFileInfo *> images;
   wxImage currentVisibleImage;
   wxImage currentOriginalImage;
   wxImageList *imgList;
   int currentZoom = 100;
   void ShowImage(wxImage img);
   wxImage FitImage(wxImage img, int targetWidth, int targetHeight);
   wxImage RotateImage(ImageUtils::ROTATE_DIRECTION dir, wxImage img);
   void ZoomImage(int factor);
   inline wxImage cropResizeImage(const wxImage &originalImage, int targetWidth, int targetHeight)
   {
      int originalWidth = originalImage.GetWidth();
      int originalHeight = originalImage.GetHeight();
      double aspectRatio = static_cast<double>(originalWidth) / static_cast<double>(originalHeight);
      int newWidth = targetWidth;
      int newHeight = targetHeight;
      // Kiszámítjuk az új méreteket, hogy megtartsuk a képarányt
      if (originalWidth > targetWidth || originalHeight > targetHeight)
      {
         if (aspectRatio > 1.0)
         {
            // Szélesség alapján skálázzuk az új méretet
            newWidth = targetWidth;
            newHeight = static_cast<int>(targetWidth / aspectRatio);
         }
         else
         {
            // Magasság alapján skálázzuk az új méretet
            newHeight = targetHeight;
            newWidth = static_cast<int>(targetHeight * aspectRatio);
         }
      }
      // Méretezzük az eredeti képet az új méretekre
      wxImage resizedImage = originalImage.Scale(newWidth, newHeight);
      // Üres terület hozzáadása és transzparens töltése
      if (newWidth < targetWidth || newHeight < targetHeight)
      {
         wxImage finalImage(targetWidth, targetHeight);
         finalImage.SetAlpha();
         finalImage.Paste(resizedImage, (targetWidth - newWidth) / 2, (targetHeight - newHeight) / 2);
         return finalImage;
      }
      return resizedImage;
   }
};
#endif // __ImageViewerImageWindow__