[futurebasic] Movie in Tab

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2016 : Group Archive : Group : All Groups

From: Eugen Rosu <eugen.rosu@...>
Date: Mon, 21 Nov 2016 22:14:28 +0200
Hi !
I have the bellow simple Movie Player.
It works very well, but I want to embed it [eg:  fn EmbedButton( _MyMovieButton (???), _pane1 ) ] in one of my panes.
I don't know how. How to transform the movie in a button.  Something like "FN MakeIntoFBButton( myMovie, _MyMovieButto )"
At run, you have to open an ".avi" film and just push the round button to play.
Thank you,
Eugen

-----------------------------------------------------

'-----------------
include "Tlbx HITheme.incl"
include "Tlbx MacTextEditor.incl"
include "Tlbx CoreGraphics.incl"
include "Tlbx HIView.incl"
include "Tlbx QuickTime.incl"
include "Tlbx ControlDefinitions.incl

_myWindow = 1
_wndW = 650
_wndH = 940
_tab = 100
_tabCount = 2
_EF1LeftUp = 20
_EF1RightUp = _wndW-20
_EF1LeftDwn = _wndW*9/16
_EF1RightDwn = _EF1LeftDwn + 250
begin enum 1
_pane1
_pane2
end enum
_PlayButton = 10

toolbox fn HITextViewCopyBackgroundColor( HIViewRef inTextView, CGColorRef * outColor ) = OSStatus
toolbox fn HITextViewSetBackgroundColor( HIViewRef inTextView, CGColorRef inColor ) = OSStatus
'~'5

BEGIN GLOBALS
     DIM AS HANDLE              MyMovie
     DIM as Pointer             gMovieBlk
     DIM as SHORT               WhatButtonIsActive
BEGIN RECORD MovieInfo
DIM as handle     MovieH
DIM as pointer    MovieController
DIM as pointer    MoviePort
DIM as short      FPS, MovieResRefNum
END RECORD
dim as long theTrack
     DIM as ControlRef      sliderRef
     DIM as SINGLE          DurationInSeconds, duration
END GLOBALS


'~The Movie


'~Enter/Init this QT .Incl
LOCAL MODE
LOCAL FN FBQTEnter
'~'
IF FN EnterMovies THEN ShutDown @"QuickTime Not Available!"
END FN = FN NewPTRclear ( SizeOf( MovieInfo ) )
'~'5

'~Start a movie playing
LOCAL MODE
     DIM as short       OSErr
     DIM as pointer     DoActionResult
LOCAL FN FBQTChgMovie ( MovieBlk as pointer to MovieInfo, doWhat as pointer, WhatInfo as pointer )'WhatInfo& )
'~'
LONG IF MovieBlk
DoActionResult = WhatInfo
MovieBlk = MovieBlk + SizeOf( MovieInfo )
OSErr = FN MCDoAction( MovieBlk.MovieController, doWhat, DoActionResult )
Poke Long Event - 8, 2
CALL MoviesTask( MovieBlk.MovieH, 0 )
END IF
END FN
'~'5


'~Open a new QT Movie/Window
CLEAR LOCAL MODE
     DIM as short      MovieResRefNum, ResID, DataRefChanged
     dim as movie      Movie, MovieCT
     DIM AS CGrafPtr   CGrafPtr
     DIM AS GDHandle   CurDev
     DIM as rect       BoxRect
     dim as single     centeredHor : centeredHor = 0
     dim as single     konstant, KonstVertic
     dim as FSSpec     fileSpec, FSSpec
     dim as OSStatus   err
     DIM as handle     duration, MovRate, MovTime
'~'1
LOCAL FN FBQTOpen( MovieBlk as pointer to MovieInfo, FileName as Str255, VRefNum as short, ¬
                 MovieTop as short, MovieLeft as short )', wind as WindowRef)
MovieBlk = MovieBlk + SIZEOF( MovieInfo )
LONG IF MovieBlk
long if ( files$( _FSSpecOpen, "MooV", "Open Movie:", fileSpec ) != "" )
LONG IF FN OpenMovieFile( fileSpec, MovieResRefNum, _FSRdPerm ) = _NoErr

LONG IF FN NewMovieFromFile( Movie, MovieResRefNum, ResID, "", _newMovieActive, DataRefChanged)  = _noErr
GetMovieBox( Movie, BoxRect )'---> Set Movie Rectangle
OffSetRect( BoxRect, -BoxRect.Left+20, -BoxRect.Top+20 )'---> Reset Movie Box
// Case I --> Movie frame is wider than my black box, but it is shorter than my black box
LONG IF BoxRect.Right > _EF1RightUp or BoxRect.Bottom < _EF1LeftDwn
konstant = _EF1RightUp/BoxRect.Right
BoxRect.Right = _EF1RightUp
BoxRect.Bottom = BoxRect.Bottom * konstant
END IF

// Case II --> Movie frame is wider than my black box and it is higher than my black box
LONG IF BoxRect.Right > _EF1RightUp or BoxRect.Bottom > _EF1LeftDwn
centeredHor = ( _EF1RightUp - BoxRect.Right ) / 2
END IF

// Case III --> Movie frame is narrower than my black box and it is higher than my black box
LONG IF BoxRect.Right < _EF1RightUp or BoxRect.Bottom > _EF1LeftDwn
KonstVertic = _EF1LeftDwn / BoxRect.Bottom
BoxRect.Bottom = _EF1LeftDwn
BoxRect.Right = BoxRect.Right * KonstVertic
centeredHor = ( _EF1RightUp - BoxRect.Right ) / 2
END IF

LONG IF BoxRect.Bottom < 300
BoxRect.Top = 20 + (( 306 - BoxRect.Bottom ) / 2)
BoxRect.Bottom = BoxRect.Bottom + BoxRect.Top
END IF

SetRect( BoxRect, BoxRect.Left + centeredHor, BoxRect.Top, BoxRect.Right + centeredHor, BoxRect.Bottom )
SetMovieBox( Movie, BoxRect )

GetGWorld( CGrafPtr, CurDev )
GetMovieGWorld( Movie, CGrafPtr, CurDev )
SetMovieGWorld( Movie, CGrafPtr, CurDev )

MovieCT = FN NewMovieController( Movie, BoxRect, &15 )'---> Get Movie Controls BoxRect,&15
err   = FN MCGetControllerBoundsRect( MovieCT, BoxRect )
err   = FN MCEnableEditing( MovieCT, _zTrue )
err   = FN GetMovieTimeScale( Movie )
BoxRect.Top = 0 : BoxRect.Left = 0 : BoxRect.Bottom = 0 : BoxRect.Right = 0
konstant = 0 'Fix Top Left
OffSetRect( BoxRect, 16-8, 16+30 )

'---> Set Movie Block
MovieBlk.MovieH           = Movie
MovieBlk.MovieController  = MovieCT
MovieBlk.MoviePort        = CGrafPtr
MovieBlk.MovieResRefNum   = MovieResRefNum
end if
END IF
END IF
END IF

END FN' = MovieBlk.MovieH
'~'5

'~Close/Dispose of a QT Movie/Window
LOCAL MODE
     DIM as handle Movie
     dim as OSStatus    err
LOCAL FN FBQTClose( MovieBlk as pointer to MovieInfo )', WndID as short )
'~'1
long if MovieBlk
#if def _oneQTwindow
MovieBlk = MovieBlk + 1
#else
MovieBlk = MovieBlk + SIZEOF( MovieInfo )
#endif
Movie = MovieBlk.MovieH
LONG IF Movie
CALL StopMovie( Movie )'stop the movie
CALL DisposeMovieController( MovieBlk.MovieController& )
MovieBlk.MovieController& = 0
err = FN CloseMovieFile(MovieBlk.MovieResRefNum%)'close the movie file
CALL DisposeMovie( MovieBlk.MovieH )
MovieBlk.MovieH = 0
END IF
end if
END FN
'~'5

'~End Movie


LOCAL
     dim as HILayoutInfo   layout
LOCAL FN ViewBindToParent( view as HIViewRef, left as Boolean, top as Boolean, right as Boolean, bottom as Boolean )
'~'1
layout.version = _kHILayoutInfoVersionZero
fn HIViewGetLayoutInfo( view, @layout )
if ( top ) then layout.binding.top.kind = _kHILayoutBindTop
if ( left ) then layout.binding.left.kind = _kHILayoutBindLeft
if ( bottom ) then layout.binding.bottom.kind = _kHILayoutBindBottom
if ( right ) then layout.binding.right.kind = _kHILayoutBindRight
fn HIViewSetLayoutInfo( view, @layout )
END FN
'~'5

local fn MyMouseTrackingHandler( nextHandler as EventHandlerCallRef, theEvent as EventRef, view as HIViewRef )
'~'1
select fn GetEventKind( theEvent )
case _kEventControlTrackingAreaEntered
fn SetThemeCursor( _kThemeArrowCursor )

case _kEventControlTrackingAreaExited
fn SetThemeCursor( _kThemeIBeamCursor )

end select
end fn = _noErr
'~'5

local fn InstallMouseTrackingHandler( view as HIViewRef )
'~'1
dim as EventTypeSpec   eventSpec(1)
dim as OSStatus        result : result = _errMessageNotSupported
fn HIViewNewTrackingArea( view, 0, 0, #0 )
eventSpec.eventClass(0) = _kEventClassControl
eventSpec.eventKind(0)  = _kEventControlTrackingAreaEntered
eventSpec.eventClass(1) = _kEventClassControl
eventSpec.eventKind(1)  = _kEventControlTrackingAreaExited
result = fn InstallEventHandler( fn GetControlEventTarget( view ), @fn MyMouseTrackingHandler, 2, @eventSpec(0), #0, #0 )
end fn = result
'~'5

LOCAL
     DIM AS HIViewRef     TextViewBlack
     DIM AS HIRect        bounds
LOCAL FN BlackRect
'~'1
bounds.origin.x = 3
bounds.origin.y = 20
bounds.size.width = 570
bounds.size.height = 321
fn HITextViewCreate( #bounds, 0, 0, @TextViewBlack )
fn HIViewAddSubview( button&(_pane1), TextViewBlack)
fn HIViewSetVisible( TextViewBlack, _true )
fn HIViewSetEnabled( TextViewBlack, _false )
fn ViewBindToParent( button&(_pane1), _true, _true, _true, _true)
fn HITextViewSetBackgroundColor( TextViewBlack, fn CGColorCreateGenericRGB( 0, 0, 0, 1) )
fn ViewBindToParent( TextViewBlack, _true, _true, _true, _false )
END FN
'~'5

LOCAL
     dim as ControlRoundButtonSize    @size
LOCAL FN MovieButtons
'~'1
appearance button -_PlayButton, ,0,0,1, ,(35,380)-(35+20,380+20), _kControlRoundButtonProc
size = _kControlRoundButtonLargeSize
fn SetButtonData( _PlayButton, 0, _kControlRoundButtonSizeTag, sizeof( ControlRoundButtonSize ), size )
fn EmbedButton( _PlayButton, _pane1 )
fn ViewBindToParent( button&( _PlayButton ), _true, _true, _false, _false )
appearance button _PlayButton
END FN
'~'5

LOCAL
     DIM AS LONG         evnt, id, i
LOCAL FN doDialog
'~'1
evnt = dialog(0)
id = dialog(evnt)
SELECT evnt
CASE _btnClick
SELECT id
CASE _tab
FOR i = 1 to _tabCount
// *** Show/hide user panes *** //
long if i == button(_tab)
LONG IF i = 1 AND id = 100'Movie Subtitle Pane
END IF
LONG IF i = 2 AND id = 100'Source Subtitle Pane
END IF
button i
fn InstallMouseTrackingHandler( button&( _tab) )
xelse
button -i
fn InstallMouseTrackingHandler( button&( _tab) )
end if
NEXT
CASE _PlayButton'Play movie
FN FBQTChgMovie( gMovieBlk, _mcActionPlay, 0x00010000)
END SELECT
END SELECT
END FN
'~'5

LOCAL
     dim as WindowAttributes         attr
     dim as Rect                     r, rTab
     DIM AS HIContentBorderMetrics   border
     DIM AS WindowRef                w
     dim as ControlTabInfoRec        infoRec
     dim as short                    x
     dim as str15                    tabTitleStr(_tabCount)
     tabTitleStr(1) = "Movie"
     tabTitleStr(2) = "Text"
LOCAL FN BuildWindow
'~'1
attr  = _kWindowStandardFloatingAttributes + _kWindowStandardHandlerAttribute + _kWindowResizableAttribute
attr += _kWindowCompositingAttribute + _kWindowLiveResizeAttribute + _kWindowFullZoomAttribute
attr += _kWindowHasRoundBottomBarCornersAttribute
SetRect( @r, 0, 44, 650, 940 )
appearance window - _myWindow, @"untitled", @r, _kDocumentWindowClass, attr
fn SetWindowBackground( _kThemeActiveDialogBackgroundBrush, _true )
FN NewWindowPositionMethod(0)
w = window( _wndRef )
border.top = 0.0
border.left = 0.0
border.bottom = 30.0
border.right = 0.0
fn HIWindowSetContentBorderThickness( w, @border )
MinWindow 650, 895
MaxWindow 1760, 1050

SetRect( @rTab, 20, 20, _wndW-19, _wndH-93 )
appearance button _tab, _activeBtn, 0, 0, _tabCount,, @rTab, _kControlTabSmallProc
InsetRect( @r, 10, 10 )
for x = 1 to _tabCount
// **** Titles for tabs **** //
infoRec.version = _kControlTabInfoVersionZero
infoRec.iconSuiteID = 0
infoRec.name = tabTitleStr(x)
fn SetButtonData( _tab, x, _kControlTabInfoTag, sizeof( infoRec ), infoRec )
// **** User Panes - only top one is initially visible **** //
long if x == 1
appearance button x,,_kControlSupportsEmbedding,,,, @rTab, _kControlUserPaneProc // visible
xelse
appearance button -x,,_kControlSupportsEmbedding,,,, @rTab, _kControlUserPaneProc // invisible
end if
fn embedbutton( x, _tab )
fn ViewBindToParent( button&(_tab), _true, _true, _true, _true )
next

FN BlackRect
FN MovieButtons
appearance window _myWindow
END FN
'~'5

'~'7

gMovieBlk = FN FBQTEnter
FN BuildWindow
FN FBQTOpen( gMovieBlk, "", 0, 0, 0 )

ON DIALOG FN doDialog
RunApplicationEventLoop()

-------------------------------------------------------