[futurebasic] Text Over Movie

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

From: Eugen Rosu <eugen.rosu@...>
Date: Tue, 29 Nov 2016 15:06:58 +0200
Hi !
How can I keep a text over a movie ? When the movie is playing ?
In the example below.

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
_EF1LeftUp = 20
_EF1RightUp = _wndW-20
_EF1LeftDwn = _wndW*9/16
_EF1RightDwn = _EF1LeftDwn + 250

_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
     DIM AS HIViewRef           textView
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
     dim as CGColorRef    @prevColor, newColor
     dim as OSStatus      ignore
LOCAL FN TxtViewSetAlpha( txtView as HIViewRef, alpha as single )
'~'1
long if ( fn HITextViewCopyBackgroundColor( txtView, @prevColor ) == _noErr )
newColor = fn CGColorCreateCopyWithAlpha( prevColor, alpha )
long if ( newColor )
ignore = fn HITextViewSetBackgroundColor( txtView, newColor )
fn CGColorRelease( newColor )
end if
fn CGColorRelease( prevColor )
end if
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 mode
     dim as TXNTypeAttributes  attr
local fn SetHITextViewFontColor( textView as HIViewRef, rgb as ^RGBColor )
'~'1
attr.tag  = _kTXNQDFontColorAttribute
attr.size = _kTXNQDFontColorAttributeSize
attr.data.dataPtr = rgb
end fn = fn TXNSetTypeAttributes( fn HITextViewGetTXNObject( textView ), 1, @attr, _kTXNStartOffset, _kTXNEndOffset )
'~'5

local mode
     dim as TXNTypeAttributes attr
local fn SetHITextViewFontSize( textView as HIViewRef, fontSize as short ) as OSStatus
'~'1
attr.tag  = _kTXNQDFontSizeAttribute
attr.size = _kTXNFontSizeAttributeSize
attr.data.dataValue = fontSize << 16
end fn = fn TXNSetTypeAttributes( fn HITextViewGetTXNObject( textView ), 1, @attr, _kTXNStartOffset, _kTXNEndOffset )
'~'5

local mode
     dim as TXNControlData txnControlData(1)
     dim as TXNControlTag txnControlTag(1)
local fn SetHITextViewJustification( textView as HIViewRef, justification as UInt32 )
'~'1
//_kTXNFlushDefault = 0/*flush according to the line direction */
//_kTXNFlushLeft = 1
//_kTXNFlushRight = 2
//_kTXNCenter = 4
//_kTXNFullJust = 8
//_kTXNForceFullJust = 16

txnControlTag(0) = _kTXNJustificationTag
txnControlData.uValue(0) = justification
end fn = fn TXNSetTXNObjectControls( fn HITextViewGetTXNObject( textView ), _false, 1, @txnControlTag(0), @txnControlData(0) )
'~'5

LOCAL
     dim as TXNMargins       margins
     dim as TXNControlData   cData
     dim as TXNControlTag    tag
LOCAL FN TxtViewSetMargins( txtView as HIViewRef, left as SInt16, top as SInt16, right as SInt16, bottom as SInt16 )
'~'1
margins.topMargin    = top
margins.leftMargin   = left
margins.bottomMargin = bottom
margins.rightMargin  = right
cData.marginsPtr     = @margins
tag = _kTXNMarginsTag

END FN = fn TXNSetTXNObjectControls( fn HITextViewGetTXNObject( txtView ), _false, 1, @tag, @cData )
'~'5

LOCAL
     DIM AS HIViewRef     TextViewBlack
     DIM AS HIRect        bounds
LOCAL FN BlackRect
'~'1
bounds.origin.x = 20
bounds.origin.y = 42
bounds.size.width = 610
bounds.size.height = 341
fn HITextViewCreate( #bounds, 0, 0, @TextViewBlack )
fn HIViewAddSubview( fn HIViewGetRoot( window( _wndRef ) ), TextViewBlack)
fn HIViewSetVisible( TextViewBlack, _true )
fn HIViewSetEnabled( TextViewBlack, _false )
fn ViewBindToParent( fn HIViewGetRoot( window( _wndRef ) ), _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, ,(20+35, 20+380)-(20+35+20, 20+380+20), _kControlRoundButtonProc
size = _kControlRoundButtonLargeSize
fn SetButtonData( _PlayButton, 0, _kControlRoundButtonSizeTag, sizeof( ControlRoundButtonSize ), size )
fn ViewBindToParent( button&( _PlayButton ), _true, _true, _false, _false )
appearance button _PlayButton
END FN
'~'5

LOCAL
     DIM AS HIViewRef       contentView
     DIM AS HIRect          bounds
     DIM AS RGBColor        fontRGB
LOCAL FN MyTextView
'~'1
bounds.origin.x = 20
bounds.origin.y = 42
bounds.size.width = 610
bounds.size.height = 341

fn HITextViewCreate( #bounds, 0, 0, @textView )
fn HIViewAddSubview( fn HIViewGetRoot( window( _wndRef ) ), textView )
fn HIViewSetVisible( textView, _true )
fn HIViewSetEnabled( textView, _false )
fn TxtViewSetMargins( textView, 10, 10, 10, 10 )
fontRGB.red = 65535 : fontRGB.green = 65535 : fontRGB.blue  = 65535// White color
fn SetHITextViewFontColor( textView, fontRGB)
fn SetHITextViewJustification( textView, _kTXNCenter)
fn SetHITextViewFontSize( textView, 20 )
fn TxtViewSetAlpha( textView, 0 )
fn HIViewSetText( textView, @"This text must be over the movie" )
END FN
'~'5


LOCAL
     DIM AS LONG         evnt, id
LOCAL FN doDialog
'~'1
evnt = dialog(0)
id = dialog(evnt)
SELECT evnt
CASE _btnClick
SELECT id
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
     DIM AS HIContentBorderMetrics   border
     DIM AS WindowRef                w
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

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

'~'7

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

ON DIALOG FN doDialog
RunApplicationEventLoop()

‘----------------------------------------------