1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00
ruby-opencv/ext/opencv/trackbar.cpp

116 lines
2.8 KiB
C++
Raw Normal View History

/************************************************************
trackbar.cpp -
$Author: lsxi $
Copyright (C) 2005 Masakazu Yonekura
************************************************************/
2011-05-04 11:45:42 -04:00
#include "trackbar.h"
/*
* Document-class: OpenCV::GUI::Trackbar
*
* Simple Trackbar wedget. OpenCV::GUI::Window can treat trackbar.
* Trackbar can treat only positive-integer value.
*/
__NAMESPACE_BEGIN_OPENCV
__NAMESPACE_BEGIN_GUI
__NAMESPACE_BEGIN_TRACKBAR
VALUE rb_klass;
2011-05-04 11:45:42 -04:00
VALUE rb_class() {
return rb_klass;
}
2011-05-04 11:45:42 -04:00
void define_ruby_class() {
if (rb_klass)
return;
/*
* opencv = rb_define_module("OpenCV");
* GUI = rb_define_module_under(opencv, "GUI");
*
* note: this comment is used by rdoc.
*/
VALUE GUI = rb_module_GUI();
rb_klass = rb_define_class_under(GUI, "Trackbar", rb_cObject);
rb_define_alloc_func(rb_klass, rb_allocate);
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
rb_define_method(rb_klass, "name", RUBY_METHOD_FUNC(rb_name), 0);
rb_define_method(rb_klass, "max", RUBY_METHOD_FUNC(rb_max), 0);
rb_define_method(rb_klass, "value", RUBY_METHOD_FUNC(rb_value), 0);
rb_define_method(rb_klass, "value=", RUBY_METHOD_FUNC(rb_set_value), 1);
}
2011-05-04 11:45:42 -04:00
VALUE rb_allocate(VALUE klass) {
Trackbar *ptr;
2011-05-04 11:45:42 -04:00
return Data_Make_Struct(klass, Trackbar, trackbar_mark, 0, ptr);
}
2011-05-04 11:45:42 -04:00
void trackbar_mark(void *ptr) {
rb_gc_mark(((Trackbar*)ptr)->block);
}
/*
* call-seq:
* new(<i>name,maxval[,val],&block</i>)
* new(<i>name,maxval[,val]</i>){|value| ... }
*
* Create new Trackbar.
* <i>name</i> should be String.
* <i>maxval</i> and <i>val</i> should be Fixnum.
* When Trackbar adjuster changed, block will be called.
*/
2011-05-04 11:45:42 -04:00
VALUE rb_initialize(int argc, VALUE *argv, VALUE self) {
VALUE name, maxval, val, block;
rb_scan_args(argc, argv, "21&", &name, &maxval, &val, &block);
2011-05-04 11:45:42 -04:00
if (NIL_P(block))
rb_raise(rb_eArgError, "block not given.");
Check_Type(name, T_STRING);
Trackbar *trackbar = TRACKBAR(self);
2010-12-29 13:39:15 -05:00
trackbar->name = strcpy(ALLOC_N(char, RSTRING_LEN(name)), StringValueCStr(name));
trackbar->maxval = NUM2INT(maxval);
trackbar->val = IF_INT(val, 0);
trackbar->block = block;
return self;
}
/*
* Return trackbar name.
*/
2011-05-04 11:45:42 -04:00
VALUE rb_name(VALUE self) {
return rb_str_new2(TRACKBAR(self)->name);
}
/*
* Return the maximum value that can be taken this trackbar.
*/
2011-05-04 11:45:42 -04:00
VALUE rb_max(VALUE self) {
return INT2NUM(TRACKBAR(self)->maxval);
}
/*
* Return the value of this trackbar.
*/
2011-05-04 11:45:42 -04:00
VALUE rb_value(VALUE self) {
return INT2NUM(TRACKBAR(self)->val);
}
/*
* call-seq:
* value = <i>val</i>
*
* Set trackbar value.
*/
2011-05-04 11:45:42 -04:00
VALUE rb_set_value(VALUE self, VALUE val) {
TRACKBAR(self)->val = NUM2INT(val);
return self;
}
__NAMESPACE_END_TRACKBAR
__NAMESPACE_END_GUI
__NAMESPACE_END_OPENCV