First checkin. It works enough.
authorviric@mandarina
Sat, 01 Nov 2008 20:57:17 +0100
changeset 0 7e720dcafcaf
child 1 506e0fc65ba3
First checkin. It works enough.
CMakeLists.txt
CropArea.hpp
MainWindow.cpp
MainWindow.hpp
main.cpp
wxPictureWindow.cpp
wxPictureWindow.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMakeLists.txt	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,14 @@
+PROJECT(wxcrop)
+
+FIND_PACKAGE(wxWidgets)
+
+IF (wxWidgets_FOUND)
+    INCLUDE(${wxWidgets_USE_FILE})
+ENDIF (wxWidgets_FOUND)
+
+
+ADD_EXECUTABLE(wxcrop
+    main.cpp
+    MainWindow.cpp
+    wxPictureWindow.cpp)
+TARGET_LINK_LIBRARIES(wxcrop ${wxWidgets_LIBRARIES})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CropArea.hpp	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,12 @@
+#ifndef _HEADER_CROPAREA_HPP_
+#define _HEADER_CROPAREA_HPP_
+
+struct CropArea
+{
+    long int width;
+    long int height;
+    long int x;
+    long int y;
+};
+
+#endif /* _HEADER_CROPAREA_HPP_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MainWindow.cpp	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,12 @@
+#include <wx/wx.h>
+#include <wx/image.h>
+#include "wxPictureWindow.hpp"
+#include "MainWindow.hpp"
+
+MainWindow::MainWindow(const wxImage &img, const CropArea area, const wxSize size)
+    :wxFrame(0, wxID_ANY, _("wxDjvuMaker"), wxDefaultPosition, size)
+{
+    wxBoxSizer *s = new wxBoxSizer(wxVERTICAL);
+    wxPictureWindow *picture = new wxPictureWindow(img, area, this);
+    s->Add(picture);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MainWindow.hpp	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,13 @@
+#ifndef _HEADER_MAINWINDOW_HPP_
+#define _HEADER_MAINWINDOW_HPP_
+
+#include <wx/wx.h>
+#include "CropArea.hpp"
+
+class MainWindow : public wxFrame
+{
+public:
+    MainWindow(const wxImage &img, CropArea area, wxSize size);
+};
+
+#endif /* _HEADER_MAINWINDOW_HPP_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,54 @@
+#include <wx/wx.h>
+#include <wx/log.h>
+#include <wx/image.h>
+#include <wx/string.h>
+#include <wx/init.h>
+
+#include "MainWindow.hpp"
+
+class MyApp : public wxApp
+{
+    public:
+        virtual bool OnInit();
+};
+
+IMPLEMENT_APP(MyApp)
+
+bool MyApp::OnInit()
+{
+    if (argc < 2)
+        return false;
+
+    ::wxInitAllImageHandlers();
+
+    wxString filename(argv[1]);
+
+    wxLogVerbose(_T("Opening file %s."), filename.c_str());
+    wxImage img(filename);
+    if (!img.IsOk())
+        return false;
+
+    CropArea area;
+    if (argc < 6)
+    {
+        area.x = 0;
+        area.y = 0;
+        area.width = 0;
+        area.height = 0;
+    }
+    else
+    {
+        wxString(argv[2]).ToLong(&area.x);
+        wxString(argv[3]).ToLong(&area.y);
+        wxString(argv[4]).ToLong(&area.width);
+        wxString(argv[5]).ToLong(&area.height);
+    }
+
+    img.Rescale(img.GetWidth()/3, img.GetHeight()/3);
+
+    wxSize size(img.GetWidth(), img.GetHeight());
+    MainWindow *mw = new MainWindow(img, area, size);
+    mw->Show();
+
+    return true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wxPictureWindow.cpp	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,64 @@
+#include <wx/scrolwin.h>
+#include <wx/image.h>
+#include <wx/bitmap.h>
+#include <wx/dc.h>
+#include <iostream>
+#include "wxPictureWindow.hpp"
+
+const int factor = 3;
+
+BEGIN_EVENT_TABLE(wxPictureWindow, wxScrolledWindow)
+  EVT_MOUSE_EVENTS (wxPictureWindow::OnMouse)
+END_EVENT_TABLE()
+
+wxPictureWindow::wxPictureWindow(const wxImage &img, const CropArea area, wxWindow *parent)
+    :wxScrolledWindow(parent, wxID_ANY),
+    _bmp(wxBitmap(img)),
+    _area(area)
+{
+    SetVirtualSize(_bmp.GetWidth(), _bmp.GetHeight());
+    SetScrollRate(10, 10);
+    _area.x /= factor;
+    _area.y /= factor;
+    _area.width /= factor;
+    _area.height /= factor;
+}
+
+void wxPictureWindow::OnDraw(wxDC &dc)
+{
+    dc.DrawBitmap(_bmp, 0, 0, false);
+
+    wxRect rect(_area.x, _area.y, _area.width, _area.height);
+    dc.SetPen(*wxGREEN_PEN);
+    dc.SetBrush(*wxTRANSPARENT_BRUSH);
+    dc.DrawRectangle(rect);
+}
+
+void wxPictureWindow::OnMouse(wxMouseEvent &ev)
+{
+    wxClientDC dc(this);
+    DoPrepareDC(dc);
+
+    if (ev.LeftDown())
+    {
+        _area.x = ev.GetLogicalPosition(dc).x;
+        _area.y = ev.GetLogicalPosition(dc).y;
+        _area.width = 0;
+        _area.height = 0;
+    }
+    else if (ev.LeftIsDown())
+    {
+        _area.width = ev.GetLogicalPosition(dc).x - _area.x;
+        _area.height = ev.GetLogicalPosition(dc).y - _area.y;
+    }
+
+    Refresh();
+}
+
+wxPictureWindow::~wxPictureWindow()
+{
+    std::cout << _area.x * factor << " ";
+    std::cout << _area.y * factor << " ";
+    std::cout << _area.width * factor << " ";
+    std::cout << _area.height * factor << std::endl;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wxPictureWindow.hpp	Sat Nov 01 20:57:17 2008 +0100
@@ -0,0 +1,20 @@
+#include <wx/scrolwin.h>
+#include <wx/dcclient.h>
+#include "CropArea.hpp"
+
+class wxPictureWindow : public wxScrolledWindow
+{
+    public:
+        wxPictureWindow(const wxImage &img, CropArea area, wxWindow *parent);
+        ~wxPictureWindow();
+    protected:
+        virtual void OnDraw(wxDC &dc);
+        void OnMouse(wxMouseEvent &ev);
+
+    private:
+        wxString _filename;
+        wxBitmap _bmp;
+        CropArea _area;
+
+    DECLARE_EVENT_TABLE()
+};