Esempio n. 1
0
/*
 * call-seq:
 *   image[rect] -> WX::Image or nil
 *   image[x,y] -> WX::Color or nil
 *
 * if giving a WX::Rect, return a sub image of the given place
 * if giving x and y, return the color of the given position or nil when out of range
 * ===Arguments
 * * x and y are Integer
 * * rect is a WX::Rect
 * ===Return value
 * WX::Image, WX::Color or nil
 * === Exceptions
 * [ArgumentError]
 * * rect does have negative size
 * * rect does not fit into the Size of the Image
*/
DLL_LOCAL VALUE _get(int argc,VALUE *argv,VALUE self)
{
	VALUE vx,vy;
	rb_scan_args(argc, argv, "11",&vx,&vy);
	if(_self->IsOk())
	{
		if(NIL_P(vy))
			return _getSubImage(self, vy);

		int x,y;
		x = RB_NUM2UINT(vx);
		y = RB_NUM2UINT(vy);

		if(!check_inside(x,y, _self->GetSize()))
			return Qnil;

		unsigned char red,green,blue,alpha;
		red = _self->GetRed(x,y);
		green = _self->GetGreen(x,y);
		blue = _self->GetBlue(x,y);
		if(_self->HasAlpha())
			alpha = _self->GetAlpha(x,y);
		else
			alpha = wxALPHA_OPAQUE;
		return wrap(new wxColor(red,green,blue,alpha));
	}else
		return Qnil;
}
Esempio n. 2
0
/*
 * call-seq:
 *   insert_stretch_spacer(pos,[prop])
 *
 * inserts a new stretch spacer WX::Sizer::Item
 * ===Arguments
 * * pos is Integer
 * * prop is a Integer
 * ===Return value
 * WX::Sizer::Item
 */
DLL_LOCAL VALUE _insert_stretch_spacer(int argc,VALUE *argv,VALUE self)
{
	VALUE idx,prop;
	rb_scan_args(argc, argv, "11",&idx,&prop);

	return wrap(_self->InsertStretchSpacer(RB_NUM2UINT(idx),NIL_P(prop) ? 1 : RB_NUM2INT(prop)));
}
Esempio n. 3
0
	wxString GetTip() {
		if(rb_respond_to(mRuby,rb_intern("to_a"))){

			if(m_currentTip >= RB_NUM2UINT(rb_funcall(mRuby,rb_intern("size"),0)))
				m_currentTip = 0;
			return unwrap<wxString>(rb_funcall(mRuby,rb_intern("[]"),1,RB_UINT2NUM(m_currentTip++)));
		}else
			return unwrap<wxString>(mRuby);
	}
Esempio n. 4
0
/*
 * call-seq:
 *   marshal_load(array) -> self
 *
 * Provides marshalling support for use by the Marshal library.
 *
 *
 */
DLL_LOCAL VALUE _marshal_load(VALUE self,VALUE data)
{
	data = rb_Array(data);

	VALUE tmp = RARRAY_AREF(data,3);
	unsigned char* alpha = NULL;
	if(!NIL_P(tmp))
		alpha = (unsigned char*)StringValuePtr(tmp);

	VALUE val = RARRAY_AREF(data,2);
	_self->Create(
		RB_NUM2UINT(RARRAY_AREF(data,0)),RB_NUM2UINT(RARRAY_AREF(data,1)),
		(unsigned char*)StringValuePtr(val),alpha);

	_setMask(self,RARRAY_AREF(data,4));

#if wxUSE_PALETTE
	_setPalette(self,RARRAY_AREF(data,5));
#endif

	return self;
}
Esempio n. 5
0
/*
 *  call-seq:
 *     WIN32OLE_VARIANT.array(ary, vt)
 *
 *  Returns Ruby object wrapping OLE variant whose variant type is VT_ARRAY.
 *  The first argument should be Array object which specifies dimensions
 *  and each size of dimensions of OLE array.
 *  The second argument specifies variant type of the element of OLE array.
 *
 *  The following create 2 dimensions OLE array. The first dimensions size
 *  is 3, and the second is 4.
 *
 *     ole_ary = WIN32OLE_VARIANT.array([3,4], VT_I4)
 *     ruby_ary = ole_ary.value # => [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
 *
 */
static VALUE
folevariant_s_array(VALUE klass, VALUE elems, VALUE vvt)
{
    VALUE obj = Qnil;
    VARTYPE vt;
    struct olevariantdata *pvar;
    SAFEARRAYBOUND *psab = NULL;
    SAFEARRAY *psa = NULL;
    UINT dim = 0;
    UINT i = 0;

    ole_initialize();

    vt = RB_NUM2UINT(vvt);
    vt = (vt | VT_ARRAY);
    Check_Type(elems, T_ARRAY);
    obj = folevariant_s_allocate(klass);

    TypedData_Get_Struct(obj, struct olevariantdata, &olevariant_datatype, pvar);
    dim = RARRAY_LEN(elems);

    psab = ALLOC_N(SAFEARRAYBOUND, dim);

    if(!psab) {
        rb_raise(rb_eRuntimeError, "memory allocation error");
    }

    for (i = 0; i < dim; i++) {
        psab[i].cElements = RB_FIX2INT(rb_ary_entry(elems, i));
        psab[i].lLbound = 0;
    }

    psa = SafeArrayCreate((VARTYPE)(vt & VT_TYPEMASK), dim, psab);
    if (psa == NULL) {
        if (psab) free(psab);
        rb_raise(rb_eRuntimeError, "memory allocation error(SafeArrayCreate)");
    }

    V_VT(&(pvar->var)) = vt;
    if (vt & VT_BYREF) {
        V_VT(&(pvar->realvar)) = (vt & ~VT_BYREF);
        V_ARRAY(&(pvar->realvar)) = psa;
        V_ARRAYREF(&(pvar->var)) = &(V_ARRAY(&(pvar->realvar)));
    } else {
        V_ARRAY(&(pvar->var)) = psa;
    }
    if (psab) free(psab);
    return obj;
}
Esempio n. 6
0
/*
 * call-seq:
 *   image[x,y]= WX::Color or WX::Image or WX::Bitmap
 *   image[pos]= WX::Color or WX::Image or WX::Bitmap
 *   image[rect]= WX::Color
 *
 * if giving x and y or pos, and as value a color, sets the color at the given position
 * if giving x and y or pos, and an image or bitmap does paste it at the given position
 * if giving a WX::Rect, fill the color at the place with the given one
 * ===Arguments
 * * x and y are Integer
 * * pos is a WX::Point
 * * rect is a WX::Rect
 *
 * === Exceptions
 * [ArgumentError]
 * * rect does not fit into the Size of the Image
 */
DLL_LOCAL VALUE _set(int argc,VALUE *argv,VALUE self)
{
	VALUE vx,vy,value;
	rb_scan_args(argc, argv, "21",&vx,&vy,&value);

	rb_check_frozen(self);

	if(_self->IsOk())
	{
		if(NIL_P(value)) {
			if(is_wrapable<wxRect>(vx)) {
				wxColor c(unwrap<wxColor>(vy));
				wxSize size(_self->GetSize());
				wxRect vrect;

				if(check_contain_rect(_GetSize(self), size, vx, vrect))
				{
					_self->SetRGB(vrect,c.Red(),c.Green(),c.Blue());
					if(_self->HasAlpha()) {
						for(int i = vrect.x; i <= vrect.GetRight(); ++i)
							for(int j = vrect.y; j <= vrect.GetBottom(); ++j)
								if(check_inside(i, j, size))
									_self->SetAlpha(i,j,c.Alpha());
					}
				}
			} else {
				wxPoint vpoint(unwrap<wxPoint>(vx));
				set_at_pos(vpoint.x, vpoint.y, _self, vy);
			}
		} else {
			set_at_pos(RB_NUM2UINT(vx), RB_NUM2UINT(vy), _self, value);
		}
	}

	return NIL_P(value) ? value : vy;
}
Esempio n. 7
0
/*
 * call-seq:
 *   insert_spacer(pos, size)
 *
 * inserts a new spacer WX::Sizer::Item into the given position.
 * ===Arguments
 * * pos is Integer
 * * size is a Integer
 * ===Return value
 * WX::Sizer::Item
 */
DLL_LOCAL VALUE _insert_spacer(VALUE self,VALUE idx,VALUE size)
{
	return wrap(_self->InsertSpacer(RB_NUM2UINT(idx),RB_NUM2INT(size)));
}
Esempio n. 8
0
	RubyTipProvider(VALUE obj,VALUE i) : wxTipProvider(RB_NUM2UINT(i)), mRuby(obj) {}