2
2
Bear Engine - Animation editor
4
Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
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
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"
67
66
void bf::main_frame::load_animation( const wxString& path )
72
animation_file_xml_reader reader;
74
if ( !doc.Load(path) )
75
throw std::ios_base::failure
76
( "Cannot load the XML file '" + wx_to_std_string(path) + "'" );
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;
84
catch( std::exception& e )
87
( this, std_to_wx_string( e.what() ),
88
_("Error when loading the animation."), wxOK );
70
animation_file_xml_reader reader;
74
anim = reader.load( doc.GetRoot() );
76
m_animation_edit->set_value(anim);
77
m_last_saved_animation = m_animation_edit->get_value();
78
m_animation_file = path;
92
80
} // main_frame::load_animation()
94
82
/*----------------------------------------------------------------------------*/
138
126
bool bf::main_frame::save_as()
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 );
205
193
wxMenuBar* menu_bar = new wxMenuBar();
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"));
210
199
SetMenuBar(menu_bar);
219
208
wxToolBar* bar = CreateToolBar();
221
bar->AddTool( wxID_NEW, _("&New"), wxArtProvider::GetBitmap(wxART_NEW) );
223
( wxID_OPEN, _("&Open"), wxArtProvider::GetBitmap(wxART_FILE_OPEN) );
225
( wxID_SAVE, _("&Save"), wxArtProvider::GetBitmap(wxART_FILE_SAVE) );
211
( wxID_NEW, _("&New"), wxArtProvider::GetBitmap(wxART_NEW), _("New") );
213
( wxID_OPEN, _("&Open"), wxArtProvider::GetBitmap(wxART_FILE_OPEN),
216
( wxID_SAVE, _("&Save"), wxArtProvider::GetBitmap(wxART_FILE_SAVE),
226
218
bar->AddSeparator();
227
bar->AddTool( ID_COMPILE, _("&Compile"), wxBitmap(compile_xpm) );
220
( ID_COMPILE, _("&Compile"), wxBitmap(compile_xpm), _("Compile") );
230
223
} // main_frame::create_toolbar()
248
241
/*----------------------------------------------------------------------------*/
243
* \brief Create the "Edit" menu of the menu bar.
245
wxMenu* bf::main_frame::create_edit_menu() const
247
wxMenu* menu = new wxMenu();
250
( ID_CHANGE_DURATION, _("&Change all durations..."),
251
_("Change the duration of all frames at once.") );
254
} // main_frame::create_edit_menu()
256
/*----------------------------------------------------------------------------*/
250
258
* \brief Create the "Animation" menu of the menu bar.
252
260
wxMenu* bf::main_frame::create_animation_menu() const
330
338
void bf::main_frame::compile_animation_no_check()
332
std::string std_path( wx_to_std_string(m_animation_file) );
333
std::size_t pos = std_path.rfind(".anim");
335
if ( pos != std::string::npos )
336
std_path = std_path.substr(0, pos);
338
std_path += ".canim";
340
std::ofstream f( std_path.c_str() );
345
m_animation_edit->get_value().compile(cf);
342
wxGetApp().compile_animation
343
( m_animation_edit->get_value(), m_animation_file );
345
catch ( std::exception& e )
349
347
wxMessageDialog dlg
350
( this, _("Error"), _("Can't open the animation file."), wxOK );
348
( this, _("Error"), std_to_wx_string(e.what()), wxOK );
358
356
* \brief Answer to a click on "Configuration" menu.
359
357
* \param event This event occured.
361
void bf::main_frame::on_configuration_menu(wxCommandEvent& event)
359
void bf::main_frame::on_configuration_menu( wxCommandEvent& WXUNUSED(event) )
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.
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) )
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.
381
void bf::main_frame::on_new_animation(wxCommandEvent& event)
380
void bf::main_frame::on_new_animation( wxCommandEvent& WXUNUSED(event) )
383
382
main_frame* frame = new main_frame;
389
388
* \brief Answer to a click on "Open animation".
390
389
* \param event This event occured.
392
void bf::main_frame::on_open_animation(wxCommandEvent& event)
391
void bf::main_frame::on_open_animation( wxCommandEvent& WXUNUSED(event) )
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);
396
( this, _("Choose an animation"), path.GetPath(), wxEmptyString,
397
_("Animation files (*.anim)|*.anim"), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
398
399
if ( dlg.ShowModal() == wxID_OK )
413
414
* \brief Answer to a click on "Save".
414
415
* \param event This event occured.
416
void bf::main_frame::on_save(wxCommandEvent& event)
417
void bf::main_frame::on_save( wxCommandEvent& WXUNUSED(event) )
419
420
} // main_frame::on_save()
423
424
* \brief Answer to a click on "Save as".
424
425
* \param event This event occured.
426
void bf::main_frame::on_save_as(wxCommandEvent& event)
427
void bf::main_frame::on_save_as( wxCommandEvent& WXUNUSED(event) )
429
430
} // main_frame::on_save_as()
433
434
* \brief Answer to a click on "Compile".
434
435
* \param event This event occured.
436
void bf::main_frame::on_compile(wxCommandEvent& event)
437
void bf::main_frame::on_compile( wxCommandEvent& WXUNUSED(event) )
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.
446
void bf::main_frame::on_exit(wxCommandEvent& event)
447
void bf::main_frame::on_exit( wxCommandEvent& WXUNUSED(event) )
449
450
} // main_frame::on_exit()
451
452
/*----------------------------------------------------------------------------*/
454
* \brief Answer to a click on the menu to change the duration of the frames.
455
* \param event This event occured.
457
void bf::main_frame::on_change_duration( wxCommandEvent& WXUNUSED(event) )
459
frame_duration_dialog dlg(this);
461
if ( dlg.ShowModal() == wxID_OK )
463
animation anim( m_animation_edit->get_value() );
465
switch( dlg.get_mode() )
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());
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() );
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() );
483
m_animation_edit->set_value(anim);
485
} // main_frame::on_change_duration()
487
/*----------------------------------------------------------------------------*/
453
489
* \brief Answer to an activation of the "online doc" menu.
454
490
* \param event This event occured.
456
void bf::main_frame::on_online_doc(wxCommandEvent& event)
492
void bf::main_frame::on_online_doc( wxCommandEvent& WXUNUSED(event) )
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.
468
void bf::main_frame::on_about(wxCommandEvent& event)
504
void bf::main_frame::on_about( wxCommandEvent& WXUNUSED(event) )
470
506
about_dialog dlg(*this);
527
563
EVT_MENU( wxID_EXIT, bf::main_frame::on_exit )
565
EVT_MENU( bf::main_frame::ID_CHANGE_DURATION,
566
bf::main_frame::on_change_duration )
529
568
EVT_MENU( wxID_HELP, bf::main_frame::on_online_doc )
530
569
EVT_MENU( wxID_ABOUT, bf::main_frame::on_about )