1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
31 #include <sys/types.h> /* on BSD, uio.h needs types.h */
32 #include <sys/uio.h> /* "input.h" */
33 #include <kernel/OS.h>
35 #include <Application.h>
38 #include <DirectWindow.h>
52 #include "video_output.h"
55 #include "interface.h"
60 #include "beos_window.h"
62 /*****************************************************************************
63 * intf_sys_t: description and status of FB interface
64 *****************************************************************************/
65 typedef struct intf_sys_s
67 InterfaceWindow * p_window;
71 /*****************************************************************************
73 *****************************************************************************/
75 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t *p_intf )
76 : BWindow(frame, name, B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
79 SetName( "interface" );
83 p_view = new BView( Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW );
89 InterfaceWindow::~InterfaceWindow()
93 /*****************************************************************************
94 * InterfaceWindow::MessageReceived
95 *****************************************************************************/
97 void InterfaceWindow::MessageReceived( BMessage * p_message )
101 switch( p_message->what )
104 p_message->FindString( "bytes", (const char **)&psz_key );
105 p_interface->p_sys->i_key = psz_key[0];
109 BWindow::MessageReceived( p_message );
114 /*****************************************************************************
115 * InterfaceWindow::QuitRequested
116 *****************************************************************************/
118 bool InterfaceWindow::QuitRequested()
127 /*****************************************************************************
128 * intf_BeCreate: initialize dummy interface
129 *****************************************************************************/
130 int intf_BeCreate( intf_thread_t *p_intf )
132 /* Allocate instance and initialize some members */
133 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
134 if( p_intf->p_sys == NULL )
136 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
139 p_intf->p_sys->i_key = -1;
141 /* Create the interface window */
142 p_intf->p_sys->p_window =
143 new InterfaceWindow( BRect( 100, 100, 200, 200 ), "Interface :)", p_intf );
144 if( p_intf->p_sys->p_window == 0 )
146 free( p_intf->p_sys );
147 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow\n" );
151 /* Spawn video output thread */
152 if( p_main->b_video )
154 p_intf->p_vout = vout_CreateThread( NULL, 0, 0, 0, NULL, 0, NULL );
155 if( p_intf->p_vout == NULL ) /* error */
157 intf_ErrMsg("intf error: can't create output thread\n" );
161 /* Bind normal keys. */
162 intf_AssignNormalKeys( p_intf );
169 /*****************************************************************************
170 * intf_BeDestroy: destroy dummy interface
171 *****************************************************************************/
172 void intf_BeDestroy( intf_thread_t *p_intf )
174 /* Close input thread, if any (blocking) */
175 if( p_intf->p_input )
177 input_DestroyThread( p_intf->p_input, NULL );
180 /* Close video output thread, if any (blocking) */
183 vout_DestroyThread( p_intf->p_vout, NULL );
186 /* Destroy the interface window */
187 p_intf->p_sys->p_window->Lock();
188 p_intf->p_sys->p_window->Quit();
190 /* Destroy structure */
191 free( p_intf->p_sys );
195 /*****************************************************************************
196 * intf_BeManage: event loop
197 *****************************************************************************/
198 void intf_BeManage( intf_thread_t *p_intf )
200 if( p_intf->p_sys->i_key != -1 )
202 intf_ProcessKey( p_intf, p_intf->p_sys->i_key );
203 p_intf->p_sys->i_key = -1;