/*
 * Copyright (c) 2024 Ross Cunniff
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "libo3d.oah"

using namespace oadl;

o3d::Display disp(nil,nil);

var mouseDown = 0;

proc callback(draw, event)
{
    switch (event) {
    case o3d::INPUT_CONFIG :
        "Config: ", arg(4), "x", arg(5), " @ ", arg(2), ",", arg(3), "\n";
    case o3d::INPUT_DESTROY :
        halt();
    case o3d::INPUT_KEYBOARD :
        "Key: ", arg(2), "\n";
    case o3d::INPUT_BUTTON_PRESS :
        mouseDown |= 1 << arg(4);
        "Button: ", arg(4), " at ", arg(2), ",", arg(3), "\n";
    case o3d::INPUT_BUTTON_RELEASE :
        mouseDown &= ~(1 << arg(4));
        "Release: ", arg(4), " at ", arg(2), ",", arg(3), "\n";
    case o3d::INPUT_POINTER :
        if (mouseDown) {
            "Drag: ", arg(2), ",", arg(3), "\n";
        }
    }
}

proc main()
{
    var draw;

    disp.chooseVisual(o3d::VIS_DBUFF, 0);
    draw = disp.createWindow("test", 100, 100, 256, 256, o3d::WIN_INPUT);
    disp.makeCurrent(draw);
    "Renderer: ", disp.getInfo(o3d::INFO_RENDERER), "\n";
    disp.inputHandler(callback);

    while(1) {
        disp.update(o3d::UPDATE_ALL);
    }
}