view libclient/malikania/js-color.hpp @ 36:9af360f34c7d

Misc: use raw duktape API
author David Demelier <markand@malikania.fr>
date Wed, 10 Aug 2016 14:30:51 +0200
parents d4f5f7231b84
children
line wrap: on
line source

/*
 * js-color.hpp -- color description (JavaScript binding)
 *
 * Copyright (c) 2013-2016 Malikania Authors
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef MALIKANIA_JS_COLOR_HPP
#define MALIKANIA_JS_COLOR_HPP

/**
 * \file js-color.h
 * \brief JavaScript binding for Color.
 *
 * Colors can be created from plain JavaScript object.
 *
 * ````
 * {
 *   red: 0,
 *   green: 255,
 *   blue: 255,
 *   alpha: 255
 * }
 * ````
 *
 * It can also takes strings like "#rrggbbaa" and SVG names.
 */

#include "color.hpp"
#include "duktape.hpp"

namespace malikania {

/**
 * Get a color.
 *
 * May return a default value or a color with adjusted components.
 *
 * @param ctx the context
 * @param index the index
 */
Color dukx_get_color(duk_context *ctx, duk_idx_t index);

/**
 * Require a color.
 *
 * If the color has any invalid component, raise a JavaScript error.
 *
 * @param ctx the context
 * @param index the index
 */
Color dukx_require_color(duk_context *ctx, duk_idx_t index);

/**
 * Like get, but return the default value only if the value at the given
 * index is not an object or not a string, otherwise, adjust invalid values.
 *
 * @param ctx the context
 * @param index the index
 * @param def the default value
 */
Color dukx_optional_color(duk_context *ctx, duk_idx_t index, Color def);

/**
 * Push the color as object.
 *
 * @param ctx the context
 * @param color the color
 */
void dukx_push_color(duk_context *ctx, const Color &color);

/**
 * Put the color properties into the object at the top of the stack.
 *
 * @pre the top value must be an object
 * @param ctx the context
 * @param color the color
 */
void dukx_put_color(duk_context *ctx, const Color &color);

void dukx_load_color(duk_context *ctx);

} // !malikania

#endif // !MALIKANIA_JS_COLOR_HPP