home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek 6
/
Geek-006.iso
/
linux
/
video
/
xmovie-1.5.3.tar.gz
/
xmovie-1.5.3.tar
/
xmovie-1.5.3
/
xmovie
/
mwindowgui.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-11-29
|
10KB
|
531 lines
#include "asset.h"
#include "colormodels.h"
#include "errorbox.h"
#include "file.h"
#include "keys.h"
#include "mainwindow.h"
#include "mainmenu.h"
#include "mwindowgui.h"
#include "playbackengine.h"
#include "theme.h"
#include "units.h"
#include "vframe.h"
#include <string.h>
MWindowGUI::MWindowGUI(MainWindow *mwindow, int x, int y, int w, int h)
: BC_Window("XMovie",
x,
y,
w,
h,
32,
32,
1,
0,
1)
{
this->mwindow = mwindow;
bitmap = 0;
yuv_bitmap = 0;
}
MWindowGUI::~MWindowGUI()
{
if(bitmap) delete bitmap;
if(yuv_bitmap) delete yuv_bitmap;
}
int MWindowGUI::create_objects()
{
int w = get_w(), h = get_h();
add_tool(menu = new MainMenu(mwindow, get_w()));
menu->create_objects();
mwindow->theme->update_positions(mwindow, this, w, h);
mwindow->theme->draw_mwindow_bg(mwindow, this);
add_tool(canvas = new MainCanvas(mwindow,
0,
menu->get_h(),
mwindow->canvas_w,
mwindow->canvas_h));
canvas->draw_top_background(this, 0, 0, canvas->get_w(), canvas->get_h());
canvas->flash();
add_tool(time_title = new BC_Title(mwindow->theme->time_x,
mwindow->theme->time_y,
"",
MEDIUM_7SEGMENT,
BLACK));
add_tool(playbutton = new PlayButton(mwindow,
mwindow->theme->play_x,
mwindow->theme->play_y));
add_tool(backbutton = new FrameBackButton(mwindow,
mwindow->theme->frameback_x,
mwindow->theme->frameback_y));
add_tool(forwardbutton = new FrameForwardButton(mwindow,
mwindow->theme->framefwd_x,
mwindow->theme->framefwd_y));
add_tool(scrollbar = new MainScrollbar(mwindow,
mwindow->theme->scroll_x,
mwindow->theme->scroll_y,
mwindow->theme->scroll_w));
return 0;
}
int MWindowGUI::resize_scrollbar()
{
scrollbar->update(
scrollbar->get_w(),
mwindow->current_percentage * SCROLLBAR_LENGTH,
0,
SCROLLBAR_LENGTH);
return 0;
}
int MWindowGUI::resize_widgets()
{
mwindow->theme->draw_mwindow_bg(mwindow, this);
canvas->reposition_window(mwindow->theme->canvas_x,
mwindow->theme->canvas_y,
mwindow->canvas_w,
mwindow->canvas_h);
canvas->draw_top_background(this, 0, 0, canvas->get_w(), canvas->get_h());
time_title->reposition_window(mwindow->theme->time_x, mwindow->theme->time_y);
playbutton->reposition_window(mwindow->theme->play_x, mwindow->theme->play_y);
backbutton->reposition_window(mwindow->theme->frameback_x, mwindow->theme->frameback_y);
forwardbutton->reposition_window(mwindow->theme->framefwd_x, mwindow->theme->framefwd_y);
scrollbar->reposition_window(mwindow->theme->scroll_x,
mwindow->theme->scroll_y,
mwindow->theme->scroll_w,
scrollbar->get_h());
resize_scrollbar();
return 0;
}
int MWindowGUI::resize_canvas(int w, int h)
{
mwindow->theme->update_positions(mwindow, this, w, h);
resize_window(w, h);
resize_widgets();
return 0;
}
int MWindowGUI::resize_event(int w, int h)
{
if(mwindow->asset && mwindow->asset->video_data && !yuv_bitmap)
{
unlock_window();
mwindow->stop_playback();
lock_window();
}
// fix dimensions for canvas size
mwindow->theme->update_positions(mwindow, this, w, h);
resize_window(w, h);
resize_widgets();
if(!canvas->video_is_on() && mwindow->video_file)
{
mwindow->flash_frame(mwindow->current_percentage);
canvas->flash();
}
return 0;
}
int MWindowGUI::start_playback()
{
canvas->start_video();
// YUV strategy
if(mwindow->video_file->yuv_copy_possible())
{
int in_x, in_y, in_w, in_h;
mwindow->get_yuv_cropping(in_x, in_y, in_w, in_h);
yuv_bitmap = canvas->new_bitmap(in_w,
in_h,
BC_YUV420P);
playback_colormodel = BC_YUV420P;
}
// Other strategies
else
{
if(!bitmap)
{
bitmap = canvas->new_bitmap(canvas->get_w(), canvas->get_h());
}
playback_colormodel = get_color_model();
}
return 0;
}
int MWindowGUI::stop_playback()
{
// Delete YUV strategy
if(playback_colormodel == BC_YUV420P)
{
delete yuv_bitmap;
yuv_bitmap = 0;
}
canvas->stop_video();
return 0;
}
int MWindowGUI::flash_frame(VFrame* frame)
{
// Flash YUV buffer
if(yuv_bitmap)
{
canvas->draw_bitmap(yuv_bitmap,
1,
0,
0,
canvas->get_w(),
canvas->get_h());
return 0;
}
// Test for resize
if(bitmap &&
(bitmap->get_w() != canvas->get_w() ||
bitmap->get_h() != canvas->get_h()))
{
delete bitmap;
bitmap = 0;
}
if(!bitmap)
{
bitmap = canvas->new_bitmap(canvas->get_w(), canvas->get_h());
}
if(frame)
{
bitmap->read_frame(frame,
0,
0,
canvas->get_w(),
canvas->get_h(),
0);
}
canvas->draw_bitmap(bitmap,
0,
0,
0,
canvas->get_w(),
canvas->get_h());
return 0;
}
int MWindowGUI::close_event()
{
mwindow->exit_cleanly();
set_done(0);
return 0;
}
int MWindowGUI::update_position()
{
char string[1024];
scrollbar->update((long)(mwindow->current_percentage * SCROLLBAR_LENGTH));
Units::totext(string, (long)(mwindow->current_time * 1000),
1000,
TIME_HMS2,
30,
16);
time_title->update(string);
return 0;
}
MainScrollbar::MainScrollbar(MainWindow *mwindow, int x, int y, int w)
: BC_PercentageSlider(x,
y,
0,
w,
w,
0,
SCROLLBAR_LENGTH,
0,
0)
{
this->mwindow = mwindow;
set_tooltip("Seek to a position");
}
MainScrollbar::~MainScrollbar()
{
}
int MainScrollbar::handle_event()
{
int result = 0;
if(mwindow->asset)
{
if(get_keypress())
{
if(get_keypress() == LEFT)
{
mwindow->gui->unlock_window();
mwindow->stop_playback();
mwindow->gui->lock_window();
mwindow->frame_backward();
result = 1;
}
else
if(get_keypress() == RIGHT)
{
mwindow->gui->unlock_window();
mwindow->stop_playback();
mwindow->gui->lock_window();
mwindow->frame_forward();
result = 1;
}
}
else
{
mwindow->gui->unlock_window();
mwindow->stop_playback();
mwindow->gui->lock_window();
mwindow->current_percentage = (double)get_value() / get_length();
mwindow->flash_frame(mwindow->current_percentage);
mwindow->gui->canvas->flash();
result = 1;
}
}
return result;
}
PlayButton::PlayButton(MainWindow *mwindow, int x, int y)
: BC_Button(x, y, mwindow->theme->play)
{
set_tooltip("Play movie");
this->mwindow = mwindow;
mode = 0;
}
PlayButton::~PlayButton()
{
}
int PlayButton::set_mode(int mode)
{
this->mode = mode;
switch(mode)
{
case 0:
update_bitmaps(mwindow->theme->play);
set_tooltip("Play movie");
break;
case 1:
update_bitmaps(mwindow->theme->pause);
set_tooltip("Pause movie");
break;
}
return 0;
}
int PlayButton::handle_event()
{
if(mode == 1)
{
mwindow->gui->unlock_window();
mwindow->stop_playback();
mwindow->gui->lock_window();
set_mode(0);
}
else
{
set_mode(1);
mwindow->start_playback();
}
return 1;
}
int PlayButton::keypress_event()
{
if(get_keypress() == ' ')
{
handle_event();
return 1;
}
return 0;
}
FrameBackButton::FrameBackButton(MainWindow *mwindow, int x, int y)
: BC_Button(x, y, mwindow->theme->frame_bck)
{
this->mwindow = mwindow;
set_tooltip("Backward a frame");
}
FrameBackButton::~FrameBackButton()
{
}
int FrameBackButton::handle_event()
{
mwindow->gui->unlock_window();
mwindow->stop_playback();
mwindow->gui->lock_window();
mwindow->frame_backward();
return 1;
}
int FrameBackButton::keypress_event()
{
if(get_keypress() == LEFT)
{
handle_event();
return 1;
}
return 0;
}
FrameForwardButton::FrameForwardButton(MainWindow *mwindow, int x, int y)
: BC_Button(x, y, mwindow->theme->frame_fwd)
{
this->mwindow = mwindow;
set_tooltip("Forward a frame");
}
FrameForwardButton::~FrameForwardButton()
{
}
int FrameForwardButton::handle_event()
{
mwindow->gui->unlock_window();
mwindow->stop_playback();
mwindow->gui->lock_window();
mwindow->frame_forward();
return 1;
}
int FrameForwardButton::keypress_event()
{
if(get_keypress() == RIGHT)
{
handle_event();
return 1;
}
return 0;
}
ErrorThread::ErrorThread(MWindowGUI *gui) : Thread()
{
this->gui = gui;
}
ErrorThread::~ErrorThread()
{
}
int ErrorThread::show_error(char *text)
{
strcpy(this->text, text);
this->x = gui->get_abs_cursor_x();
this->y = gui->get_abs_cursor_y();
Thread::synchronous = 0;
startup_lock.lock();
start();
startup_lock.lock();
startup_lock.unlock();
return 0;
}
void ErrorThread::run()
{
ErrorBox box("XMovie: Error",
x < INFINITY ? x : gui->get_abs_cursor_x(),
y < INFINITY ? y : gui->get_abs_cursor_y());
box.create_objects(text);
startup_lock.unlock();
box.run_window();
}
MainCanvas::MainCanvas(MainWindow *mwindow, int x, int y, int w, int h)
: BC_SubWindow(x, y, w, h, -1)
{
this->mwindow = mwindow;
}
MainCanvas::~MainCanvas()
{
}
PlaybackScroll::PlaybackScroll(MainWindow *mwindow)
: Thread()
{
this->mwindow = mwindow;
}
PlaybackScroll::~PlaybackScroll()
{
}
int PlaybackScroll::start_playback()
{
synchronous = 1;
interrupt = 0;
startup_lock.lock();
start();
return 0;
}
int PlaybackScroll::stop_playback()
{
interrupt = 1;
return 0;
}
int PlaybackScroll::wait_for_startup()
{
startup_lock.lock();
startup_lock.unlock();
return 0;
}
int PlaybackScroll::wait_for_completion()
{
join();
return 0;
}
void PlaybackScroll::run()
{
double percentage, seconds;
Timer timer;
startup_lock.unlock();
while(!interrupt)
{
mwindow->engine->current_position(percentage, seconds);
if(percentage >= 0 && percentage > mwindow->current_percentage)
{
mwindow->current_percentage = percentage;
mwindow->current_time = seconds;
mwindow->gui->lock_window();
mwindow->gui->update_position();
mwindow->gui->unlock_window();
}
timer.delay(250);
}
}