2008-08-19 11:01:28 -04:00
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
trackbar.cpp -
|
|
|
|
|
|
|
|
$Author: lsxi $
|
|
|
|
|
|
|
|
Copyright (C) 2005 Masakazu Yonekura
|
|
|
|
|
|
|
|
************************************************************/
|
2011-05-04 11:45:42 -04:00
|
|
|
#include "trackbar.h"
|
2008-08-19 11:01:28 -04:00
|
|
|
/*
|
|
|
|
* 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() {
|
2008-08-19 11:01:28 -04:00
|
|
|
return rb_klass;
|
|
|
|
}
|
|
|
|
|
2011-05-04 11:45:42 -04:00
|
|
|
void define_ruby_class() {
|
|
|
|
if (rb_klass)
|
2008-08-19 11:01:28 -04:00
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* opencv = rb_define_module("OpenCV");
|
2012-02-05 05:08:46 -05:00
|
|
|
* GUI = rb_define_module_under(opencv, "GUI");
|
2008-08-19 11:01:28 -04:00
|
|
|
*
|
|
|
|
* 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);
|
2011-05-14 15:09:00 -04:00
|
|
|
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
2008-08-19 11:01:28 -04:00
|
|
|
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) {
|
2008-08-19 11:01:28 -04:00
|
|
|
Trackbar *ptr;
|
2012-02-05 05:08:46 -05:00
|
|
|
return Data_Make_Struct(klass, Trackbar, trackbar_mark, trackbar_free, ptr);
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
|
|
|
|
2011-05-04 11:45:42 -04:00
|
|
|
void trackbar_mark(void *ptr) {
|
2008-08-19 11:01:28 -04:00
|
|
|
rb_gc_mark(((Trackbar*)ptr)->block);
|
|
|
|
}
|
|
|
|
|
2012-02-05 05:08:46 -05:00
|
|
|
void trackbar_free(void *ptr) {
|
|
|
|
Trackbar *trackbar = (Trackbar*)ptr;
|
|
|
|
free(trackbar->name);
|
|
|
|
free(trackbar);
|
|
|
|
}
|
|
|
|
|
2008-08-19 11:01:28 -04:00
|
|
|
/*
|
|
|
|
* 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) {
|
2008-08-19 11:01:28 -04:00
|
|
|
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.");
|
2008-08-19 11:01:28 -04:00
|
|
|
Check_Type(name, T_STRING);
|
|
|
|
Trackbar *trackbar = TRACKBAR(self);
|
2012-02-05 04:45:54 -05:00
|
|
|
trackbar->name = strcpy(ALLOC_N(char, RSTRING_LEN(name) + 1), StringValueCStr(name));
|
2008-08-19 11:01:28 -04:00
|
|
|
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) {
|
2008-08-19 11:01:28 -04:00
|
|
|
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) {
|
2011-07-23 06:51:58 -04:00
|
|
|
return INT2NUM(TRACKBAR(self)->maxval);
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the value of this trackbar.
|
|
|
|
*/
|
2011-05-04 11:45:42 -04:00
|
|
|
VALUE rb_value(VALUE self) {
|
2011-07-23 06:51:58 -04:00
|
|
|
return INT2NUM(TRACKBAR(self)->val);
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2008-08-19 11:01:28 -04:00
|
|
|
TRACKBAR(self)->val = NUM2INT(val);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
__NAMESPACE_END_TRACKBAR
|
|
|
|
__NAMESPACE_END_GUI
|
|
|
|
__NAMESPACE_END_OPENCV
|
|
|
|
|