[Scummvm-cvs-logs] SF.net SVN: scummvm: [28116] scummex/branches/gsoc2007-gameresbrowser

zbychs at users.sourceforge.net zbychs at users.sourceforge.net
Mon Jul 16 01:57:43 CEST 2007


Revision: 28116
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28116&view=rev
Author:   zbychs
Date:     2007-07-15 16:57:42 -0700 (Sun, 15 Jul 2007)

Log Message:
-----------
Added image viewer with zoom.

Modified Paths:
--------------
    scummex/branches/gsoc2007-gameresbrowser/src/browser/ExplorationTree.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/browserapp/BrowserApp.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/browserapp/Makefile.am
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.h
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/Makefile.am
    scummex/branches/gsoc2007-gameresbrowser/vc8/Browser.sln
    scummex/branches/gsoc2007-gameresbrowser/vc8/basic_plugin/basic_plugin.vcproj
    scummex/branches/gsoc2007-gameresbrowser/vc8/browserapp/browserapp.vcproj

Added Paths:
-----------
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.h
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.cpp
    scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.h

Modified: scummex/branches/gsoc2007-gameresbrowser/src/browser/ExplorationTree.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/ExplorationTree.cpp	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/ExplorationTree.cpp	2007-07-15 23:57:42 UTC (rev 28116)
@@ -553,6 +553,13 @@
 	removeIdx();
 	_detached = true;
 
+	/*wxBoxSizer *panelsizer = new wxBoxSizer(wxVERTICAL);
+	panelsizer->Add(_page, 1, wxALL|wxEXPAND, 0);
+
+	frame->SetAutoLayout(true);
+	frame->SetSizer(panelsizer);	
+	frame->Layout();*/
+
 	frame->Show(true);
 }
 

Modified: scummex/branches/gsoc2007-gameresbrowser/src/browserapp/BrowserApp.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browserapp/BrowserApp.cpp	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browserapp/BrowserApp.cpp	2007-07-15 23:57:42 UTC (rev 28116)
@@ -14,6 +14,10 @@
 #include "MainForm.h"
 #include "guicon.h"
 
+#include <wx/filename.h>
+
+//#include "MadEdit.h"
+
 IMPLEMENT_APP(BrowserDlgApp)
 
 bool BrowserDlgApp::OnInit() {
@@ -22,8 +26,29 @@
 	SetTopWindow(dialog);
 	dialog->Show(true);*/
 	MainForm* mainForm = new MainForm(NULL);
+
+
 	SetTopWindow(mainForm);
 	mainForm->Show(true);
+
+
+	/*const long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU | wxTHICK_FRAME | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxCLOSE_BOX;
+	wxFrame* frame = new wxFrame(mainForm, wxID_ANY, wxT("MadEdit"));
+
+	*MadEdit* madEdit = new MadEdit(frame);
+
+	wxFileName fn(wxT("C:\\Zbys\\gsoc\\Browser\\vc8\\dummy.txt"));
+	madEdit->LoadFromFile(fn.GetFullPath());
+
+	*wxBoxSizer *panelsizer = new wxBoxSizer(wxVERTICAL);
+	panelsizer->Add(_page, 1, wxALL|wxEXPAND, 0);
+
+	frame->SetAutoLayout(true);
+	frame->SetSizer(panelsizer);	
+	frame->Layout();*
+
+	frame->Show(true);*/
+
 	return true;
 }
  

Modified: scummex/branches/gsoc2007-gameresbrowser/src/browserapp/Makefile.am
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browserapp/Makefile.am	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browserapp/Makefile.am	2007-07-15 23:57:42 UTC (rev 28116)
@@ -35,6 +35,8 @@
 	$(builddir)/../plugins/basic/AuxInterfaces.o \
 	$(builddir)/../plugins/basic/BasicParsers.o \
 	$(builddir)/../plugins/basic/BitmapPanel.o \
+	$(builddir)/../plugins/basic/ImageBox.o \
+	$(builddir)/../plugins/basic/ImageProc.o \
 	$(builddir)/../plugins/basic/DirectoryPresenter.o \
 	$(builddir)/../plugins/basic/DiskFileProvider.o \
 	$(builddir)/../plugins/basic/FileInfoPresenter.o \

Added: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.cpp	                        (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.cpp	2007-07-15 23:57:42 UTC (rev 28116)
@@ -0,0 +1,265 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        ImageBox.cpp
+// Purpose:     wxImageBox class
+// Author:      Alex Thuering
+// Created:		8.10.2003
+// RCS-ID:      $Id: ImageBox.cpp,v 1.4 2005/01/09 15:45:42 ntalex Exp $
+// Copyright:   (c) Alex Thuering
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#include "basic_stdafx.h"
+
+#include "ImageBox.h"
+#include "ImageProc.h"
+#include "math.h"
+
+////////////////////////////////////////////////////////////
+////////////////////// wxImageBox //////////////////////////
+////////////////////////////////////////////////////////////
+
+BEGIN_EVENT_TABLE(wxImageBox, wxPaintBox)
+  EVT_SIZE(wxImageBox::OnResize)
+  EVT_RIGHT_DOWN(wxImageBox::OnMouseRightButton)
+  EVT_RIGHT_UP(wxImageBox::OnMouseRightButton)
+END_EVENT_TABLE()
+
+DEFINE_EVENT_TYPE(EVT_COMMAND_IMAGEBOX_IMAGE_CHANGED)
+
+wxImageBox::wxImageBox(wxWindow *parent, wxWindowID id) : wxPaintBox(parent, id)
+{
+  m_scaleV = m_scale = 1;
+  m_repaint = false;
+  m_pmenu = NULL;
+}
+
+void wxImageBox::UpdatePaintBox()
+{
+  m_repaint = true;
+  UpdateScaleValue();
+  Refresh();
+}
+
+void wxImageBox::Update()
+{
+  wxCommandEvent evt(EVT_COMMAND_IMAGEBOX_IMAGE_CHANGED, this->GetId());
+  GetEventHandler()->ProcessEvent(evt);
+  UpdatePaintBox();
+}
+
+bool wxImageBox::LoadFile(wxString fname)
+{
+  if (!GetImage().LoadFile(fname))
+    return false;
+  Update();
+  return true;
+}
+
+void wxImageBox::Clear()
+{
+  GetImage().Create(0,0);
+  Update();
+}
+
+bool wxImageBox::IsEmpty()
+{
+  return !GetImage().Ok();
+}
+
+void wxImageBox::SetScale(double scale)
+{
+  m_scaleV = scale;
+  UpdatePaintBox();
+}
+
+bool wxImageBox::UpdateScaleValue()
+{
+  if (!GetImage().Ok())
+  {
+    m_scale = 1;
+    return false;
+  }
+  double old = m_scale;
+  m_scale = m_scaleV;
+  if (m_scale < 0) // fit to page, width, height
+  {
+    wxSize page = GetSize();
+    wxSize cpage = GetClientSize();
+    if ((page.GetWidth() == 0) || (page.GetHeight() == 0))
+      return false;
+    
+    if (m_scale == scFIT_TO_WIDTH)
+    {
+      m_scale = (double) page.GetWidth()/GetImage().GetWidth();
+      if (GetImage().GetHeight()*m_scale > page.GetHeight())
+        m_scale = (double) cpage.GetWidth()/GetImage().GetWidth();
+    }
+    else if (m_scale == scFIT_TO_HEIGHT)
+    {
+      m_scale = (double) page.GetHeight()/GetImage().GetHeight();
+      if (GetImage().GetWidth()*m_scale > page.GetWidth())
+        m_scale = (double) cpage.GetHeight()/GetImage().GetHeight();
+    }
+    else //if (m_scale == scFIT_TO_PAGE)
+    {
+      m_scale = (double) page.GetWidth()/GetImage().GetWidth();
+      if (m_scale > (double) page.GetHeight()/GetImage().GetHeight())
+      m_scale = (double) page.GetHeight()/GetImage().GetHeight();
+    }
+  }
+  //wxMessageBox(wxString::Format("%f", m_scale));
+  return old != m_scale;
+}
+
+wxRect wxImageBox::getPaintRect()
+{
+  wxSize size = GetClientSize();
+  wxRect paintRect(0, 0, size.GetWidth(), size.GetHeight());
+  GetViewStart(&paintRect.x, &paintRect.y);
+  int xu,yu;
+  GetScrollPixelsPerUnit(&xu, &yu);
+  paintRect.x *= xu; paintRect.y *= yu;
+  return paintRect;
+}
+
+void wxImageBox::Paint()
+{
+  // image width & height
+  m_imageWidth = (int) (GetImage().GetWidth()*m_scale);
+  m_imageHeight = (int) (GetImage().GetHeight()*m_scale);
+  if (m_imageWidth == 0 || m_imageHeight == 0)
+  {
+	delete m_buffer;
+	m_buffer = new wxBitmap(0,0);
+    return;
+  }
+  
+  // get paintRect
+  wxRect paintRect = getPaintRect();
+  // make buffer 2 times as big as visible area (paintRect)
+  paintRect.x -= paintRect.width/2; if (paintRect.x < 0) paintRect.x = 0;
+  paintRect.y -= paintRect.height/2; if (paintRect.y < 0) paintRect.y = 0;
+  paintRect.width *= 2;
+  paintRect.height *= 2;
+  
+  if (paintRect.GetRight() > m_imageWidth)
+    paintRect.width = m_imageWidth - paintRect.x;
+  if (paintRect.GetBottom() > m_imageHeight)
+    paintRect.height = m_imageHeight - paintRect.y;
+  
+  m_bufferX = paintRect.x;
+  m_bufferY = paintRect.y;
+  
+  // scale
+  //wxImage img = GetImage().Scale(m_imageWidth, m_imageHeight);
+  wxRect subRect = ScaleRect(paintRect, 1/m_scale);
+  wxImage img;
+  int imgw = GetImage().GetWidth();
+  int imgh = GetImage().GetHeight();
+  // if subRect equal image (+-1%)
+  if (subRect.x*100/imgw!=0 || subRect.y*100/imgh!=0 ||
+     (subRect.width-imgw)*100/imgw!=0 || (subRect.height-imgh)*100/imgh!=0)
+    img = GetImage().GetSubImage(subRect);
+  else
+    img = GetImage();
+  img = img.Scale(paintRect.width, paintRect.height);
+  
+  PaintImg(img);
+  delete m_buffer;
+  m_buffer = new wxBitmap(img);
+}
+
+void wxImageBox::PaintImg(wxImage& img)
+{
+}
+
+void wxImageBox::OnPaint(wxPaintEvent &event)
+{
+  wxRect paintRect = getPaintRect();
+  if (paintRect.GetRight() >= m_imageWidth)
+    paintRect.width = m_imageWidth - paintRect.x;
+  if (paintRect.GetBottom() >= m_imageHeight)
+    paintRect.height = m_imageHeight - paintRect.y;
+  wxRect bufferRect(m_bufferX, m_bufferY,
+	m_buffer->GetWidth(), m_buffer->GetHeight());
+  if (m_repaint ||
+      paintRect.x < bufferRect.x ||
+      paintRect.y < bufferRect.y ||
+      paintRect.GetRight() > bufferRect.GetRight() ||
+      paintRect.GetBottom() > bufferRect.GetBottom())
+  {
+    Paint(); // update buffer
+    m_repaint = false;
+    //wxLogMessage("Repaint: %d,%d - %d,%d -> %d,%d - %d,%d",
+    // paintRect.x, paintRect.y, paintRect.width, paintRect.height,
+    // bufferRect.x, bufferRect.y, bufferRect.width, bufferRect.height);
+  }
+  wxPaintBox::OnPaint(event);
+}
+
+void wxImageBox::OnResize(wxSizeEvent &event)
+{
+  UpdatePaintBox();
+}
+
+void wxImageBox::OnMouseRightButton(wxMouseEvent &event)
+{
+  if (event.RightUp() && m_pmenu)
+	PopupMenu(m_pmenu, event.GetPosition());
+}
+
+////////////////////////////////////////////////////////////
+///////////////////// wxPaintBox ///////////////////////////
+////////////////////////////////////////////////////////////
+
+BEGIN_EVENT_TABLE(wxPaintBox, wxScrolledWindow)
+  EVT_PAINT(wxPaintBox::OnPaint)
+  EVT_ERASE_BACKGROUND(wxPaintBox::OnEraseBackground)
+END_EVENT_TABLE()
+
+wxPaintBox::wxPaintBox(wxWindow *parent, wxWindowID id):
+    wxScrolledWindow(parent, id)
+{
+  SetScrollRate(1,1);
+  m_buffer = new wxBitmap;
+  m_bufferX = m_bufferY = 0;
+  m_imageWidth = m_imageHeight = 0;
+  SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
+}
+
+void wxPaintBox::OnPaint(wxPaintEvent& WXUNUSED(event))
+{
+  SetVirtualSize(m_imageWidth, m_imageHeight);
+  
+  wxPaintDC dc(this);  
+  PrepareDC(dc);
+  //dc.BeginDrawing();
+  dc.DrawBitmap(*m_buffer, m_bufferX, m_bufferY);
+  //background
+  dc.SetPen(wxPen(*wxBLACK,0,wxTRANSPARENT));
+  dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID));
+  int w = wxMax(GetClientSize().GetWidth(), m_imageWidth);
+  int h = wxMax(GetClientSize().GetHeight(), m_imageHeight);
+  dc.DrawRectangle(m_imageWidth, 0, w-m_imageWidth, h+50);
+  dc.DrawRectangle(0, m_imageHeight, w, h-m_imageHeight+50);
+  //dc.EndDrawing();
+}
+
+void wxPaintBox::OnEraseBackground(wxEraseEvent &event)
+{
+}
+
+////////////////////////////////////////////////////////////
+////////////////// Help functions //////////////////////////
+////////////////////////////////////////////////////////////
+
+wxRect ScaleRect(wxRect rect, double scale)
+{
+  wxRect res;
+  res.x = (int) (rect.x*scale);  
+  res.y = (int) (rect.y*scale);
+  res.width = (int) (rect.width*scale);
+  res.height = (int) (rect.height*scale);
+  return res;
+}
+


Property changes on: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.h	                        (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.h	2007-07-15 23:57:42 UTC (rev 28116)
@@ -0,0 +1,104 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        ImageBox.h
+// Purpose:     wxImageBox class
+// Author:      Alex Thuering
+// Created:		8.10.2003
+// RCS-ID:      $Id: ImageBox.h,v 1.4 2003/11/06 12:46:59 ntalex Exp $
+// Copyright:   (c) Alex Thuering
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef WXVILLALIB_IMAGEBOX_H
+#define WXVILLALIB_IMAGEBOX_H
+
+#include <wx/wx.h>
+#include <wx/image.h>
+#include <wx/filename.h>
+
+/** The widget to display a image buffer. */
+class wxPaintBox: public wxScrolledWindow
+{
+  public:
+    wxPaintBox(wxWindow *parent, wxWindowID id = -1);
+    ~wxPaintBox() {}
+    wxBitmap& GetBuffer() { return *m_buffer; }
+    virtual void Update() {}
+
+  protected:
+    wxBitmap *m_buffer;
+    int m_bufferX, m_bufferY;
+    int m_imageWidth, m_imageHeight;
+    virtual void OnPaint(wxPaintEvent &event);
+    void OnEraseBackground(wxEraseEvent &event);
+    DECLARE_EVENT_TABLE()
+};
+
+const int scFIT_TO_PAGE = -1;
+const int scFIT_TO_WIDTH = -2;
+const int scFIT_TO_HEIGHT = -3;
+
+/** The widget to display a image with the zoom function. */
+class wxImageBox: public wxPaintBox
+{
+  public:
+	/** Constructs a image box. */
+    wxImageBox(wxWindow *parent, wxWindowID id = -1);
+	/** Loads an image from a file. */
+	bool LoadFile(wxString fname);
+	/** Creates a empty image. */
+    virtual void Clear();
+	/** Returns true if image is not empty. */
+    virtual bool IsEmpty();
+	
+	/** Causes a event to be generated to repaint the image box. */
+	virtual void Update();
+	/** Repaints the image box.  */
+	virtual void UpdatePaintBox();
+	
+    /** Adjusts a zoom factor/level.
+      * Zoom level can be:\n
+      *  scFIT_TO_PAGE	 - to fit a image to the image box\n
+      *  scFIT_TO_WIDTH  - to fit a image to the width of image box\n
+      *  scFIT_TO_HEIGHT - to fit a image to the height of image box\n
+     */
+    void SetScale(double scale = scFIT_TO_PAGE);
+    /** Returns the current zoom factor/level. */
+    float GetScale() { return m_scaleV; }
+    /** Returns the current zoom factor. */
+    float GetScaleValue() { return m_scale; }
+    /** Returns the image. */
+    wxImage& GetImage() { return m_image; }
+	
+	/** Sets the pop up menu. */
+	void SetPopupMenu(wxMenu* menu) { m_pmenu = menu; }
+	/** Returns the pop up menu if it was set, or null otherwise. */
+	wxMenu* GetPopupMenu() { return m_pmenu; }
+
+  protected:
+    wxImage m_image;
+    double m_scale;
+    double m_scaleV;
+	bool m_repaint;
+	wxMenu* m_pmenu;
+    bool UpdateScaleValue();
+    wxRect getPaintRect();
+    virtual void Paint();
+	virtual void PaintImg(wxImage& img);
+    void OnPaint(wxPaintEvent &event);
+    void OnResize(wxSizeEvent &event);
+	virtual void OnMouseRightButton(wxMouseEvent &event);
+    DECLARE_EVENT_TABLE()
+};
+
+wxRect ScaleRect(wxRect rect, double scale);
+
+BEGIN_DECLARE_EVENT_TYPES()
+  DECLARE_LOCAL_EVENT_TYPE(EVT_COMMAND_IMAGEBOX_IMAGE_CHANGED, 3300)
+END_DECLARE_EVENT_TYPES()
+
+#define EVT_IMAGEBOX_IMAGE_CHANGED(id, fn)\
+ DECLARE_EVENT_TABLE_ENTRY(EVT_COMMAND_IMAGEBOX_IMAGE_CHANGED, id,\
+ wxID_ANY,\
+ (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)& fn, NULL),
+
+#endif // WXVILLALIB_IMAGEBOX_H


Property changes on: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageBox.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.cpp	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.cpp	2007-07-15 23:57:42 UTC (rev 28116)
@@ -7,7 +7,8 @@
 #include "PluginUtil.h"
 
 #include "GUIInterfaces.h"
-#include "BitmapPanel.h"
+//#include "BitmapPanel.h"
+#include "ImageBox.h"
 
 #include <iostream>
 
@@ -55,11 +56,25 @@
 
 	wxBoxSizer *panelsizer = new wxBoxSizer( wxVERTICAL );
 
-	wxPanel *bmpPanel = new BitmapPanel(panel, *_bitmap);
-	panelsizer->Add(bmpPanel,	1, wxALL|wxEXPAND, 0);
-	wxButton *dumpButton = new wxButton(panel, wxID_ANY, wxT("Dump Image"), wxPoint(167,450), wxSize(75,25), 0, wxDefaultValidator, wxT("dumpButton"));
-	panelsizer->Add(dumpButton,	0, wxALL, 0);
+	//wxPanel *bmpPanel = new BitmapPanel(panel, *_bitmap);
+	_bmpPanel = new wxImageBox(panel);
+	_bmpPanel->GetImage() = _bitmap->ConvertToImage();
+	panelsizer->Add(_bmpPanel,	1, wxALL|wxEXPAND, 0);
 
+	wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
+
+	wxButton *dumpButton = new wxButton(panel, wxID_ANY, wxT("Dump Image"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("dumpButton"));
+	buttonsizer->Add(dumpButton,	0, wxALL, 0);
+	wxButton *autoScaleButton = new wxButton(panel, wxID_ANY, wxT("Autoscale"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("dumpButton"));
+	buttonsizer->Add(autoScaleButton,	0, wxALL, 0);
+	wxButton *origScaleButton = new wxButton(panel, wxID_ANY, wxT("100%"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, wxT("dumpButton"));
+	buttonsizer->Add(origScaleButton,	0, wxALL, 0);
+	wxButton *scaleUpButton = new wxButton(panel, wxID_ANY, wxT("+"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, wxT("dumpButton"));
+	buttonsizer->Add(scaleUpButton,	0, wxALL, 0);
+	wxButton *scaleDownButton = new wxButton(panel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, wxT("dumpButton"));
+	buttonsizer->Add(scaleDownButton, 0, wxALL, 0);
+
+	panelsizer->Add(buttonsizer, 0, wxALL, 0);
 	panel->SetAutoLayout(true);
 	panel->SetSizer(panelsizer);	
 
@@ -67,6 +82,14 @@
 
 	dumpButton->Connect(dumpButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
 		wxCommandEventHandler(DumpImageEvtHandler::dumpButtonClick), NULL, &_evtHelper);
+	autoScaleButton->Connect(autoScaleButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
+		wxCommandEventHandler(DumpImageEvtHandler::autoScaleButtonClick), NULL, &_evtHelper);
+	origScaleButton->Connect(origScaleButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
+		wxCommandEventHandler(DumpImageEvtHandler::origScaleButtonClick), NULL, &_evtHelper);
+	scaleUpButton->Connect(scaleUpButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
+		wxCommandEventHandler(DumpImageEvtHandler::scaleUpButtonClick), NULL, &_evtHelper);
+	scaleDownButton->Connect(scaleDownButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
+		wxCommandEventHandler(DumpImageEvtHandler::scaleDownButtonClick), NULL, &_evtHelper);
 }
 
 void ImagePresenter::panelDeactivate() {
@@ -101,6 +124,22 @@
 	_that->dumpImage();
 }
 
+void DumpImageEvtHandler::autoScaleButtonClick(wxCommandEvent& event) {
+	_that->_bmpPanel->SetScale();
+}
+
+void DumpImageEvtHandler::origScaleButtonClick(wxCommandEvent& event) {
+	_that->_bmpPanel->SetScale(1);
+}
+
+void DumpImageEvtHandler::scaleUpButtonClick(wxCommandEvent& event) {
+	_that->_bmpPanel->SetScale(_that->_bmpPanel->GetScaleValue() * 1.5);
+}
+
+void DumpImageEvtHandler::scaleDownButtonClick(wxCommandEvent& event) {
+	_that->_bmpPanel->SetScale(_that->_bmpPanel->GetScaleValue() * 0.66);
+}
+
 void ImagePresenter::dumpImage() {
 	//infoout << wxT("FileInfoPresenter::dumpFile(): ") << std::endl;
 

Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.h	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImagePresenter.h	2007-07-15 23:57:42 UTC (rev 28116)
@@ -9,6 +9,8 @@
 #include "PanelProvider.h"
 #include "GUIInterfaces.h"
 
+class wxImageBox;
+
 namespace Browser {
 
 using namespace Core;
@@ -32,6 +34,10 @@
 	DumpImageEvtHandler(ImagePresenter* that)
 		: _that(that) {}
 	void dumpButtonClick(wxCommandEvent& event);
+	void autoScaleButtonClick(wxCommandEvent& event);
+	void origScaleButtonClick(wxCommandEvent& event);
+	void scaleUpButtonClick(wxCommandEvent& event);
+	void scaleDownButtonClick(wxCommandEvent& event);
 };
 
 /////////////////////////////////////////////////////////////////////////////
@@ -45,8 +51,10 @@
 	Pin<IPanelReciever>* _panelRecieverPin;
 
 	wxBitmap* _bitmap;
+	wxImageBox* _bmpPanel;
 
 	DumpImageEvtHandler _evtHelper;
+	friend struct DumpImageEvtHandler;
 
 public:
 	ASSIGN_DESC(0,wxT("CoreObjects"), 1)

Added: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.cpp	                        (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.cpp	2007-07-15 23:57:42 UTC (rev 28116)
@@ -0,0 +1,214 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        ImageProc.cpp
+// Purpose:     Image processing functions.
+// Author:      Alex Thuering
+// Created:		18.06.2003
+// RCS-ID:      $Id: ImageProc.cpp,v 1.4 2005/01/07 06:59:18 ntalex Exp $
+// Copyright:   (c) Alex Thuering
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#include "basic_stdafx.h"
+
+#include "ImageProc.h"
+#include <math.h>
+
+//////////////////////////////////////////////////////////////////////////////
+/////////////////////////////// Adjust ///////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+typedef void wxAdjustColourFunc(
+ unsigned char& r, unsigned char& g, unsigned char& b, void* param);
+
+void wxAdjustColours(wxImage& img, wxRect rect, void* arg, wxAdjustColourFunc* func)
+{
+  int w = img.GetWidth();
+  int h = img.GetHeight();
+  
+  int k = wxMax(rect.GetLeft(),0);
+  rect.width += rect.x-k; rect.x = k; //rect.SetLeft(k);
+  k = wxMax(rect.GetTop(),0);
+  rect.height += rect.y-k; rect.y = k; //rect.SetTop(k);
+  rect.SetRight(wxMin(rect.GetRight(),w-1));
+  rect.SetBottom(wxMin(rect.GetBottom(),h-1));
+  
+  unsigned char* data = img.GetData() + rect.GetTop()*w*3;
+  if (img.HasMask())
+  {
+	unsigned char maskRed   = img.GetMaskRed();
+	unsigned char maskGreen = img.GetMaskGreen();
+	unsigned char maskBlue  = img.GetMaskBlue();
+	
+	for (int y=rect.GetTop(); y<=rect.GetBottom(); y++)
+	{
+	  data += rect.GetLeft()*3;
+	  for (int x=rect.GetLeft(); x<=rect.GetRight(); x++)
+	  {
+		if (maskRed != *data || maskGreen != *(data+1) || maskBlue != *(data+2))
+		  (*func)(*data, *(data+1), *(data+2), arg);
+		data += 3;
+	  }
+	  data += (w-rect.GetRight()-1)*3;
+	}
+  }
+  else
+  {
+	for (int y=rect.GetTop(); y<=rect.GetBottom(); y++)
+	{
+	  data += rect.GetLeft()*3;
+	  for (int x=rect.GetLeft(); x<=rect.GetRight(); x++)
+	  {
+		(*func)(*data, *(data+1), *(data+2), arg);
+		data += 3;
+	  }
+	  data += (w-rect.GetRight()-1)*3;
+	}
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///////////////////////////// Brightness /////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+void wxAdjustBrightness(wxImage& img, char n)
+{
+  wxAdjustBrightness(img, wxRect(0,0,img.GetWidth(),img.GetHeight()), n);
+}
+
+void wxAdjustBrightnessFunc(unsigned char& r, unsigned char& g, unsigned char& b, void* arg)
+{
+  wxAdjustBrightness(r, g, b, *((char*) arg));
+}
+
+void wxAdjustBrightness(wxImage& img, wxRect rect, char n)
+{
+  wxAdjustColours(img, rect, &n, &wxAdjustBrightnessFunc);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+////////////////////////////// To colour /////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+void wxAdjustToColour(wxImage& img, wxColour colour)
+{
+  wxAdjustToColour(img, wxRect(0,0,img.GetWidth(),img.GetHeight()), colour);
+}
+
+void wxAdjustToColourFunc(unsigned char& r, unsigned char& g, unsigned char& b, void* arg)
+{
+  wxAdjustToColour(r, g, b, *((wxColour*) arg));
+}
+
+void wxAdjustToColour(wxImage& img, wxRect rect, wxColour colour)
+{
+  wxAdjustColours(img, rect, &colour, &wxAdjustToColourFunc);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///////////////////////////// Contrast /////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+wxArrayInt contrastTable;
+
+void InitializateContrastTable()
+{
+  if (contrastTable.IsEmpty())
+    for (int i=0; i<256; i++)
+    {
+      double brightness = double(i)/255;
+      contrastTable.Add(int(
+        1000*((sin(3.1415*(brightness-0.5))+1)/2-brightness)));
+    }
+}
+
+// Adjust contrast: dark color become darker, light color become lighter.
+inline void wxAdjustContrast(
+ unsigned char& r, unsigned char& g, unsigned char& b, char n)
+{
+  int brightness = wxGetBrightness(r,g,b);
+  wxAdjustBrightness(r,g,b, contrastTable[brightness]*n/100);
+}
+
+void wxAdjustContrast(wxImage& img, char n)
+{
+  wxAdjustContrast(img, wxRect(0,0,img.GetWidth(),img.GetHeight()), n);
+}
+
+void wxAdjustContrast(wxImage& img, wxRect rect, char n)
+{
+  InitializateContrastTable();
+  unsigned char* data = img.GetData() + rect.GetTop()*img.GetWidth()*3;
+  for (int y=rect.GetTop(); y<=rect.GetBottom(); y++)
+  {
+    data += rect.GetLeft()*3;
+    for (int x=rect.GetLeft(); x<=rect.GetRight(); x++)
+    {
+      wxAdjustContrast(*data, *(data+1), *(data+2), n);
+      data += 3;
+    }
+    data += (img.GetWidth()-rect.GetRight()-1)*3;
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///////////////////////// Convert functions //////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+// Convert RGB to HSL
+void RGB2HSL(const wxColour colour,
+  double& hue, double& saturation, double& luminosity)
+{
+  double r = (double) colour.Red()/255;
+  double g = (double) colour.Green()/255;
+  double b = (double) colour.Blue()/255;
+  double max = wxMax(r, wxMax(g,b));
+  double min = wxMin(r, wxMin(g,b));
+  hue = 0;
+  saturation = 0;
+  luminosity = (min+max)/2;
+  double delta=max-min;
+  if (delta == 0)
+    return;
+  saturation = delta/((luminosity <= 0.5) ? (min+max) : (2-max-min));
+  if (r == max)
+    hue = (g == min ? 5+(max-b)/delta : 1-(max-g)/delta);
+  else if (g == max)
+    hue = (b == min ? 1+(max-r)/delta : 3-(max-b)/delta);
+  else
+    hue = (r == min ? 3+(max-g)/delta : 5-(max-r)/delta);
+  hue /= 6;
+}
+
+// Convert HSL to RGB
+wxColour HSL2RGB(double hue, double saturation, double luminosity)
+{
+  wxColour colour;
+  
+  if (saturation == 0)
+  {
+    int c = (int) (255*luminosity+0.5);
+    colour.Set(c, c, c);
+    return colour;
+  }
+  
+  double v=(luminosity <= 0.5) ? (luminosity*(1+saturation)) :
+    (luminosity+saturation-luminosity*saturation);
+  double y=2*luminosity-v;
+  double x=y+(v-y)*(6*hue-floor(6*hue));
+  double z=v-(v-y)*(6*hue-floor(6*hue));
+  
+  double r,g,b;
+  switch ((int) (6*hue))
+  {
+    case 0: r=v; g=x; b=y; break;
+    case 1: r=z; g=v; b=y; break;
+    case 2: r=y; g=v; b=x; break;
+    case 3: r=y; g=z; b=v; break;
+    case 4: r=x; g=y; b=v; break;
+    case 5: r=v; g=y; b=z; break;
+    default: r=v; g=x; b=y; break;
+  }
+  
+  colour.Set((int) (255*r+0.5), (int) (255*g+0.5), (int) (255*b+0.5));
+  return colour;
+}


Property changes on: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.h	                        (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.h	2007-07-15 23:57:42 UTC (rev 28116)
@@ -0,0 +1,54 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        ImageProc.h
+// Purpose:     Image processing functions.
+// Author:      Alex Thuering
+// Created:		18.06.2003
+// RCS-ID:      $Id: ImageProc.h,v 1.3 2005/01/07 06:59:18 ntalex Exp $
+// Copyright:   (c) Alex Thuering
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef WXVILLALIB_IMAGE_PROC_H
+#define IMAGE_PROC_H
+
+#include <wx/wx.h>
+#include <wx/image.h>
+
+/** Brightness */
+inline int wxGetBrightness(unsigned char r, unsigned char g, unsigned char b)
+{ return (wxMax(r, wxMax(g,b))+wxMin(r, wxMin(g,b)))/2; }
+
+inline unsigned char wxAdjustBrightness(unsigned char c, char n)
+{ return n<=0 ? c*(n+128)/128 : c + (255-c)*n/128; }
+
+inline void wxAdjustBrightness(
+ unsigned char& r, unsigned char& g, unsigned char& b, char n)
+{
+  r = wxAdjustBrightness(r,n);
+  g = wxAdjustBrightness(g,n);
+  b = wxAdjustBrightness(b,n);
+}
+
+void wxAdjustBrightness(wxImage& img, wxRect rect, char n);
+void wxAdjustBrightness(wxImage& img, char n);
+
+/** Adjust to colour */
+inline unsigned char wxAdjustToColour(unsigned char src, unsigned char c)
+{ return src*c/255; }
+
+inline void wxAdjustToColour(
+ unsigned char& r, unsigned char& g, unsigned char& b, const wxColour& c)
+{
+  r = wxAdjustToColour(r, c.Red());
+  g = wxAdjustToColour(g, c.Green());
+  b = wxAdjustToColour(b, c.Blue());
+}
+
+void wxAdjustToColour(wxImage& img, wxRect rect, wxColour c);
+void wxAdjustToColour(wxImage& img, wxColour c);
+
+/** Contrast */
+void wxAdjustContrast(wxImage& img, wxRect rect, char n);
+void wxAdjustContrast(wxImage& img, char n);
+
+#endif // WXVILLALIB_IMAGE_PROC_H


Property changes on: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/ImageProc.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/Makefile.am
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/Makefile.am	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/basic/Makefile.am	2007-07-15 23:57:42 UTC (rev 28116)
@@ -8,6 +8,10 @@
 	BasicParsers.h \
 	BitmapPanel.cpp \
 	BitmapPanel.h \
+	ImageBox.cpp \
+	ImageBox.h \
+	ImageProc.cpp \
+	ImageProc.h \
 	DirectoryPresenter.cpp \
 	DirectoryPresenter.h \
 	DiskFileProvider.cpp \

Modified: scummex/branches/gsoc2007-gameresbrowser/vc8/Browser.sln
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/vc8/Browser.sln	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/vc8/Browser.sln	2007-07-15 23:57:42 UTC (rev 28116)
@@ -11,22 +11,22 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "browserapp", "browserapp\browserapp.vcproj", "{17A7578C-6C1C-40C0-A91C-693A3223B70F}"
 	ProjectSection(ProjectDependencies) = postProject
 		{4795B9E0-B3AC-49E2-BCE6-D8C200B2FCC5} = {4795B9E0-B3AC-49E2-BCE6-D8C200B2FCC5}
+		{DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA} = {DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA}
+		{C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60} = {C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60}
 		{B42300E1-0BC0-45E7-878E-2CB1AEA9D520} = {B42300E1-0BC0-45E7-878E-2CB1AEA9D520}
-		{C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60} = {C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60}
-		{DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA} = {DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA}
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic_plugin", "basic_plugin\basic_plugin.vcproj", "{C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60}"
 	ProjectSection(ProjectDependencies) = postProject
+		{DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA} = {DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA}
 		{B42300E1-0BC0-45E7-878E-2CB1AEA9D520} = {B42300E1-0BC0-45E7-878E-2CB1AEA9D520}
-		{DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA} = {DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA}
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scumm_plugin", "scumm_plugin\scumm_plugin.vcproj", "{4795B9E0-B3AC-49E2-BCE6-D8C200B2FCC5}"
 	ProjectSection(ProjectDependencies) = postProject
+		{DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA} = {DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA}
+		{C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60} = {C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60}
 		{B42300E1-0BC0-45E7-878E-2CB1AEA9D520} = {B42300E1-0BC0-45E7-878E-2CB1AEA9D520}
-		{C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60} = {C84F34F4-6FFB-4C4F-98E6-085CD5AF9F60}
-		{DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA} = {DCE4A2F5-35FC-4D18-95E6-0D04BB907CBA}
 	EndProjectSection
 EndProject
 Global

Modified: scummex/branches/gsoc2007-gameresbrowser/vc8/basic_plugin/basic_plugin.vcproj
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/vc8/basic_plugin/basic_plugin.vcproj	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/vc8/basic_plugin/basic_plugin.vcproj	2007-07-15 23:57:42 UTC (rev 28116)
@@ -316,10 +316,18 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\plugins\basic\ImageBox.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\plugins\basic\ImagePresenter.cpp"
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\plugins\basic\ImageProc.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\plugins\basic\TextPresenter.cpp"
 				>
 			</File>
@@ -370,10 +378,18 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\plugins\basic\ImageBox.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\plugins\basic\ImagePresenter.h"
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\plugins\basic\ImageProc.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\plugins\basic\TextPresenter.h"
 				>
 			</File>

Modified: scummex/branches/gsoc2007-gameresbrowser/vc8/browserapp/browserapp.vcproj
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/vc8/browserapp/browserapp.vcproj	2007-07-15 22:08:40 UTC (rev 28115)
+++ scummex/branches/gsoc2007-gameresbrowser/vc8/browserapp/browserapp.vcproj	2007-07-15 23:57:42 UTC (rev 28116)
@@ -199,7 +199,7 @@
 				AdditionalOptions="/Ob0"
 				Optimization="0"
 				InlineFunctionExpansion="0"
-				AdditionalIncludeDirectories="../../src/core;../../src/browser;../../src/plugins"
+				AdditionalIncludeDirectories="../../src/core;../../src/browser;../../src/plugins;C:\Zbys\gsoc\Browser\MadEdit"
 				PreprocessorDefinitions="WIN32;_DEBUG;_UNICODE;_WINDOWS;WXUSINGDLL;wxUSE_NO_MANIFEST=1"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list