VALUE rb_ScrollConsoleScreenBuffer( VALUE self, VALUE hConsoleOutput, VALUE left1, VALUE top1, VALUE right1, VALUE bottom1, VALUE col, VALUE row, VALUE cChar, VALUE attr, VALUE left2, VALUE top2, VALUE right2, VALUE bottom2) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); CHAR_INFO fill; COORD origin; SMALL_RECT scroll, clip; scroll.Left = NUM2INT( left1 ); scroll.Right = NUM2INT( right1 ); scroll.Top = NUM2INT( top1 ); scroll.Bottom = NUM2INT( bottom1 ); clip.Left = NUM2INT( left2 ); clip.Right = NUM2INT( right2 ); clip.Top = NUM2INT( top2 ); clip.Bottom = NUM2INT( bottom2 ); #ifdef UNICODE fill.Char.UnicodeChar = NUM2CHR( cChar ); #else fill.Char.AsciiChar = NUM2CHR( cChar ); #endif fill.Attributes = NUM2INT(attr); origin.X = NUM2UINT( col ); origin.Y = NUM2UINT( row ); if ( ScrollConsoleScreenBuffer( handle, &scroll, &clip, origin, &fill ) ) return INT2FIX(1); return rb_getWin32Error(); }
sf::Color rbColor::ToSFML( VALUE aColor ) { aColor = rbColor::ToRuby( aColor ); sf::Uint8 r = NUM2CHR( GetRed( aColor ) ); sf::Uint8 g = NUM2CHR( GetGreen( aColor ) ); sf::Uint8 b = NUM2CHR( GetBlue( aColor ) ); sf::Uint8 a = NUM2CHR( GetAlpha( aColor ) ); return sf::Color( r, g, b, a ); }
static VALUE gbp_initialize(VALUE self, VALUE port) { gbp_com *gbp; short int status; Data_Get_Struct(self, gbp_com, gbp); if (TYPE(port) == T_STRING) { if (gbp->tty != NULL) free(gbp->tty); gbp->tty = StringValuePtr(port); status = TL_Open_TTY(gbp->tty, 9600); set_max_speed(); /* TL_Close(); status = TL_Open_TTY(gbp->tty, 38400); */ } else { gbp->ncom = NUM2CHR(port); status = TL_Open(gbp->ncom, gbp->vcom); } if (status != NO_ERR) { gbp->in_use = FALSE; } else { gbp->in_use = TRUE; } TL_SetTimeOut(gbp->timeout); return self; }
static VALUE r_sem_put_char(VALUE self, VALUE data) { static char c; c = NUM2CHR(data); *shm = c; return CHR2FIX(c); }
static VALUE bug_str_cstr_unterm(VALUE str, VALUE c) { long len; rb_str_modify(str); len = RSTRING_LEN(str); RSTRING_PTR(str)[len] = NUM2CHR(c); return str; }
void Map::draw() const { int i, j; int maxX = map_offset_x + viewport_width; int maxY = map_offset_y + viewport_height; Display::lock(); for (j = map_offset_y; j < maxY; ++j) { for (i = map_offset_x; i < maxX; ++i) { VALUE t = tile(i, j); if (t == Qnil) continue; unsigned char code; uint colour; VALUE u = rb_iv_get(t, "@unit"); if (u != Qnil) { // Draw the unit. code = NUM2CHR(rb_iv_get(u, "@code")); colour = NUM2UINT(rb_iv_get(u, "@colour")); } else { VALUE items = rb_iv_get(t, "@items"); if (RARRAY(items)->len > 0) { // Draw an item. code = 'i'; colour = 0x800000; } else { // Draw the tile. code = NUM2CHR(rb_iv_get(t, "@code")); colour = NUM2UINT(rb_iv_get(t, "@colour")); } } Display::set_colour(colour); Display::draw_glyph(tile_size*(i - map_offset_x), tile_size*(j - map_offset_y), code); } } Display::unlock(); }
/* * call-seq: * view.set_uint8(2, 2) => nil * * Sets an unsigned int8 value at a given offset. * * === Examples * buf = ArrayBuffer.new(100) => ArrayBuffer * view = DataView.new(buf) => DataView * view.set_uint8(2, 5) => nil * */ static VALUE rb_data_view_set_uint8(VALUE obj, VALUE offset_, VALUE item_) { int argc; VALUE argv[3]; argc = 3; argv[0] = offset_; argv[1] = item_; argv[2] = Qfalse; DataViewAset(obj); rb_type_array_set_uint8(buf->buf, index, (unsigned char)NUM2CHR(item), little_endian); return Qnil; }
VALUE rb_FillConsoleOutputCharacter( VALUE self, VALUE hConsoleOutput, VALUE cCharacter, VALUE nLength, VALUE col, VALUE row ) { HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) ); DWORD numChars; COORD dwWriteCoord; dwWriteCoord.X = NUM2UINT(col); dwWriteCoord.Y = NUM2UINT(row); if (FillConsoleOutputCharacter( handle, NUM2CHR(cCharacter), NUM2ULONG(nLength), dwWriteCoord, &numChars )) return ULONG2NUM(numChars); return rb_getWin32Error(); }
/* call-seq: * window.setIcon( width, height, pixels ) * * Change the window's icon. * * pixels must be an array of width x height pixels in 32-bits RGBA format. In the ruby binding the array will be * flattened so you can have array's up to 3 dimensions(or more) to represent each pixel component. The size of the * array will be assumed to be width * height * 4. * * The OS default icon is used by default. * * Usage example: * pixels = [ * [[255, 0, 0, 255], [0, 0, 255, 255]], * [[0, 255, 0, 255], [0, 0, 0, 255]] * ] * * window.setIcon( 2, 2, pixels ) */ static VALUE Window_SetIcon( VALUE self, VALUE aWidth, VALUE aHeight, VALUE somePixels ) { const unsigned int rawWidth = FIX2UINT( aWidth ); const unsigned int rawHeight = FIX2UINT( aHeight ); VALIDATE_CLASS( somePixels, rb_cArray, "pixels" ); const unsigned long dataSize = rawWidth * rawHeight * 4; sf::Uint8 * const tempData = new sf::Uint8[dataSize]; VALUE pixels = rb_funcall( somePixels, rb_intern("flatten"), 0 ); for(unsigned long index = 0; index < dataSize; index++) { sf::Uint8 val = NUM2CHR( rb_ary_entry( pixels, index ) ); tempData[index] = val; } sf::Window *object = NULL; Data_Get_Struct( self, sf::Window, object ); object->SetIcon( rawWidth, rawHeight, tempData ); delete[] tempData; return Qnil; }
/* * This function computes house cusps, ascendant, midheaven, etc * http://www.astro.com/swisseph/swephprg.htm#_Toc283735486 int swe_houses( double tjd_ut, // Julian day number, UT double geolat, // geographic latitude, in degrees double geolon, // geographic longitude, in degrees (eastern longitude is positive, western longitude is negative, northern latitude is positive, southern latitude is negative int hsys, // house method, ascii code of one of the letters PKORCAEVXHTBG double *cusps, // array for 13 doubles double *ascmc // array for 10 doubles ); * House method codes... * ‘P’ = Placidus * ‘K’ = Koch * ‘O’ = Porphyrius * ‘R’ = Regiomontanus * ‘C’ = Campanus * ‘A’ or ‘E’ = Equal (cusp 1 is Ascendant) * ‘V’ = Vehlow equal (Asc. in middle of house 1) * ‘W’ = Whole sign * ‘X’ = axial rotation system * ‘H’ = azimuthal or horizontal system * ‘T’ = Polich/Page (“topocentric” system) * ‘B’ = Alcabitus * ‘M’ = Morinus * ‘U’ = Krusinski-Pisa * ‘G’ = Gauquelin sectors */ static VALUE t_swe_houses(VALUE self, VALUE julian_day, VALUE latitude, VALUE longitude, VALUE house_system) { double cusps[13]; double ascmc[10]; char serr[AS_MAXCH]; VALUE arr = rb_ary_new(); int id_push = rb_intern("push"); int i =0; if ( swe_houses(NUM2DBL(julian_day), NUM2DBL(latitude), NUM2DBL(longitude), NUM2CHR(house_system), cusps, ascmc) < 0 ) rb_raise (rb_eRuntimeError, serr); for ( i = 0; i < 13; i++) rb_funcall(arr, id_push, 1, rb_float_new(cusps[i])); for ( i = 0; i < 10; i++) rb_funcall(arr, id_push, 1, rb_float_new(ascmc[i])); return arr; }
static VALUE rg_set_markup(int argc, VALUE *argv, VALUE self) { VALUE markup, accel_marker; gunichar accel_char = 0; rb_scan_args(argc, argv, "11", &markup, &accel_marker); StringValue(markup); if (NIL_P(accel_marker)){ pango_layout_set_markup(_SELF(self), RSTRING_PTR(markup), RSTRING_LEN(markup)); } else { pango_layout_set_markup_with_accel(_SELF(self), RSTRING_PTR(markup), RSTRING_LEN(markup), NUM2CHR(accel_marker), &accel_char); } return CHR2FIX(accel_char); }
/* This method is from rbpangoattribute.c */ static VALUE rg_s_parse_markup(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self) { VALUE markup_text, accel_marker; PangoAttrList *pattr_list; gchar* gtext; gunichar accel_char; GError *error = NULL; gboolean ret; char c; VALUE text = Qnil; VALUE attr_list = Qnil; rb_scan_args(argc, argv, "11", &markup_text, &accel_marker); if (NIL_P(markup_text)) rb_raise(rb_eRuntimeError, "1st argument can't accept nil"); StringValue(markup_text); ret = pango_parse_markup(RSTRING_PTR(markup_text), RSTRING_LEN(markup_text), NIL_P(accel_marker) ? 0 : NUM2CHR(accel_marker), &pattr_list, >ext, &accel_char, &error); if (!ret) RAISE_GERROR(error); if (pattr_list){ attr_list = PANGOATTRLIST2RVAL(pattr_list); pango_attr_list_unref(pattr_list); } c = (char)accel_char; if (text){ text = CSTR2RVAL(gtext); g_free(gtext); } return rb_ary_new3(3, attr_list, text, accel_char ? rb_str_new(&c, 1) : Qnil); }
static void ole_val2ptr_variant(VALUE val, VARIANT *var) { switch (TYPE(val)) { case T_STRING: if (V_VT(var) == (VT_BSTR | VT_BYREF)) { *V_BSTRREF(var) = ole_vstr2wc(val); } break; case T_FIXNUM: switch(V_VT(var)) { case (VT_UI1 | VT_BYREF) : *V_UI1REF(var) = NUM2CHR(val); break; case (VT_I2 | VT_BYREF) : *V_I2REF(var) = (short)NUM2INT(val); break; case (VT_I4 | VT_BYREF) : *V_I4REF(var) = NUM2INT(val); break; case (VT_R4 | VT_BYREF) : *V_R4REF(var) = (float)NUM2INT(val); break; case (VT_R8 | VT_BYREF) : *V_R8REF(var) = NUM2INT(val); break; default: break; } break; case T_FLOAT: switch(V_VT(var)) { case (VT_I2 | VT_BYREF) : *V_I2REF(var) = (short)NUM2INT(val); break; case (VT_I4 | VT_BYREF) : *V_I4REF(var) = NUM2INT(val); break; case (VT_R4 | VT_BYREF) : *V_R4REF(var) = (float)NUM2DBL(val); break; case (VT_R8 | VT_BYREF) : *V_R8REF(var) = NUM2DBL(val); break; default: break; } break; case T_BIGNUM: if (V_VT(var) == (VT_R8 | VT_BYREF)) { *V_R8REF(var) = rb_big2dbl(val); } break; case T_TRUE: if (V_VT(var) == (VT_BOOL | VT_BYREF)) { *V_BOOLREF(var) = VARIANT_TRUE; } break; case T_FALSE: if (V_VT(var) == (VT_BOOL | VT_BYREF)) { *V_BOOLREF(var) = VARIANT_FALSE; } break; default: break; } }
static VALUE numeric_spec_NUM2CHR(VALUE self, VALUE value) { return INT2FIX(NUM2CHR(value)); }
VALUE rb_cFloat32Array; VALUE rb_cFloat64Array; VALUE rb_cStructArray; VALUE rb_cStructType; static ID rb_type_array_intern_aget; static ID rb_type_array_intern_aset; static ID rb_type_array_intern_superclass; /* * :nodoc: * Coerces a Ruby object to an int8 at a given offset, according to host endianness. * */ DefineTypeArraySetter(int8, (signed char)NUM2CHR(item)); /* * :nodoc: * Defines operator functions for int8s at given offsets, according to host endianness. * */ DefineTypeArrayOperators(int8, signed char, TACHR2FIX(val)); DefineTypeArrayOperator(eql, ==, int8, signed char, (val == 0 ? Qfalse : Qtrue)); /* * :nodoc: * Coerces an int8 at a given offset to a Ruby object, according to host endianness. * */ DefineTypeArrayGetter(int8, signed char, TACHR2FIX(val));