diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-25 16:24:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-25 16:24:36 +0100 |
| commit | b0f5d569ccf740d5524e06ff59a17638221dc9d7 (patch) | |
| tree | 9dd8c27f890244555b927e7e90256687c16409be /src/wx | |
| parent | 489e6a92b9aa940de64a886a1f9b5a420b50c7fc (diff) | |
Various hacks.
Diffstat (limited to 'src/wx')
| -rw-r--r-- | src/wx/film_editor.cc | 22 | ||||
| -rw-r--r-- | src/wx/film_editor.h | 2 | ||||
| -rw-r--r-- | src/wx/film_viewer.cc | 109 | ||||
| -rw-r--r-- | src/wx/film_viewer.h | 12 | ||||
| -rw-r--r-- | src/wx/wx_util.cc | 12 | ||||
| -rw-r--r-- | src/wx/wx_util.h | 2 |
6 files changed, 61 insertions, 98 deletions
diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 395b855da..42d6fcff5 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -96,7 +96,7 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent) vector<Format const *> fmt = Format::all (); for (vector<Format const *>::iterator i = fmt.begin(); i != fmt.end(); ++i) { - _format->Append (wxString ((*i)->name().c_str(), wxConvUTF8)); + _format->Append (std_to_wx ((*i)->name ())); } //XXX _frames_per_second.set_increments (1, 5); @@ -105,12 +105,12 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent) vector<DCPContentType const *> const ct = DCPContentType::all (); for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) { - _dcp_content_type->Append (wxString ((*i)->pretty_name().c_str(), wxConvUTF8)); + _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ())); } vector<Scaler const *> const sc = Scaler::all (); for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) { - _scaler->Append (wxString ((*i)->name().c_str(), wxConvUTF8)); + _scaler->Append (std_to_wx ((*i)->name())); } //XXX _original_size.set_alignment (0, 0.5); @@ -340,11 +340,11 @@ FilmEditor::film_changed (Film::Property p) { pair<string, string> p = Filter::ffmpeg_strings (_film->filters ()); string const b = p.first + " " + p.second; - _filters->SetLabel (wxString (b.c_str(), wxConvUTF8)); + _filters->SetLabel (std_to_wx (b)); break; } case Film::NAME: - _name->SetValue (wxString (_film->name().c_str(), wxConvUTF8)); + _name->SetValue (std_to_wx (_film->name ())); break; case Film::FRAMES_PER_SECOND: _frames_per_second->SetValue (_film->frames_per_second ()); @@ -355,7 +355,7 @@ FilmEditor::film_changed (Film::Property p) _audio->SetLabel (wxT ("")); } else { s << _film->audio_channels () << " channels, " << _film->audio_sample_rate() << "Hz"; - _audio->SetLabel (wxString (s.str().c_str(), wxConvUTF8)); + _audio->SetLabel (std_to_wx (s.str ())); } break; case Film::SIZE: @@ -363,7 +363,7 @@ FilmEditor::film_changed (Film::Property p) _original_size->SetLabel (wxT ("")); } else { s << _film->size().width << " x " << _film->size().height; - _original_size->SetLabel (wxString (s.str().c_str(), wxConvUTF8)); + _original_size->SetLabel (std_to_wx (s.str ())); } break; case Film::LENGTH: @@ -372,7 +372,7 @@ FilmEditor::film_changed (Film::Property p) } else if (_film->length() > 0) { s << _film->length() << " frames"; } - _length->SetLabel (wxString (s.str().c_str(), wxConvUTF8)); + _length->SetLabel (std_to_wx (s.str ())); break; case Film::DCP_CONTENT_TYPE: _dcp_content_type->SetSelection (DCPContentType::as_index (_film->dcp_content_type ())); @@ -385,7 +385,7 @@ FilmEditor::film_changed (Film::Property p) } else { stringstream s; s << "First " << _film->dcp_frames() << " frames"; - _dcp_range->SetLabel (wxString (s.str().c_str(), wxConvUTF8)); + _dcp_range->SetLabel (std_to_wx (s.str ())); } break; case Film::DCP_TRIM_ACTION: @@ -449,9 +449,9 @@ FilmEditor::set_film (Film* f) } if (_film) { -// FileChanged (_film->directory ()); + FileChanged (_film->directory ()); } else { -// FileChanged (""); + FileChanged (""); } film_changed (Film::NAME); diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index c0e4ec3b4..23fd3352a 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -39,7 +39,7 @@ public: void set_film (Film *); void setup_visibility (); -//XXX sigc::signal1<void, std::string> FileChanged; + sigc::signal1<void, std::string> FileChanged; private: /* Handle changes to the view */ diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index c9a72f225..6f5625293 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -43,6 +43,10 @@ public: , _film (film) , _image (0) , _bitmap (0) + , _left_crop (0) + , _right_crop (0) + , _top_crop (0) + , _bottom_crop (0) { } @@ -72,15 +76,21 @@ public: float const target = _film->format()->ratio_as_float (); - delete _bitmap; + _cropped_image = _image->GetSubImage ( + wxRect (_left_crop, _top_crop, _image->GetWidth() - (_left_crop + _right_crop), _image->GetHeight() - (_top_crop + _bottom_crop)) + ); + if ((float (vw) / vh) > target) { /* view is longer (horizontally) than the ratio; fit height */ - _bitmap = new wxBitmap (_image->Scale (vh * target, vh)); + _cropped_image.Rescale (vh * target, vh); } else { /* view is shorter (horizontally) than the ratio; fit width */ - _bitmap = new wxBitmap (_image->Scale (vw, vw / target)); + _cropped_image.Rescale (vw, vw / target); } + delete _bitmap; + _bitmap = new wxBitmap (_cropped_image); + Refresh (); } @@ -91,6 +101,15 @@ public: resize (); } + void set_crop (int l, int r, int t, int b) + { + _left_crop = l; + _right_crop = r; + _top_crop = t; + _bottom_crop = b; + resize (); + } + void clear () { delete _bitmap; @@ -104,7 +123,12 @@ public: private: Film* _film; wxImage* _image; + wxImage _cropped_image; wxBitmap* _bitmap; + int _left_crop; + int _right_crop; + int _top_crop; + int _bottom_crop; }; BEGIN_EVENT_TABLE (ThumbPanel, wxPanel) @@ -122,7 +146,7 @@ FilmViewer::FilmViewer (Film* f, wxWindow* p) _thumb_panel = new ThumbPanel (this, f); _sizer->Add (_thumb_panel, 1, wxEXPAND); - int const max = f ? f->num_thumbs() : 0; + int const max = f ? f->num_thumbs() - 1 : 0; _slider = new wxSlider (this, wxID_ANY, 0, 0, max); _sizer->Add (_slider, 0, wxEXPAND | wxLEFT | wxRIGHT); load_thumbnail (0); @@ -139,11 +163,6 @@ FilmViewer::load_thumbnail (int n) return; } - int const left = _film->left_crop (); - int const right = _film->right_crop (); - int const top = _film->top_crop (); - int const bottom = _film->bottom_crop (); - _thumb_panel->load (_film->thumb_file(n)); } @@ -159,38 +178,20 @@ FilmViewer::slider_changed (wxCommandEvent &) reload_current_thumbnail (); } -string -FilmViewer::format_position_slider_value (double v) const -{ -#if 0 - stringstream s; - - if (_film && int (v) < _film->num_thumbs ()) { - int const f = _film->thumb_frame (int (v)); - s << f << " " << seconds_to_hms (f / _film->frames_per_second ()); - } else { - s << "-"; - } - - return s.str (); -#endif -} - void FilmViewer::film_changed (Film::Property p) { -#if 0 if (p == Film::LEFT_CROP || p == Film::RIGHT_CROP || p == Film::TOP_CROP || p == Film::BOTTOM_CROP) { - reload_current_thumbnail (); + _thumb_panel->set_crop (_film->left_crop(), _film->right_crop(), _film->top_crop(), _film->bottom_crop ()); } else if (p == Film::THUMBS) { if (_film && _film->num_thumbs() > 1) { - _position_slider.set_range (0, _film->num_thumbs () - 1); + _slider->SetRange (0, _film->num_thumbs () - 1); } else { - _image.clear (); - _position_slider.set_range (0, 1); + _thumb_panel->clear (); + _slider->SetRange (0, 1); } - _position_slider.set_value (0); + _slider->SetValue (0); reload_current_thumbnail (); } else if (p == Film::FORMAT) { reload_current_thumbnail (); @@ -199,7 +200,6 @@ FilmViewer::film_changed (Film::Property p) _film->examine_content (); update_thumbs (); } -#endif } void @@ -212,50 +212,14 @@ FilmViewer::set_film (Film* f) return; } -// _film->Changed.connect (sigc::mem_fun (*this, &FilmViewer::film_changed)); + _film->Changed.connect (sigc::mem_fun (*this, &FilmViewer::film_changed)); film_changed (Film::THUMBS); } -pair<int, int> -FilmViewer::scaled_pixbuf_size () const -{ -#if 0 - if (_film == 0) { - return make_pair (0, 0); - } - - int const cw = _film->size().width - _film->left_crop() - _film->right_crop(); - int const ch = _film->size().height - _film->top_crop() - _film->bottom_crop(); - - float ratio = 1; - if (_film->format()) { - ratio = _film->format()->ratio_as_float() * ch / cw; - } - - Gtk::Allocation const a = _scroller.get_allocation (); - float const zoom = min (float (a.get_width()) / (cw * ratio), float (a.get_height()) / cw); - return make_pair (cw * zoom * ratio, ch * zoom); -#endif -} - -void -FilmViewer::update_scaled_pixbuf () -{ -#if 0 - pair<int, int> const s = scaled_pixbuf_size (); - - if (s.first > 0 && s.second > 0 && _cropped_pixbuf) { - _scaled_pixbuf = _cropped_pixbuf->scale_simple (s.first, s.second, Gdk::INTERP_HYPER); - _image.set (_scaled_pixbuf); - } -#endif -} - void FilmViewer::update_thumbs () { -#if 0 if (!_film) { return; } @@ -272,18 +236,15 @@ FilmViewer::update_thumbs () shared_ptr<Job> j (new ThumbsJob (s, o, _film->log ())); j->Finished.connect (sigc::mem_fun (_film, &Film::update_thumbs_post_gui)); JobManager::instance()->add (j); -#endif } void FilmViewer::setup_visibility () { -#if 0 if (!_film) { return; } ContentType const c = _film->content_type (); - _position_slider.property_visible() = (c == VIDEO); -#endif + _slider->Show (c == VIDEO); } diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index f1213e023..8a1a0c908 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -40,24 +40,12 @@ public: private: void slider_changed (wxCommandEvent &); void update_thumbs (); - std::string format_position_slider_value (double) const; void load_thumbnail (int); void film_changed (Film::Property); void reload_current_thumbnail (); - void update_scaled_pixbuf (); - std::pair<int, int> scaled_pixbuf_size () const; -// void scroller_size_allocate (Gtk::Allocation); Film* _film; wxBoxSizer* _sizer; ThumbPanel* _thumb_panel; wxSlider* _slider; -// Gtk::VBox _vbox; -// Gtk::ScrolledWindow _scroller; -// Gtk::Image _image; -// Glib::RefPtr<Gdk::Pixbuf> _pixbuf; -// Glib::RefPtr<Gdk::Pixbuf> _cropped_pixbuf; -// Glib::RefPtr<Gdk::Pixbuf> _scaled_pixbuf; -// Gtk::HScale _position_slider; -// Gtk::Allocation _last_scroller_allocation; }; diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 409ab361c..bb268ea68 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -43,3 +43,15 @@ error_dialog (string m) d.run (); } #endif + +string +wx_to_std (wxString s) +{ + return string (s.mb_str ()); +} + +wxString +std_to_wx (string s) +{ + return wxString (s.c_str(), wxConvUTF8); +} diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h index 8a84b1323..6f83e3df0 100644 --- a/src/wx/wx_util.h +++ b/src/wx/wx_util.h @@ -26,3 +26,5 @@ extern void error_dialog (std::string); extern wxStaticText* add_label_to_sizer (wxSizer *, wxWindow *, std::list<wxControl*>&, std::string); +extern std::string wx_to_std (wxString); +extern wxString std_to_wx (std::string); |
