web_runtime_hooks

    Kagura runtime hooks for browser JavaScript and WebAssembly, with native integration

    Download zip
    Author
    Version
    0.7.2
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    95

    #Webポインター入力

    JS用のWebPointerInputはCanvasごとにマウス・タッチ・ペンの入力を保持し、共通UIのUIPointerFrameへ変換する。

    JS以外のバックエンドでも型とメソッドは同じで、pollはNoneを返す。入力をInputSnapshotへフォールバックする処理を共通に書ける。

    let pointer = @hooks.WebPointerInput::new(selector="#app")
    // CSS上のCanvasサイズからゲームの論理座標へ変換する。
    let frame = pointer.poll(width=game_width, height=game_height)
    // Some(frame)ならUIModalLayer.handle_pointerやUIDragController.handle_pointerへ。
    // Canvasのないヘッドレス実行ではNoneなのでInputSnapshotにフォールバックできる。
    pointer.dispose()

    押下・解放・取消はキューで保持し、フレーム間に完了した短いタップも押下→解放の順に消費する。移動は最新の小数座標を使い、補間しない。最初のポインターを解放まで所有し、別の指へ操作を移さない。ペンはTouch IDとして扱う。

    Pointer CaptureでCanvasの外まで追跡し、pointercancel・Capture喪失・Esc・右クリック・ウィンドウのフォーカス喪失・非表示化で取消を通知する。非表示化とフォーカス喪失では未消費のクリックも破棄する。Canvasにフォーカスがある間はTab、Space、方向キーのブラウザ既定動作を抑止する。

    同じCanvasへの再登録は入力とイベントリスナーを共有する。別のCanvasは独立する。dispose()は共有ハンドルを無効化してリスナーとCaptureを解放し、同じCanvasへ改めて登録できる。@hooks.uninstall()/shutdown()でも全バッファを解放する。

    UIの入力スコープやゲームの合法手はこのホスト層へ持ち込まない。マウスとタッチを同じUI契約へ渡し、モーダル制御と実際の操作判定は共通UI/アプリ側が担当する。

    WebPointerInput

    pub struct WebPointerInput {
    // private fields
    }

    Pointer input contract shared across backends. Browser installations on the same canvas share one buffer; unsupported hosts return None when polled.

    WebPointerInput::dispose

    fn WebPointerInput::dispose(self : WebPointerInput) -> Unit

    WebPointerInput::new

    fn WebPointerInput::new(selector? : String) -> WebPointerInput

    WebPointerInput::poll

    fn WebPointerInput::poll(self : WebPointerInput, width~ : Double, height~ : Double) ->
    UIPointerFrame
    ?

    Consume one press/release/cancel edge before sampling the latest movement. Coordinates are mapped from the canvas CSS box to the requested viewport.

    clear_source_image_palettes

    fn clear_source_image_palettes() -> Unit

    install

    fn install(_canvas_selector : String) -> Unit

    is_ready

    fn is_ready() -> Bool

    patch_source_image_rgba8

    fn patch_source_image_rgba8(source_image_id : Int, width : Int, height : Int, dirty_x : Int, dirty_y : Int, dirty_width : Int, dirty_height : Int, rgba8_channels : Array[Int]) -> Bool

    register_source_image_palette

    fn register_source_image_palette(source_image_id : Int, _palette :
    ImagePalette2x2
    ) -> Unit

    register_source_image_rgba8

    fn register_source_image_rgba8(source_image_id : Int, width : Int, height : Int, rgba8_channels : Array[Int]) -> Unit

    register_source_image_solid_color

    fn register_source_image_solid_color(source_image_id : Int, color :
    Rgba
    ) -> Unit

    register_static_geometry

    fn register_static_geometry(_vertices : Array[Double], _indices : Array[Int]) -> Unit

    Optional JS WebGPU optimization; other backends manage their own resources.

    request_animation_frame

    fn request_animation_frame(_f : () -> Unit) -> Unit

    shutdown

    fn shutdown() -> Unit

    source_image_cache_count

    fn source_image_cache_count() -> Int

    source_image_generation

    fn source_image_generation(image_id : Int) -> Int

    source_image_height

    fn source_image_height(image_id : Int) -> Int

    source_image_pixel_channel

    fn source_image_pixel_channel(image_id : Int, x : Int, y : Int, channel_index : Int) -> Int

    source_image_width

    fn source_image_width(image_id : Int) -> Int

    sync_dirty_atlas_pages_from_repository

    fn sync_dirty_atlas_pages_from_repository(repository :
    SimpleAtlasImageRepository
    ) -> Int

    sync_dirty_source_images_from_repository

    fn sync_dirty_source_images_from_repository(repository :
    SimpleImageRepository
    ) -> Int

    sync_source_image_palettes

    fn sync_source_image_palettes(bindings : Array[
    ImagePaletteBinding
    ]) -> Int

    sync_source_image_palettes_from_repository

    fn sync_source_image_palettes_from_repository(repository :
    SimpleImageRepository
    ) -> Int

    sync_source_images

    fn sync_source_images(bindings : Array[
    SourceImageBinding
    ]) -> Int

    sync_source_images_from_repository

    fn sync_source_images_from_repository(repository :
    SimpleImageRepository
    ) -> Int

    uninstall

    fn uninstall() -> Unit