~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to bear-factory/animation-editor/src/bf/code/main_frame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    Bear Engine - Animation editor
3
3
 
4
 
    Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
    Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
    This program is free software; you can redistribute it and/or modify it
7
7
    under the terms of the GNU General Public License as published by the
30
30
 
31
31
#include "bf/animation_editor.hpp"
32
32
#include "bf/about_dialog.hpp"
 
33
#include "bf/frame_duration_dialog.hpp"
33
34
#include "bf/image_pool.hpp"
34
35
#include "bf/animation_file_xml_reader.hpp"
35
36
#include "bf/animation_file_xml_writer.hpp"
55
56
  create_toolbar();
56
57
  create_controls();
57
58
  Fit();
58
 
 
59
 
  //turn_animation_menu_entries(false);
60
59
} // main_frame::main_frame()
61
60
 
62
61
/*----------------------------------------------------------------------------*/
66
65
 */
67
66
void bf::main_frame::load_animation( const wxString& path )
68
67
{
69
 
  try
70
 
    {
71
 
      wxXmlDocument doc;
72
 
      animation_file_xml_reader reader;
73
 
 
74
 
      if ( !doc.Load(path) )
75
 
        throw std::ios_base::failure
76
 
          ( "Cannot load the XML file '" + wx_to_std_string(path) + "'" );
77
 
 
78
 
      animation anim = reader.load( doc.GetRoot() );
79
 
      m_animation_edit->set_value(anim);
80
 
      m_last_saved_animation = m_animation_edit->get_value();
81
 
      m_animation_file = path;
82
 
      make_title();
83
 
    }
84
 
  catch( std::exception& e )
85
 
    {
86
 
      wxMessageDialog msg
87
 
        ( this, std_to_wx_string( e.what() ),
88
 
          _("Error when loading the animation."), wxOK );
89
 
 
90
 
      msg.ShowModal();
91
 
    }
 
68
  wxLogNull no_log;
 
69
  wxXmlDocument doc;
 
70
  animation_file_xml_reader reader;
 
71
  animation anim;
 
72
 
 
73
  if ( doc.Load(path) )
 
74
    anim = reader.load( doc.GetRoot() );
 
75
 
 
76
  m_animation_edit->set_value(anim);
 
77
  m_last_saved_animation = m_animation_edit->get_value();
 
78
  m_animation_file = path;
 
79
  make_title();
92
80
} // main_frame::load_animation()
93
81
 
94
82
/*----------------------------------------------------------------------------*/
138
126
bool bf::main_frame::save_as()
139
127
{
140
128
  bool result = false;
141
 
  wxFileDialog dlg( this, _("Choose a file"), wxT(""), m_animation_file,
 
129
  wxFileDialog dlg( this, _("Choose a file"), wxEmptyString, m_animation_file,
142
130
                    _("Animation files (*.anim)|*.anim"),
143
131
                    wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
144
132
 
205
193
  wxMenuBar* menu_bar = new wxMenuBar();
206
194
 
207
195
  menu_bar->Append(create_animation_menu(), _("&Animation"));
 
196
  menu_bar->Append(create_edit_menu(), _("&Edit"));
208
197
  menu_bar->Append(create_help_menu(), _("&Help"));
209
198
 
210
199
  SetMenuBar(menu_bar);
218
207
{
219
208
  wxToolBar* bar = CreateToolBar();
220
209
 
221
 
  bar->AddTool( wxID_NEW, _("&New"), wxArtProvider::GetBitmap(wxART_NEW) );
222
 
  bar->AddTool
223
 
    ( wxID_OPEN, _("&Open"), wxArtProvider::GetBitmap(wxART_FILE_OPEN) );
224
 
  bar->AddTool
225
 
    ( wxID_SAVE, _("&Save"), wxArtProvider::GetBitmap(wxART_FILE_SAVE) );
 
210
  bar->AddTool
 
211
    ( wxID_NEW, _("&New"), wxArtProvider::GetBitmap(wxART_NEW), _("New") );
 
212
  bar->AddTool
 
213
    ( wxID_OPEN, _("&Open"), wxArtProvider::GetBitmap(wxART_FILE_OPEN),
 
214
      _("Open") );
 
215
  bar->AddTool
 
216
    ( wxID_SAVE, _("&Save"), wxArtProvider::GetBitmap(wxART_FILE_SAVE),
 
217
      _("Save") );
226
218
  bar->AddSeparator();
227
 
  bar->AddTool( ID_COMPILE, _("&Compile"), wxBitmap(compile_xpm) );
 
219
  bar->AddTool
 
220
    ( ID_COMPILE, _("&Compile"), wxBitmap(compile_xpm), _("Compile") );
228
221
 
229
222
  bar->Realize();
230
223
} // main_frame::create_toolbar()
247
240
 
248
241
/*----------------------------------------------------------------------------*/
249
242
/**
 
243
 * \brief Create the "Edit" menu of the menu bar.
 
244
 */
 
245
wxMenu* bf::main_frame::create_edit_menu() const
 
246
{
 
247
  wxMenu* menu = new wxMenu();
 
248
 
 
249
  menu->Append
 
250
    ( ID_CHANGE_DURATION, _("&Change all durations..."),
 
251
      _("Change the duration of all frames at once.") );
 
252
 
 
253
  return menu;
 
254
} // main_frame::create_edit_menu()
 
255
 
 
256
/*----------------------------------------------------------------------------*/
 
257
/**
250
258
 * \brief Create the "Animation" menu of the menu bar.
251
259
 */
252
260
wxMenu* bf::main_frame::create_animation_menu() const
329
337
 */
330
338
void bf::main_frame::compile_animation_no_check()
331
339
{
332
 
  std::string std_path( wx_to_std_string(m_animation_file) );
333
 
  std::size_t pos = std_path.rfind(".anim");
334
 
 
335
 
  if ( pos != std::string::npos )
336
 
    std_path = std_path.substr(0, pos);
337
 
 
338
 
  std_path += ".canim";
339
 
 
340
 
  std::ofstream f( std_path.c_str() );
341
 
 
342
 
  if (f)
 
340
  try
343
341
    {
344
 
      compiled_file cf(f);
345
 
      m_animation_edit->get_value().compile(cf);
 
342
      wxGetApp().compile_animation
 
343
        ( m_animation_edit->get_value(), m_animation_file );
346
344
    }
347
 
  else
 
345
  catch ( std::exception& e )
348
346
    {
349
347
      wxMessageDialog dlg
350
 
        ( this, _("Error"), _("Can't open the animation file."), wxOK );
 
348
        ( this, _("Error"), std_to_wx_string(e.what()), wxOK );
351
349
 
352
350
      dlg.ShowModal();
353
351
    }
358
356
 * \brief Answer to a click on "Configuration" menu.
359
357
 * \param event This event occured.
360
358
 */
361
 
void bf::main_frame::on_configuration_menu(wxCommandEvent& event)
 
359
void bf::main_frame::on_configuration_menu( wxCommandEvent& WXUNUSED(event) )
362
360
{
363
361
  wxGetApp().configure();
364
362
} // main_frame::on_configuration_menu()
368
366
 * \brief Answer to a click on "Update image pool" menu.
369
367
 * \param event This event occured.
370
368
 */
371
 
void bf::main_frame::on_update_image_pool_menu(wxCommandEvent& event)
 
369
void bf::main_frame::on_update_image_pool_menu
 
370
( wxCommandEvent& WXUNUSED(event) )
372
371
{
373
372
  wxGetApp().update_image_pool();
374
373
} // main_frame::on_update_image_pool_menu()
378
377
 * \brief Answer to a click on "New animation".
379
378
 * \param event This event occured.
380
379
 */
381
 
void bf::main_frame::on_new_animation(wxCommandEvent& event)
 
380
void bf::main_frame::on_new_animation( wxCommandEvent& WXUNUSED(event) )
382
381
{
383
382
  main_frame* frame = new main_frame;
384
383
  frame->Show();
389
388
 * \brief Answer to a click on "Open animation".
390
389
 * \param event This event occured.
391
390
 */
392
 
void bf::main_frame::on_open_animation(wxCommandEvent& event)
 
391
void bf::main_frame::on_open_animation( wxCommandEvent& WXUNUSED(event) )
393
392
{
394
 
  wxFileDialog dlg( this, _("Choose an animation"), wxT(""), wxT(""),
395
 
                    _("Animation files (*.anim)|*.anim"),
396
 
                    wxFD_OPEN | wxFD_FILE_MUST_EXIST );
 
393
  const wxFileName path(m_animation_file);
 
394
 
 
395
  wxFileDialog dlg
 
396
    ( this, _("Choose an animation"), path.GetPath(), wxEmptyString,
 
397
      _("Animation files (*.anim)|*.anim"), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
397
398
 
398
399
  if ( dlg.ShowModal() == wxID_OK )
399
400
    {
413
414
 * \brief Answer to a click on "Save".
414
415
 * \param event This event occured.
415
416
 */
416
 
void bf::main_frame::on_save(wxCommandEvent& event)
 
417
void bf::main_frame::on_save( wxCommandEvent& WXUNUSED(event) )
417
418
{
418
419
  save();
419
420
} // main_frame::on_save()
423
424
 * \brief Answer to a click on "Save as".
424
425
 * \param event This event occured.
425
426
 */
426
 
void bf::main_frame::on_save_as(wxCommandEvent& event)
 
427
void bf::main_frame::on_save_as( wxCommandEvent& WXUNUSED(event) )
427
428
{
428
429
  save_as();
429
430
} // main_frame::on_save_as()
433
434
 * \brief Answer to a click on "Compile".
434
435
 * \param event This event occured.
435
436
 */
436
 
void bf::main_frame::on_compile(wxCommandEvent& event)
 
437
void bf::main_frame::on_compile( wxCommandEvent& WXUNUSED(event) )
437
438
{
438
439
  compile_animation();
439
440
} // main_frame::on_compile()
443
444
 * \brief Answer to a click on "Exit".
444
445
 * \param event This event occured.
445
446
 */
446
 
void bf::main_frame::on_exit(wxCommandEvent& event)
 
447
void bf::main_frame::on_exit( wxCommandEvent& WXUNUSED(event) )
447
448
{
448
449
  Close();
449
450
} // main_frame::on_exit()
450
451
 
451
452
/*----------------------------------------------------------------------------*/
452
453
/**
 
454
 * \brief Answer to a click on the menu to change the duration of the frames.
 
455
 * \param event This event occured.
 
456
 */
 
457
void bf::main_frame::on_change_duration( wxCommandEvent& WXUNUSED(event) )
 
458
{
 
459
  frame_duration_dialog dlg(this);
 
460
 
 
461
  if ( dlg.ShowModal() == wxID_OK )
 
462
    {
 
463
      animation anim( m_animation_edit->get_value() );
 
464
 
 
465
      switch( dlg.get_mode() )
 
466
        {
 
467
        case frame_duration_dialog::duration_replace:
 
468
          for (std::size_t i=0; i!=anim.frames_count(); ++i)
 
469
            anim.get_frame(i).set_duration(dlg.get_operand());
 
470
          break;
 
471
        case frame_duration_dialog::duration_add:
 
472
          for (std::size_t i=0; i!=anim.frames_count(); ++i)
 
473
            anim.get_frame(i).set_duration
 
474
              ( dlg.get_operand() + anim.get_frame(i).get_duration() );
 
475
          break;
 
476
        case frame_duration_dialog::duration_multiply:
 
477
          for (std::size_t i=0; i!=anim.frames_count(); ++i)
 
478
            anim.get_frame(i).set_duration
 
479
              ( dlg.get_operand() * anim.get_frame(i).get_duration() );
 
480
          break;
 
481
        }
 
482
 
 
483
      m_animation_edit->set_value(anim);
 
484
    }
 
485
} // main_frame::on_change_duration()
 
486
 
 
487
/*----------------------------------------------------------------------------*/
 
488
/**
453
489
 * \brief Answer to an activation of the "online doc" menu.
454
490
 * \param event This event occured.
455
491
 */
456
 
void bf::main_frame::on_online_doc(wxCommandEvent& event)
 
492
void bf::main_frame::on_online_doc( wxCommandEvent& WXUNUSED(event) )
457
493
{
458
494
  wxLaunchDefaultBrowser
459
495
    ( wxT("http://plee-the-bear.sourceforge.net/" )
465
501
 * \brief Answer to an activation of the "about" menu.
466
502
 * \param event This event occured.
467
503
 */
468
 
void bf::main_frame::on_about(wxCommandEvent& event)
 
504
void bf::main_frame::on_about( wxCommandEvent& WXUNUSED(event) )
469
505
{
470
506
  about_dialog dlg(*this);
471
507
 
477
513
 * \brief Procedure called when closing the window.
478
514
 * \param event This event occured.
479
515
 */
480
 
void bf::main_frame::on_close(wxCloseEvent& event)
 
516
void bf::main_frame::on_close( wxCloseEvent& event )
481
517
{
482
518
  save_config();
483
519
 
526
562
 
527
563
  EVT_MENU( wxID_EXIT, bf::main_frame::on_exit )
528
564
 
 
565
  EVT_MENU( bf::main_frame::ID_CHANGE_DURATION,
 
566
            bf::main_frame::on_change_duration )
 
567
 
529
568
  EVT_MENU( wxID_HELP, bf::main_frame::on_online_doc )
530
569
  EVT_MENU( wxID_ABOUT, bf::main_frame::on_about )
531
570