package jp.kazhida.kotos2d

import android.content.Context
import android.os.Handler
import android.opengl.GLSurfaceView
import android.util.AttributeSet

/**
 * Created by kazhida on 2013/07/27.
 */
public class Kotos2dGLSurfaceView(context: Context, attrs: AttributeSet? = null): GLSurfaceView(context, attrs) {

    class object {
        val TAG = javaClass<Kotos2dActivity>().getSimpleName()
        val HANDLER_OPEN_IME_KEYBOARD: Int = 2
        val HANDLER_CLOSE_IME_KEYBOARD: Int = 3
        //todo: Static handler -> Potential leak!
        val handler = Handler()

        var glSurfaceView: Kotos2dGLSurfaceView? = null

        //  todo: クラスができてからやる
//        var textInputWrapper: = Kotos2dTextInputWrapper? = null

        public fun queueAccelerometer(x : Float, y : Float, z : Float, timestamp : Long) : Unit {
            glSurfaceView?.queueEvent{
                Kotos2dAccelerometer.onSensorChanged(x, y, z, timestamp)
            }
        }
    }

    public var renderer: Kotos2dRenderer? = null
        get() {
            return $renderer
        }
        set(renderer: Kotos2dRenderer?) {
            $renderer = renderer
            setRenderer(renderer)
        }

    private val contentText: String?
    get() {
//        return renderer?.getContentText()
        return null
    }

    public var editText: Kotos2dEditText? = null


    override fun onResume() {
        super.onResume()
        queueEvent {
            renderer?.handleOnResume()
        }
    }

    override fun onPause() {
        queueEvent {
            renderer?.handleOnPause()
        }
        //super.onPause()
    }

    public fun insertText(text: String?) : Unit {
        this.queueEvent {
            renderer?.handleInsertText(text)
        }
    }

    public fun deleteBackward() : Unit {
        this.queueEvent {
            renderer?.handleDeleteBackward()
        }
    }
}