/** @method contains?( thing ) -> boolean Returns whether thing ([x, y, w, h] or [x, y]) fits completely within the rectangle. */ static VALUE rb_array_contains(VALUE self, VALUE thing) { GET_X(); GET_Y(); GET_W(); GET_H(); double x2,y2,w2,h2; Check_Type(thing, T_ARRAY); x2=array_get_x(thing); y2=array_get_y(thing); if(RARRAY(thing)->len>3){ // It's a rectangle w2=array_get_w(thing); h2=array_get_h(thing); return INT2BOOL((x <= x2) && (y <= y2) && (x + w >= x2 + w2) && (y + h >= y2 + h2) && (x + w > x2) && (y + h > y2)); }else{ // It's a point return INT2BOOL((x2>=x && x2<x+w && y2>=y && y2<y+h)); } return Qfalse; }
static VALUE Mouse_s_state(VALUE mod) { int x,y; Uint8 result; result = SDL_GetMouseState(&x, &y); return rb_ary_new3(5,INT2FIX(x), INT2FIX(y), INT2BOOL(result&SDL_BUTTON_LMASK), INT2BOOL(result&SDL_BUTTON_MMASK), INT2BOOL(result&SDL_BUTTON_RMASK)); }
/** @method overlaps?( rect ) -> boolean Returns true if any area of the two rectangles overlapss. */ static VALUE rb_array_overlaps(VALUE self, VALUE otherRect) { SDL_Rect a, b; RECT2CRECT(self, &a); RECT2CRECT(otherRect, &b); return INT2BOOL(intersect(&a, &b)); }
/** call-seq: port_specified?() -> bool Returns: true if a portnumber was explicitely set by the user when the port was created */ static VALUE wrap_snd_seq_port_info_get_port_specified(VALUE v_port_info) { snd_seq_port_info_t *port_info; Data_Get_Struct(v_port_info, snd_seq_port_info_t, port_info); return INT2BOOL(snd_seq_port_info_get_port_specified(port_info)); }
/** call-seq: timestamping?() -> bool Returns: true if the port will timestamp events automatically on arrival */ static VALUE wrap_snd_seq_port_info_get_timestamping(VALUE v_port_info) { snd_seq_port_info_t *port_info; Data_Get_Struct(v_port_info, snd_seq_port_info_t, port_info); return INT2BOOL(snd_seq_port_info_get_timestamping(port_info)); }
/* * Set the value of a hint. * * @overload []=(hint, value) * Set a hint with normal priority. * * @param hint [String] the name of the hint to query * @param value [String] the value of the hint varaible * * @overload []=(hint, priority: , value) * Set a hint with given priority. * * @param hint [String] the name of the hint to query * @param priority [Integer] the priority, one of the * {DEFAULT}, {NORMAL}, or {OVERRIDE}. * @param value [String] the value of the hint varaible * * @return [Boolean] return true if the hint was set * * @example * SDL2::Hints["SDL_HINT_XINPUT_ENABLED", priority: SDL2::Hints::OVERRIDE] = "0" * */ static VALUE Hints_s_aset(int argc, VALUE* argv, VALUE self) { VALUE name, pri, value; rb_scan_args(argc, argv, "21", &name, &pri, &value); if (argc == 2) { value = pri; return INT2BOOL(SDL_SetHint(StringValueCStr(name), StringValueCStr(value))); } else { Check_Type(pri, T_HASH); return INT2BOOL(SDL_SetHintWithPriority(StringValueCStr(name), StringValueCStr(value), NUM2INT(rb_hash_aref(pri, sym_priority)))); } return Qnil; }
void Init_wkhtml_native() { //Global initialization of library and when Ruby shuts down wkhtmltopdf_init(USE_GRAPHICS_INT); wkhtmltoimage_init(USE_GRAPHICS_INT); rb_set_end_proc(Deinit_wkhtml_native, Qnil); idReady = rb_intern("ready"); mWkHtml = rb_define_module("WkHtml"); rb_define_const(mWkHtml, "LIBRARY_VERSION", rb_obj_freeze(rb_str_new_cstr(wkhtmltopdf_version()))); rb_define_const(mWkHtml, "USE_GRAPHICS", INT2BOOL(USE_GRAPHICS_INT)); mWkHtmlToPdf = rb_define_module_under(mWkHtml, "ToPdf"); cWkHtmlToPdfGlobalSettings = rb_define_class_under(mWkHtmlToPdf, "GlobalSettings", rb_cObject); rb_define_alloc_func(cWkHtmlToPdfGlobalSettings, wkhtml_topdf_globalsettings_alloc); rb_define_method(cWkHtmlToPdfGlobalSettings, "[]=", wkhtml_topdf_globalsettings_aset, 2); rb_define_method(cWkHtmlToPdfGlobalSettings, "[]", wkhtml_topdf_globalsettings_aref, 1); cWkHtmlToPdfObjectSettings = rb_define_class_under(mWkHtmlToPdf, "ObjectSettings", rb_cObject); rb_define_alloc_func(cWkHtmlToPdfObjectSettings, wkhtml_topdf_objectsettings_alloc); rb_define_method(cWkHtmlToPdfObjectSettings, "[]=", wkhtml_topdf_objectsettings_aset, 2); rb_define_method(cWkHtmlToPdfObjectSettings, "[]", wkhtml_topdf_objectsettings_aref, 1); cWkHtmlToPdfConverter = rb_define_class_under(mWkHtmlToPdf, "Converter", rb_cObject); /* TODO rb_define_singleton_method(klass, "new", constructor, 1); //Uses Data_Wrap_Struct -> rb_obj_call_init(t_data, 1, argv); rb_define_method(klass, "initialize", initialize, 1); */ rb_define_singleton_method(cWkHtmlToPdfConverter, "create", wkhtml_topdf_converter_create, 1); rb_define_method(cWkHtmlToPdfConverter, "add_object", wkhtml_topdf_converter_add_object, 2); rb_define_method(cWkHtmlToPdfConverter, "convert", wkhtml_topdf_converter_convert, 0); rb_define_method(cWkHtmlToPdfConverter, "http_error_code", wkhtml_topdf_converter_http_error_code, 0); rb_define_method(cWkHtmlToPdfConverter, "get_output", wkhtml_topdf_converter_get_output, 0); //Force use of factory method rb_undef_alloc_func(cWkHtmlToPdfConverter); rb_undef_method(rb_singleton_class(cWkHtmlToPdfConverter), "new"); mWkHtmlToImage = rb_define_module_under(mWkHtml, "ToImage"); cWkHtmlToImageGlobalSettings = rb_define_class_under(mWkHtmlToImage, "GlobalSettings", rb_cObject); rb_define_alloc_func(cWkHtmlToImageGlobalSettings, wkhtml_toimage_globalsettings_alloc); rb_define_method(cWkHtmlToImageGlobalSettings, "[]=", wkhtml_toimage_globalsettings_aset, 2); rb_define_method(cWkHtmlToImageGlobalSettings, "[]", wkhtml_toimage_globalsettings_aref, 1); cWkHtmlToImageConverter = rb_define_class_under(mWkHtmlToImage, "Converter", rb_cObject); rb_define_singleton_method(cWkHtmlToImageConverter, "create", wkhtml_toimage_converter_create, 2); rb_define_method(cWkHtmlToImageConverter, "convert", wkhtml_toimage_converter_convert, 0); rb_define_method(cWkHtmlToImageConverter, "http_error_code", wkhtml_toimage_converter_http_error_code, 0); rb_define_method(cWkHtmlToImageConverter, "get_output", wkhtml_toimage_converter_get_output, 0); //Force use of factory method rb_undef_alloc_func(cWkHtmlToImageConverter); rb_undef_method(rb_singleton_class(cWkHtmlToImageConverter), "new"); }
static VALUE Key_s_press_p(VALUE mod, VALUE keysym) { int sym = NUM2INT(keysym); rb_secure(4); if(sym < SDLK_FIRST || SDLK_LAST < sym ) rb_raise(eSDLError, "%d is out of key", sym); if(key_state == NULL) rb_raise(eSDLError, "You should call SDL::Key#scan before calling SDL::Key#press?"); return INT2BOOL(key_state[sym]==SDL_PRESSED); }
/* * call-seq: check_language(lang, all) -> bool * * Are we interested in the given language. * * Debian::AptPkg::Configuration.check_language("fr") # => true * **/ static VALUE check_language(int argc, VALUE *argv, VALUE self) { if (argc > 2 || argc == 0) { rb_raise(rb_eArgError, "wrong number of arguments"); } VALUE lang, all; rb_scan_args(argc, argv, "11", &lang, &all); int res = APT::Configuration::checkLanguage(StringValuePtr(lang), all); return INT2BOOL(res); }
/* * call-seq: check_dep(pkg_version_a, op, pkg_version_b) -> bool * * Compare the given versions with an operator. * * Params: * * +pkg_version_a+:: Version to compare from. * +op+:: See operators const or string (<, >, <=, >=, =) * +pkg_version_b+:: Version to compare to. * * Debian::AptPkg.check_dep('1', '<', '2') # => true * Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2') # => true * **/ static VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type, VALUE pkg_version_b) { unsigned int op = 0; if (TYPE(cmp_type) == T_FIXNUM) { op = NUM2INT(cmp_type); } else { const char *op_str = StringValuePtr(cmp_type); if (strcmp(op_str, ">") == 0) op_str = ">>"; if (strcmp(op_str, "<") == 0) op_str = "<<"; if (*debListParser::ConvertRelation(op_str, op) != 0) { rb_raise(rb_eArgError, "Bad comparison operation"); return 0; } } int res = debVS.CheckDep(StringValuePtr(pkg_version_a), op, StringValuePtr(pkg_version_b)); return INT2BOOL(res); }
/* * call-seq: init_system() -> bool * * Construct the apt_pkg system. * * Debian::AptPkg.init_system # => false * **/ static VALUE init_system(VALUE self) { int res = pkgInitSystem(*_config, _system); return INT2BOOL(res); }
static VALUE Font_closed(VALUE self) { return INT2BOOL(Get_KFont(self)->font == NULL); }
/* * call-seq: check_domain_list(host, list) -> bool * * See if the host name given by host is one of the domains given. * * Debian::AptPkg.check_domain_list("alioth.debian.org", "debian.net,debian.org") # => true * **/ static VALUE check_domain_list(VALUE self, VALUE host, VALUE list) { int res = CheckDomainList(StringValuePtr(host), StringValuePtr(list)); return INT2BOOL(res); }
/* * call-seq: init_config() -> bool * * Load the default configuration and the config file. * * Debian::AptPkg.init_config # => false * **/ static VALUE init_config(VALUE self) { int res = pkgInitConfig(*_config); return INT2BOOL(res); }
/* * call-seq: check_architecture(arch) -> bool * * Are we interested in the given Architecture. * * Debian::AptPkg::Configuration.check_architecture("all") # => true * **/ static VALUE check_architecture(VALUE self, VALUE arch) { int res = APT::Configuration::checkArchitecture(StringValuePtr(arch)); return INT2BOOL(res); }
/* * call-seq: string_to_bool(text) -> int * * Parse the string input and return a boolean. * * Debian::AptPkg.string_to_bool('yes') # => true * Debian::AptPkg.string_to_bool('no') # => false * Debian::AptPkg.string_to_bool('no-recognized') # => false * **/ static VALUE string_to_bool(VALUE self, VALUE text) { return INT2BOOL(StringToBool(StringValuePtr(text)) == 1); }
/* * @overload extension_supported?(extension) * Return true if the current context supports **extension** * * @param extension [String] the name of an extension * @example * SDL2::GL.extension_supported?("GL_EXT_framebuffer_blit") */ static VALUE GL_s_extension_supported_p(VALUE self, VALUE extension) { return INT2BOOL(SDL_GL_ExtensionSupported(StringValueCStr(extension))); }
static VALUE Mixer_s_play_p(VALUE mod, VALUE channel) { return INT2BOOL(Mix_Playing(NUM2INT(channel))); }
static VALUE Mouse_s_show_p(VALUE mod) { return INT2BOOL(SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE); }
static VALUE eventqueue_grab(VALUE self) { return INT2BOOL(SDL_WM_GrabInput(SDL_GRAB_QUERY)==SDL_GRAB_ON); }
MDynamicAudioNormalizer_Handle* MDYNAMICAUDIONORMALIZER_FUNCTION(createInstance)(const uint32_t channels, const uint32_t sampleRate, const uint32_t frameLenMsec, const uint32_t filterSize, const double peakValue, const double maxAmplification, const double targetRms, const double compressFactor, const int channelsCoupled, const int enableDCCorrection, const int altBoundaryMode, FILE *const logFile) { try { MDynamicAudioNormalizer *instance = new MDynamicAudioNormalizer(channels, sampleRate, frameLenMsec, filterSize, peakValue, maxAmplification, targetRms, compressFactor, INT2BOOL(channelsCoupled), INT2BOOL(enableDCCorrection), INT2BOOL(altBoundaryMode), logFile); if(instance->initialize()) { return reinterpret_cast<MDynamicAudioNormalizer_Handle*>(instance); } else { delete instance; return NULL; } } catch(...) { return NULL; } }
VALUE sDLEvent2RubyEvent(SDL_Event* event) { VALUE newEvent=Qnil; int hx,hy; switch(event->type){ case SDL_ACTIVEEVENT: newEvent=rb_funcall(classActiveEvent, id_new, 0); rb_iv_set(newEvent, "@gain", UINT2NUM(event->active.gain)); rb_iv_set(newEvent, "@state", UINT2NUM(event->active.state)); break; case SDL_KEYDOWN: newEvent=rb_funcall(classKeyDownEvent, id_new, 0); rb_iv_set(newEvent, "@key", UINT2NUM(event->key.keysym.sym)); rb_iv_set(newEvent, "@mod", UINT2NUM(event->key.keysym.mod)); rb_iv_set(newEvent, "@unicode", UINT2NUM(event->key.keysym.unicode)); break; case SDL_KEYUP: newEvent=rb_funcall(classKeyUpEvent, id_new, 0); rb_iv_set(newEvent, "@key", UINT2NUM(event->key.keysym.sym)); rb_iv_set(newEvent, "@mod", UINT2NUM(event->key.keysym.mod)); rb_iv_set(newEvent, "@unicode", UINT2NUM(event->key.keysym.unicode)); break; case SDL_QUIT: newEvent=rb_funcall(classQuitEvent, id_new, 0); break; case SDL_MOUSEMOTION: newEvent=rb_funcall(classMouseMotionEvent, id_new, 0); rb_iv_set(newEvent, "@pos", rb_ary_new3(2, INT2NUM(event->motion.x), INT2NUM(event->motion.y))); rb_iv_set(newEvent, "@rel", rb_ary_new3(2, INT2NUM(event->motion.xrel), INT2NUM(event->motion.yrel))); rb_iv_set(newEvent, "@button", rb_ary_new3(3, INT2BOOL(event->motion.state&SDL_BUTTON(1)), INT2BOOL(event->motion.state&SDL_BUTTON(2)), INT2BOOL(event->motion.state&SDL_BUTTON(3)))); break; case SDL_MOUSEBUTTONDOWN: newEvent=rb_funcall(classMouseButtonDownEvent, id_new, 0); rb_iv_set(newEvent, "@pos", rb_ary_new3(2, INT2NUM(event->button.x), INT2NUM(event->button.y))); rb_iv_set(newEvent, "@button", UINT2NUM(event->button.button)); break; case SDL_MOUSEBUTTONUP: newEvent=rb_funcall(classMouseButtonUpEvent, id_new, 0); rb_iv_set(newEvent, "@pos", rb_ary_new3(2, INT2NUM(event->button.x), INT2NUM(event->button.y))); rb_iv_set(newEvent, "@button", UINT2NUM(event->button.button)); break; case SDL_JOYAXISMOTION: newEvent=rb_funcall(classJoyAxisEvent, id_new, 0); rb_iv_set(newEvent, "@id", INT2NUM(event->jaxis.which)); rb_iv_set(newEvent, "@value", DBL2NUM(event->jaxis.value/32767.0)); rb_iv_set(newEvent, "@axis", INT2NUM(event->jaxis.axis)); break; case SDL_JOYBALLMOTION: newEvent=rb_funcall(classJoyBallEvent, id_new, 0); rb_iv_set(newEvent, "@id", INT2NUM(event->jball.which)); rb_iv_set(newEvent, "@ball", INT2NUM(event->jball.ball)); rb_iv_set(newEvent, "@rel", rb_ary_new3(2, INT2NUM(event->jball.xrel), INT2NUM(event->jball.yrel))); break; case SDL_JOYHATMOTION: newEvent=rb_funcall(classJoyHatEvent, id_new, 0); rb_iv_set(newEvent, "@id", INT2NUM(event->jhat.which)); rb_iv_set(newEvent, "@hat", INT2NUM(event->jhat.hat)); hx = hy = 0; if(event->jhat.value&SDL_HAT_UP) hy = 1; else if(event->jhat.value&SDL_HAT_DOWN) hy = -1; if(event->jhat.value&SDL_HAT_LEFT) hx = 1; else if(event->jhat.value&SDL_HAT_LEFT) hx = -1; rb_iv_set(newEvent, "@value", rb_ary_new3(2, INT2NUM(hx), INT2NUM(hy))); break; case SDL_JOYBUTTONUP: newEvent=rb_funcall(classJoyButtonUpEvent, id_new, 0); rb_iv_set(newEvent, "@id", INT2NUM(event->jbutton.which)); rb_iv_set(newEvent, "@button", INT2NUM(event->jbutton.button)); break; case SDL_JOYBUTTONDOWN: newEvent=rb_funcall(classJoyButtonDownEvent, id_new, 0); rb_iv_set(newEvent, "@id", INT2NUM(event->jbutton.which)); rb_iv_set(newEvent, "@button", INT2NUM(event->jbutton.button)); break; case SDL_VIDEORESIZE: { /* automatically call DisplaySurface.new to fix the clipping */ VALUE newDS, oldDS = currentDisplaySurface; newDS = rb_funcall(classDisplaySurface, id_new, currDSnumargs, rb_ary_new3(2, UINT2NUM(event->resize.w), UINT2NUM(event->resize.h)), currDSflags, currDSdepth); /* keep the old object */ currentDisplaySurface = oldDS; /* replace its SDL_Surface pointer with the new one */ DATA_PTR(oldDS) = DATA_PTR(newDS); newEvent=rb_funcall(classResizeEvent, id_new, 0); rb_iv_set(newEvent, "@size", rb_ary_new3(2, UINT2NUM(event->resize.w), UINT2NUM(event->resize.h))); break; } case SDL_VIDEOEXPOSE: newEvent=rb_funcall(classVideoExposeEvent, id_new, 0); break; case RUDL_TIMEREVENT: newEvent=rb_funcall(classTimerEvent, id_new, 0); rb_iv_set(newEvent, "@id", INT2NUM(event->user.code)); break; case RUDL_ENDMUSICEVENT: newEvent=rb_funcall(classEndOfMusicEvent, id_new, 0); break; /* else if(event->type > USEREVENT && event->type < NUMEVENTS){ newEvent=rb_funcall(classEvent, id_new, 0); rb_iv_set(newEvent, "@code", INT2NUM(event->user.code)); rb_iv_set(newEvent, "@data1", INT2NUM(event->user.data1)); rb_iv_set(newEvent, "@data2", INT2NUM(event->user.data2)); }*/ } RUDL_ASSERT(newEvent!=Qnil, "Unknown event received from SDL (SDL too new for this RUDL version?)"); return newEvent; }
/* * call-seq: * extended -> bool * Return the type of descripters * false: basic descriptors (64 elements each) * true : exteneded descriptors (128 elements each) */ VALUE rb_get_extended(VALUE self) { return INT2BOOL(CVSURFPARAMS(self)->extended); }