/* * Copyright 2022 Frederico de Oliveira Linhares * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "color.h" void cg_free_color(mrb_state *mrb, void* obj) { struct cg_color *ptr = obj; mrb_free(mrb, ptr); } const struct mrb_data_type cg_color_type = { "CG_Color", cg_free_color }; static mrb_value cg_cColor_initialize(mrb_state *mrb, mrb_value self) { mrb_int red, green, blue, alpha; struct cg_color *ptr; alpha = 0xff; mrb_get_args(mrb, "iii|i", &red, &green, &blue, &alpha); ptr = (struct cg_color *)DATA_PTR(self); if(ptr) mrb_free(mrb, ptr); ptr = (struct cg_color *)mrb_malloc(mrb, sizeof(struct cg_color)); ptr->data.r = red; ptr->data.g = green; ptr->data.b = blue; ptr->data.a = alpha; mrb_data_init(self, ptr, &cg_color_type); return self; } void cg_color_init(mrb_state *mrb) { struct RClass *cg_m, *cg_cColor; cg_m = mrb_module_get(mrb, "CandyGear"); cg_cColor = mrb_define_class_under(mrb, cg_m, "Color", mrb->object_class); MRB_SET_INSTANCE_TT(cg_cColor, MRB_TT_DATA); mrb_define_method( mrb, cg_cColor, "initialize", cg_cColor_initialize, MRB_ARGS_REQ(3) | MRB_ARGS_OPT(1)); }