Class: RWin::Icon

Inherits:
Data
  • Object
show all
Defined in:
ext/rwin/rw_resources.c

Direct Known Subclasses

WR::Icon

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(v_bmmask, v_bmcolor) ⇒ Object

rb_define_singleton_method(cRwIcon, “_dump”, rwicon1__dump, -1);



517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'ext/rwin/rw_resources.c', line 517

static VALUE
rwicon_initialize(VALUE self, VALUE v_bmmask, VALUE v_bmcolor){
    RwBitmap *rbmask, *rbcolor;
    ICONINFO iinfo;
    RwIcon *ri = DATA_PTR(self);
    iinfo.fIcon = TRUE;
    iinfo.xHotspot = 0;
    iinfo.xHotspot = 0;
    RwBitmap_Data_Get_Struct(v_bmmask, rbmask);
    iinfo.hbmMask = rw_dib2ddb(rbmask);
    RwBitmap_Data_Get_Struct(v_bmcolor, rbcolor);
    iinfo.hbmColor = rw_dib2ddb(rbcolor);
    ri->hicon = CreateIconIndirect(&iinfo);
    if (!ri->hicon) rb_raise(rb_eRuntimeError, "failed to create icon");
    ri->shared = FALSE;
    return self;
}

Class Method Details

._load(str) ⇒ Object



741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# File 'ext/rwin/rw_resources.c', line 741

static VALUE
rwicon1__load(VALUE klass, VALUE str){
    int i;
    char *pstr = RSTRING_PTR(str);
    ICONDIR *idir = (ICONDIR*)pstr;
    VALUE ary = rb_ary_new();
    for(i=0; i < idir->idCount; i++){
	ICONDIRENTRY *idirent = (ICONDIRENTRY*)(pstr + sizeof(ICONDIR) + i*sizeof(ICONDIRENTRY));
	HICON hicon = rwicon1__load_core(pstr, idirent, idir->idType==1);
	if(hicon) {
	    RwIcon *ri;
	    VALUE robj;
	    robj = RwIcon_Data_Make_Struct(klass, ri);
	    ri->type = RcIcon;
	    ri->hicon = hicon;
	    Register_rsc(ri->hicon, robj);
	    rb_ary_push(ary, robj);
	} else rb_raise(rb_eRuntimeError, "Icon load failed.");
    }
    return ary;
}

.fromfile(*args) ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'ext/rwin/rw_resources.c', line 482

static VALUE
rwicon1_fromfile(int argc, VALUE* argv, VALUE klass){
    char abspath[RW_MAXPATH];
    RwIcon* ri;
    VALUE robj, fname, disired_x, disired_y;
    int dx, dy;
    rb_scan_args(argc, argv, "12", &fname, &disired_x, &disired_y);
    dx = NIL_P(disired_x) ? 0 : FIX2INT(disired_x);
    dy = NIL_P(disired_y) ? dx : FIX2INT(disired_y);
    robj = RwIcon_Data_Make_Struct(klass, ri);
    ri->type = RcIcon;
    rwconv2absolute_path(abspath, RSTRING_PTR(fname));
    ri->hicon = LoadImageA(NULL, abspath, IMAGE_ICON, dx, dy, LR_LOADFROMFILE);
    ri->shared = FALSE;
    if(!ri->hicon){
	rb_raise(rb_eRuntimeError, "Icon load failed(%s).", StringValuePtr(fname));
    }
    Register_rsc(ri->hicon, robj);
    return robj;
}

.fromresource(idicon) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'ext/rwin/rw_resources.c', line 503

static VALUE
rwicon1_fromrsrc(VALUE klass, VALUE idicon){
    RwIcon* ri;
    VALUE robj = RwIcon_Data_Make_Struct(klass, ri);
    ri->type = RcIcon;
    ri->hicon = LoadImage(hInstance, MAKEINTRESOURCE(FIX2INT(idicon)), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
    if(ri->hicon==NULL){
	rb_raise(rb_eRuntimeError, "Icon load failed from resource (%d, %d).", FIX2INT(idicon), (int)GetLastError());
    }
    ri->shared = FALSE;
    Register_rsc(ri->hicon, robj);
    return robj;
}

Instance Method Details

#_dump(*args) ⇒ Object



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'ext/rwin/rw_resources.c', line 627

static VALUE
rwicon__dump(int argc, VALUE *argv, VALUE self){
    VALUE robj, rstr;
    char *pstr;
    ICONINFO ii;
    ICONDIR *idir;
    ICONDIRENTRY *idirent;
    int clrdpth = argc>0 ? FIX2INT(argv[0]) : 24;
    RwIcon *ri = DATA_PTR(self);
    int ccalloc = sizeof(ICONDIR) + sizeof(ICONDIRENTRY);
    RW_CALLOC(pstr, ccalloc);
    GetIconInfo(ri->hicon, &ii);
    idir = (ICONDIR*)pstr;
    idir->idType = ii.fIcon ? 1 : 2;
    idir->idCount = 1;
    idirent = (ICONDIRENTRY*)(pstr+sizeof(ICONDIR));
    rstr = rwicon__dump_core(&ii, idirent, clrdpth);
    robj = rb_str_new(pstr, ccalloc);
    rb_str_cat(robj, RSTRING_PTR(rstr), RSTRING_LEN(rstr));
    return robj;
}

#_hiconObject



535
536
537
538
539
# File 'ext/rwin/rw_resources.c', line 535

static VALUE
rwicon_hicon(VALUE self){
    RwIcon *ri = DATA_PTR(self);
    return ULONG_PTR2NUM((ULONG_PTR)ri->hicon);
}

#disposeObject



541
542
543
544
545
546
547
548
549
550
# File 'ext/rwin/rw_resources.c', line 541

static VALUE
rwicon_dispose(VALUE self){
    RwIcon *ri = DATA_PTR(self);
    if (ri->hicon) {
	if(!ri->shared) DestroyIcon(ri->hicon);
	ri->hicon = NULL;
	return Qtrue;
    }
    return Qnil;
}

#to_bmpsObject



552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'ext/rwin/rw_resources.c', line 552

static VALUE
rwicon_to_bmps(VALUE self){
    ICONINFO iinfo;
    VALUE v_bmmask, v_bmcolor;
    RwIcon *ri = DATA_PTR(self);
    GetIconInfo(ri->hicon, &iinfo);
    v_bmmask = rwbitmap1_fromhandle_core(cRwBitmap, iinfo.hbmMask);
    v_bmcolor = iinfo.hbmColor ? rwbitmap1_fromhandle_core(cRwBitmap, iinfo.hbmColor) : Qnil;
    DeleteObject(iinfo.hbmMask);
    DeleteObject(iinfo.hbmColor);
    if(iinfo.fIcon) return rb_ary_new3(2, v_bmmask, v_bmcolor);
    return rb_ary_new3(4, v_bmmask, v_bmcolor, INT2FIX(iinfo.xHotspot), INT2FIX(iinfo.yHotspot));
}