void outLibDialog::outLib()
{
    QString merchantID = ui->comboBoxMerchant->currentText();
    QString storeID = ui->comboBoxStore->currentText();
    QString sql;
    QString num = ui->spinBox->text();
    QSqlQuery query;
    //更新merchantStore
    if(num.toInt() == ui->spinBox->maximum()){
        sql = "delete from merchantStore where storeNumber = '"+storeID+"' and merchantNumber = '"+merchantID+"';";
    }else{
        sql = "update merchantStore set number = number - "+num+" where storeNumber = '"+storeID+"' and merchantNumber = '"+merchantID+"';";
    }
    //更新store
    sql = sql + "update store set leftCap = leftCap + "+num+" where storeNumber = '"+storeID+"';";
    //更新goodsShelve
    if(!query.exec("select * from goodsshelve where merchantNumber = '"+merchantID+"'")){
        tips("错误","数据库出错");
        return;
    }

    if(query.size()){
        sql = sql + "update goodsShelve set number = number +"+num+" where merchantNumber = '"+merchantID+"';";
    }
    else{
        sql = sql + "insert into goodsShelve values('"+merchantID+"','"+num+"');";
    }
    if(!query.exec(sql)){
        tips("错误","数据库出错");
        return;
    }
    tips("提示","出库成功");
    this->accept();
}
outLibDialog::outLibDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::outLibDialog)
{
    ui->setupUi(this);
    this->setWindowTitle("出库");
    this->setWindowIcon(QIcon(":/SuperMarketManageSystem/img/supermarket.png"));
    //设置对话框大小
    this->setMaximumSize(307,284);
    this->setMinimumSize(307,284);
    //设置对话框背景
    QPalette palette;
    palette.setBrush(QPalette::Background,QBrush(QPixmap(":/SuperMarketManageSystem/img/loginbk1.jpg").scaled(this->size())));
    this->setPalette(palette);
    QSqlQuery query("select storeNumber from store");
    if(!query.exec()){
        tips("错误","数据库出错");
        return;
    }
    ui->spinBox->setMinimum(1);
    ui->comboBoxStore->clear();
    while(query.next()){
        ui->comboBoxStore->addItem(query.value("storeNumber").toString());
    }
    QString sql = "select merchantNumber from merchantStore where storeNumber = '"+ui->comboBoxStore->currentText()+"'";
    ui->comboBoxMerchant->clear();
    if(!query.exec(sql)){
        tips("错误","数据库出错");
        return;
    }
    while(query.next()){
        ui->comboBoxMerchant->addItem(query.value("merchantNumber").toString());
    }
    connect(ui->comboBoxStore,ui->comboBoxStore->currentTextChanged,[=](QString sID){
        QSqlQuery query;
        QString sql = "select merchantNumber from merchantStore where storeNumber = '"+sID+"'";
        ui->comboBoxMerchant->clear();
        if(!query.exec(sql)){
            tips("错误","数据库出错");
            return;
        }
        while(query.next()){
            ui->comboBoxMerchant->addItem(query.value("merchantNumber").toString());
        }
    });
    connect(ui->comboBoxMerchant,ui->comboBoxMerchant->currentTextChanged,[=](QString sID){
        QSqlQuery query;
        QString sql = "select number from merchantStore where merchantNumber = '"+sID+"' and storeNumber = '"+ui->comboBoxStore->currentText()+"'";
        if(!query.exec(sql)){
            tips("错误","数据库出错");
            return;
        }
        if(query.next())ui->spinBox->setMaximum(query.value("number").toInt());
    });
    connect(ui->pushButtonYes,ui->pushButtonYes->clicked,this,outLib);
    connect(ui->pushButtonNo,ui->pushButtonNo->clicked,[=](bool){
        tips("提示","取消出库");
        this->reject();
    });
}
Exemple #3
0
void main(void)
 {
   Book tips("Jamsa’s C/C++ Programmer’s Bible", "Jamsa and Klander", "Jamsa Press", 49.95);
   Book diary("All My Secrets...", "Kris Jamsa", "None", 9.95);
   tips.show_book();
   diary.show_book();
 }
Exemple #4
0
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
	set_restore(false);
	window.set_click_dismiss(false);
	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

#ifdef DEBUG_TOOLTIP
	window.connect_signal<event::SDL_MOUSE_MOTION>(
			boost::bind(debug_tooltip, boost::ref(window), _3, _5),
			event::tdispatcher::front_child);
#endif

	/**** Set the version number ****/
	if(tcontrol* control
	   = find_widget<tcontrol>(&window, "revision_number", false, false)) {

		control->set_label(_("Version ") + game_config::revision);
	}
	window.canvas()[0].set_variable(
			"revision_number",
			variant(_("Version") + std::string(" ") + game_config::revision));

	/**** Set the tip of the day ****/
	tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);

	std::vector<ttip> tips(settings::get_tips());
	if(tips.empty()) {
		WRN_CF << "There are not tips of day available." << std::endl;
	}

	FOREACH(const AUTO & tip, tips)
	{

		string_map widget;
		std::map<std::string, string_map> page;

		widget["label"] = tip.text();
		widget["use_markup"] = "true";
		page["tip"] = widget;

		widget["label"] = tip.source();
		widget["use_markup"] = "true";
		page["source"] = widget;

		tip_pages.add_page(page);
	}
/** Read the file with the tips-of-the-day. */
void read_tips_of_day(config& tips_of_day)
{
	tips_of_day.clear();
	LOG_CF << "Loading tips of day\n";
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
		read(tips_of_day, *stream);
	} catch(config::error&) {
		ERR_CF << "Could not read data/hardwired/tips.cfg\n";
	}

	//We shuffle the tips after each initial loading.
	config::const_child_itors itors = tips_of_day.child_range("tip");
	if (itors.first != itors.second ) {
		std::vector<config> tips(itors.first, itors.second);
		std::random_shuffle(tips.begin(), tips.end());
		tips_of_day.clear();
		foreach (const config &tip, tips) {
			tips_of_day.add_child("tip", tip);
		}
Exemple #6
0
bool RimeWithWeaselHandler::_ShowMessage(weasel::Context& ctx, weasel::Status& status) {
	// show as auxiliary string
	std::wstring& tips(ctx.aux.str);
	bool show_icon = false;
	if (m_message_type == "deploy") {
		if (m_message_type == "start")
			tips = L"正在部署 RIME";
		else if (m_message_value == "success")
			tips = L"部署完成";
		else if (m_message_value == "failure")
			tips = L"有錯誤,請查看日誌 %TEMP%\\rime.weasel.*.INFO";
	}
	else if (m_message_type == "schema") {
		tips = /*L"【" + */status.schema_name/* + L"】"*/;
	}
	else if (m_message_type == "option") {
		if (m_message_value == "!ascii_mode")
			show_icon = true;  //tips = L"中文";
		else if (m_message_value == "ascii_mode")
			show_icon = true;  //tips = L"西文";
		else if (m_message_value == "!full_shape")
			tips = L"半角";
		else if (m_message_value == "full_shape")
			tips = L"全角";
		else if (m_message_value == "!ascii_punct")
			tips = L",。";
		else if (m_message_value == "ascii_punct")
			tips = L",.";
		else if (m_message_value == "!simplification")
			tips = L"漢字";
		else if (m_message_value == "simplification")
			tips = L"汉字";
	}
	if (tips.empty() && !show_icon)
		return m_ui->IsCountingDown();

	m_ui->Update(ctx, status);
	m_ui->ShowWithTimeout(1200 + 200 * tips.length());
	return true;
}
Exemple #7
0
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
	set_restore(false);
	window.set_click_dismiss(false);
	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

	/**** Set the version number ****/
	if(tcontrol* control
			= find_widget<tcontrol>(&window, "revision_number", false, false)) {

		control->set_label(_("Version ") + game_config::revision);
	}
	window.canvas()[0].set_variable("revision_number",
		variant(_("Version") + std::string(" ") + game_config::revision));

	/**** Set the tip of the day ****/
	tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);

	std::vector<ttip> tips(settings::get_tips());
	if(tips.empty()) {
		WRN_CF << "There are not tips of day available.\n";
	}

	foreach(const ttip& tip, tips) {

		string_map widget;
		std::map<std::string, string_map> page;

		widget["label"] = tip.text();
		widget["use_markup"] = "true";
		page["tip"] = widget;

		widget["label"] = tip.source();
		widget["use_markup"] = "true";
		page["source"] = widget;

		tip_pages.add_page(page);
	}
Exemple #8
0
/** Read the file with the tips-of-the-day. */
void read_tips_of_day(config& tips_of_day)
{
	tips_of_day.clear();
	LOG_CF << "Loading tips of day\n";
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
		read(tips_of_day, *stream);
	} catch(config::error&) {
		ERR_CF << "Could not read data/hardwired/tips.cfg\n";
	}

	//we shuffle the tips after each initial loading. We only shuffle if
	//the upload_log preference has been set. If it hasn't been set, it's the
	//user's first time playing since this feature has been added, so we'll
	//leave the tips in their default order, which will always contain a tip
	//regarding the upload log first, so the user sees it.
	config::const_child_itors itors = tips_of_day.child_range("tip");
	if (itors.first != itors.second && preferences::has_upload_log()) {
		std::vector<config> tips(itors.first, itors.second);
		std::random_shuffle(tips.begin(), tips.end());
		tips_of_day.clear();
		foreach (const config &tip, tips) {
			tips_of_day.add_child("tip", tip);
		}
// cbEVT_EDITOR_TOOLTIP
void CCManager::OnEditorTooltip(CodeBlocksEvent& event)
{
    event.Skip();

    if (wxGetKeyState(WXK_CONTROL))
        return;

    EditorBase* base = event.GetEditor();
    cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr;
    if (!ed || ed->IsContextMenuOpened())
        return;

    cbStyledTextCtrl* stc = ed->GetControl();
    cbCodeCompletionPlugin* ccPlugin = GetProviderFor(ed);
    int pos = stc->PositionFromPointClose(event.GetX(), event.GetY());
    if (!ccPlugin || pos < 0 || pos >= stc->GetLength())
    {
        if (stc->CallTipActive() && event.GetExtraLong() == 0 && m_CallTipActive == wxSCI_INVALID_POSITION)
            static_cast<wxScintilla*>(stc)->CallTipCancel();
        return;
    }

    int hlStart, hlEnd, argsPos;
    hlStart = hlEnd = argsPos = wxSCI_INVALID_POSITION;
    bool allowCallTip = true;
    const std::vector<cbCodeCompletionPlugin::CCToken>& tokens = ccPlugin->GetTokenAt(pos, ed, allowCallTip);
    std::set<wxString> uniqueTips;
    for (size_t i = 0; i < tokens.size(); ++i)
        uniqueTips.insert(tokens[i].displayName);
    wxStringVec tips(uniqueTips.begin(), uniqueTips.end());

    const int style = event.GetInt();
    if (!tips.empty())
    {
        const int tknStart = stc->WordStartPosition(pos, true);
        const int tknEnd   = stc->WordEndPosition(pos,   true);
        if (tknEnd - tknStart > 2)
        {
            for (size_t i = 0; i < tips[0].Length(); ++i)
            {
                size_t hlLoc = tips[0].find(stc->GetTextRange(tknStart, tknEnd), i);
                if (hlLoc == wxString::npos)
                    break;
                hlStart = hlLoc;
                hlEnd = hlStart + tknEnd - tknStart;
                if (   (hlStart > 0 && (tips[0][hlStart - 1] == wxT('_') || wxIsalpha(tips[0][hlStart - 1])))
                    || (hlEnd < static_cast<int>(tips[0].Length()) - 1 && (tips[0][hlEnd] == wxT('_') || wxIsalpha(tips[0][hlEnd]))) )
                {
                    i = hlEnd;
                    hlStart = hlEnd = wxSCI_INVALID_POSITION;
                }
                else
                    break;
            }
        }
    }
    else if (  allowCallTip
             && !(   stc->IsString(style)
                  || stc->IsComment(style)
                  || stc->IsCharacter(style)
                  || stc->IsPreprocessor(style) ) )
    {
        const int line = stc->LineFromPosition(pos);
        if (pos + 4 > stc->PositionFromLine(line) + (int)ed->GetLineIndentString(line).Length())
        {
            const CallTipVec& cTips = ccPlugin->GetCallTips(pos, style, ed, argsPos);
            for (size_t i = 0; i < cTips.size(); ++i)
                tips.push_back(cTips[i].tip);
            if (!tips.empty())
            {
                hlStart = cTips[0].hlStart;
                hlEnd   = cTips[0].hlEnd;
            }
        }
    }
    if (tips.empty())
    {
        if (stc->CallTipActive() && event.GetExtraLong() == 0 && m_CallTipActive == wxSCI_INVALID_POSITION)
            static_cast<wxScintilla*>(stc)->CallTipCancel();
    }
    else
    {
        DoShowTips(tips, stc, pos, argsPos, hlStart, hlEnd);
        event.SetExtraLong(1);
    }
    m_CallTipActive = wxSCI_INVALID_POSITION;
}
Exemple #10
0
void title_screen::pre_show(window& win)
{
	win.set_click_dismiss(false);
	win.set_enter_disabled(true);
	win.set_escape_disabled(true);

	// Each time the dialog shows, we set this to false
	redraw_background_ = false;

#ifdef DEBUG_TOOLTIP
	win.connect_signal<event::SDL_MOUSE_MOTION>(
			std::bind(debug_tooltip, std::ref(win), _3, _5),
			event::dispatcher::front_child);
#endif

	win.connect_signal<event::SDL_VIDEO_RESIZE>(std::bind(&title_screen::on_resize, this, std::ref(win)));

	//
	// General hotkeys
	//
	win.register_hotkey(hotkey::TITLE_SCREEN__RELOAD_WML, [](event::dispatcher& w, hotkey::HOTKEY_COMMAND) {
		dynamic_cast<window&>(w).set_retval(RELOAD_GAME_DATA);
		return true;
	});

	win.register_hotkey(hotkey::HOTKEY_FULLSCREEN, std::bind(fullscreen, std::ref(win.video())));
	win.register_hotkey(hotkey::LUA_CONSOLE, std::bind(&launch_lua_console, std::ref(win)));

	//
	// Background and logo images
	//
	if(game_config::images::game_title.empty()) {
		ERR_CF << "No title image defined" << std::endl;
	} 

	win.get_canvas()[0].set_variable("title_image", variant(game_config::images::game_title));

	if(game_config::images::game_title_background.empty()) {
		ERR_CF << "No title background image defined" << std::endl;
	}

	win.get_canvas()[0].set_variable("background_image", variant(game_config::images::game_title_background));

	find_widget<image>(&win, "logo-bg", false).set_image(game_config::images::game_logo_background);
	find_widget<image>(&win, "logo", false).set_image(game_config::images::game_logo);

	//
	// Version string
	//
	const std::string version_string = formatter() << ("Version") << " " << game_config::revision;

	if(label* version_label = find_widget<label>(&win, "revision_number", false, false)) {
		version_label->set_label(version_string);
	}

	win.get_canvas()[0].set_variable("revision_number", variant(version_string));

	//
	// Tip-of-the-day browser
	//
	multi_page& tip_pages = find_widget<multi_page>(&win, "tips", false);

	std::vector<game_tip> tips(settings::get_tips());
	if(tips.empty()) {
		WRN_CF << "There are no tips of day available." << std::endl;
	}

	for(const auto& tip : tips)	{
		string_map widget;
		std::map<std::string, string_map> page;

		widget["use_markup"] = "true";

		widget["label"] = tip.text();
		page.emplace("tip", widget);

		widget["label"] = tip.source();
		page.emplace("source", widget);

		tip_pages.add_page(page);
	}

	update_tip(win, true);

	register_button(win, "next_tip", hotkey::TITLE_SCREEN__NEXT_TIP,
		std::bind(&title_screen::update_tip, this, std::ref(win), true));
	register_button(win, "previous_tip", hotkey::TITLE_SCREEN__PREVIOUS_TIP,
		std::bind(&title_screen::update_tip, this, std::ref(win), false));

	//
	// Help
	//
	register_button(win, "help", hotkey::HOTKEY_HELP, [this](window&) {
		help::help_manager help_manager(&game_config_manager::get()->game_config());
		help::show_help(game_.video());
	});

	//
	// About
	//
	register_button(win, "about", hotkey::HOTKEY_NULL, std::bind(&game_version::display, std::ref(win.video())));

	//
	// Tutorial
	//
	register_button(win, "tutorial", hotkey::TITLE_SCREEN__TUTORIAL, [this](window& w) {
		game_.set_tutorial();
		w.set_retval(LAUNCH_GAME);
	});

	//
	// Campaign
	//
	register_button(win, "campaign", hotkey::TITLE_SCREEN__CAMPAIGN, [this](window& w) {
		try{
			if(game_.new_campaign()) {
				w.set_retval(LAUNCH_GAME);
			}
		} catch (const config::error& e) {
			gui2::show_error_message(game_.video(), e.what());
		}
	});

	//
	// Multiplayer
	//
	register_button(win, "multiplayer", hotkey::TITLE_SCREEN__MULTIPLAYER, [this](window& w) {
		while(true) {
			gui2::dialogs::mp_method_selection dlg;
			dlg.show(game_.video());

			if(dlg.get_retval() != gui2::window::OK) {
				return;
			}

			const int res = dlg.get_choice();

			if(res == 2 && preferences::mp_server_warning_disabled() < 2) {
				if(!gui2::dialogs::mp_host_game_prompt::execute(game_.video())) {
					continue;
				}
			}

			switch(res) {
				case 0:
					game_.select_mp_server(preferences::server_list().front().address);
					w.set_retval(MP_CONNECT);
					break;
				case 1:
					game_.select_mp_server("");
					w.set_retval(MP_CONNECT);
					break;
				case 2:
					game_.select_mp_server("localhost");
					w.set_retval(MP_HOST);
					break;
				case 3:
					w.set_retval(MP_LOCAL);
					break;
			}

			return;
		}
	});

	//
	// Load game
	//
	register_button(win, "load", hotkey::HOTKEY_LOAD_GAME, [this](window& w) {
		if(game_.load_game()) {
			w.set_retval(LAUNCH_GAME);
		} else {
			game_.clear_loaded_game();
		}
	});

	//
	// Addons
	//
	register_button(win, "addons", hotkey::TITLE_SCREEN__ADDONS, [this](window&) {
		// NOTE: we need the help_manager to get access to the Add-ons section in the game help!
		help::help_manager help_manager(&game_config_manager::get()->game_config());

		if(manage_addons(game_.video())) {
			game_config_manager::get()->reload_changed_game_config();
		}
	});

	//
	// Editor
	//
	register_button(win, "editor", hotkey::TITLE_SCREEN__EDITOR, [&](window& w) { w.set_retval(MAP_EDITOR); });

	//
	// Cores
	//
	register_button(win, "cores", hotkey::TITLE_SCREEN__CORES, [this](window&) {
		int current = 0;
		std::vector<config> cores;
		for(const config& core : game_config_manager::get()->game_config().child_range("core")) {
			cores.push_back(core);

			if(core["id"] == preferences::core_id()) {
				current = cores.size() - 1;
			}
		}

		gui2::dialogs::core_selection core_dlg(cores, current);
		if(core_dlg.show(game_.video())) {
			const std::string& core_id = cores[core_dlg.get_choice()]["id"];

			preferences::set_core_id(core_id);
			game_config_manager::get()->reload_changed_game_config();
		}
	});

	if(game_config_manager::get()->game_config().child_range("core").size() <= 1) {
		find_widget<button>(&win, "cores", false).set_visible(window::visibility::invisible);
	}

	//
	// Language
	//
	register_button(win, "language", hotkey::HOTKEY_LANGUAGE, [this](window& w) {
		try {
			if(game_.change_language()) {
				t_string::reset_translations();
				::image::flush_cache();
				on_resize(w);
			}
		} catch(std::runtime_error& e) {
			gui2::show_error_message(game_.video(), e.what());
		}
	});

	//
	// Preferences
	//
	register_button(win, "preferences", hotkey::HOTKEY_PREFERENCES, [this](window&) { game_.show_preferences(); });

	//
	// Credits
	//
	register_button(win, "credits", hotkey::TITLE_SCREEN__CREDITS, [&](window& w) { w.set_retval(SHOW_ABOUT); });

	//
	// Quit
	//
	register_button(win, "quit", hotkey::HOTKEY_QUIT_TO_DESKTOP, [&](window& w) { w.set_retval(QUIT_GAME); });

	//
	// Debug clock
	//
	register_button(win, "clock", hotkey::HOTKEY_NULL,
		std::bind(&title_screen::show_debug_clock_window, this, std::ref(win.video())));

	find_widget<button>(&win, "clock", false).set_visible(show_debug_clock_button
		? widget::visibility::visible
		: widget::visibility::invisible);
}
Exemple #11
0
void ttitle_screen::pre_show(twindow& window)
{
	set_restore(false);
	window.set_click_dismiss(false);
	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

#ifdef DEBUG_TOOLTIP
	window.connect_signal<event::SDL_MOUSE_MOTION>(
			std::bind(debug_tooltip, std::ref(window), _3, _5),
			event::tdispatcher::front_child);
#endif

	/**** Set the version number ****/
	if(tcontrol* control
	   = find_widget<tcontrol>(&window, "revision_number", false, false)) {

		control->set_label(_("Version ") + game_config::revision);
	}
	window.canvas()[0].set_variable(
			"revision_number",
			variant(_("Version") + std::string(" ") + game_config::revision));

	/**** Set the tip of the day ****/
	tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);

	std::vector<ttip> tips(settings::get_tips());
	if(tips.empty()) {
		WRN_CF << "There are not tips of day available." << std::endl;
	}

	for(const auto & tip : tips)
	{

		string_map widget;
		std::map<std::string, string_map> page;

		widget["label"] = tip.text();
		widget["use_markup"] = "true";
		page["tip"] = widget;

		widget["label"] = tip.source();
		widget["use_markup"] = "true";
		page["source"] = widget;

		tip_pages.add_page(page);
	}

	update_tip(window, true);

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "next_tip", false),
			std::bind(&ttitle_screen::update_tip,
						this,
						std::ref(window),
						true));

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "previous_tip", false),
			std::bind(&ttitle_screen::update_tip,
						this,
						std::ref(window),
						false));

	if(game_config::images::game_title.empty()) {
		ERR_CF << "No title image defined" << std::endl;
	} else {
		window.canvas()[0].set_variable(
				"title_image", variant(game_config::images::game_title));
	}

	if(game_config::images::game_title_background.empty()) {
		ERR_CF << "No title background image defined" << std::endl;
	} else {
		window.canvas()[0].set_variable(
				"background_image",
				variant(game_config::images::game_title_background));
	}

	/***** Logo *****/
	find_widget<timage>(&window, "logo", false).set_image("misc/logo.png");

	/***** About dialog button *****/
	tbutton& about = find_widget<tbutton>(&window, "about", false);
	connect_signal_mouse_left_click(
			about,
			std::bind(&tgame_version::display, std::ref(window.video())));

	/***** Set the clock button. *****/
	tbutton& clock = find_widget<tbutton>(&window, "clock", false);
	clock.set_visible(show_debug_clock_button ? twidget::tvisible::visible
											  : twidget::tvisible::invisible);

	connect_signal_mouse_left_click(
			clock,
			std::bind(&ttitle_screen::show_debug_clock_window,
						this,
						std::ref(window.video())));
}
Exemple #12
0
int main()
{
	int c = 0, i = 0;
    CvCapture* capture = cvCaptureFromCAM(0);

	if(!cvQueryFrame(capture))
	{
		printf("Video capture failed, please check the camera.");
	}
	else
	{
		printf("Video camera capture status: OK");
	}

    CvSize sz = cvGetSize(cvQueryFrame( capture));
	
	height = sz.height;
    width = sz.width;
    step = sz.width;
    
    IplImage* src = cvCreateImage( sz, 8, 3 );
	IplImage* hsv_image = cvCreateImage( sz, 8, 3);
	IplImage* hsv_mask = cvCreateImage( sz, 8, 1);
	IplImage* handview = cvCreateImage(sz, 8, 1);
	CvScalar  hsv_min = cvScalar(5, 70, 0, 0);
	CvScalar  hsv_max = cvScalar(20, 150, 255, 0); //H-> 0-20

	while( c != 27)
	{
		//printf("%d\t\t",framecount);
		src = cvQueryFrame( capture);
		cvCvtColor(src, hsv_image, CV_BGR2HSV);
		cvInRangeS (hsv_image, hsv_min, hsv_max, hsv_mask);
		cvSmooth(hsv_mask, handview, CV_MEDIAN, 5, 0, 0, 0);
		cvDilate(handview, handview, NULL, 3);
		//cvDilate(hsv_mask, handview, NULL, 1);
		//cvErode(handview, handview, NULL, 1);
		//cvDilate(handview, handview, NULL, 1);
		
		CvMemStorage* storage = cvCreateMemStorage(0);
		CvSeq* contour = 0;
		cvFindContours(handview, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
		cvZero(handview);
		
		for( ; contour != 0; contour = contour->h_next )
		{
			// replace CV_FILLED with 1 to see the outlines         
			double area = cvContourArea( contour, CV_WHOLE_SEQ, 0);
			if(area > 500)
			{
				cvDrawContours( handview, contour, cvScalar( 255 ), cvScalar( 255 ), 0, 0, 8 );
				//max = area;
			}
		}
		//cvShowImage("handview", handview);
		
		tips(handview);

		//cvNamedWindow( "hsv-msk",1);
		//cvShowImage( "hsv-msk", hsv_mask); //hsv_mask->origin = 1; 
		
		for(i=0; i<tipcount; i++)
		{
			if(posmax == i)
				cvCircle(src, cvPoint(tips_position[posmax][1], tips_position[posmax][0]), 3, cvScalar(0,255,0), 2, 8, 0);	
			else
				cvCircle(src, cvPoint(tips_position[i][1], tips_position[i][0]), 3, cvScalar(255,0,0), 2, 8, 0);
			

			if(speed[i][1] > 1 && speed[i][2] > 1 && (int)speed[i][5] == 1 && oldtips[(oldtipflag+1)%FRAMERUN][i][2] == 1)
			{	
				cvCircle(src, cvPoint(speed[i][4], speed[i][3]), 5, cvScalar(0,0,255), 3, 8, 0);
				speed[i][1] = 0;
				speed[i][2] = 0;
				speed[i][5] = 0;
				//printf("check\t");
			}
			else if(speed[i][1] > 1 && speed[i][2] > 1  && oldtips[(oldtipflag+1)%FRAMERUN][i][2] == -1)
			{	
				//cvCircle(src, cvPoint(speed[posmax][4], speed[posmax][3]), 9, cvScalar(0,0,255), 3, 8, 0);
				speed[i][1] = speed[i][2];
				speed[i][2] = 0;
				speed[i][5] = 0;
				//printf("check\t");
			}
		}
					
		//printf("%d\t%d\t%d", (int)speed[3][1], (int)speed[3][2], (int)speed[3][5]);
			
		//printf("\n");
		/*if(speed[posmax][1] > 1 && speed[posmax][2] > 1 && oldtips[(oldtipflag+1)%FRAMERUN][posmax][2] == 1)
		{	
			cvCircle(src, cvPoint(speed[posmax][4], speed[posmax][3]), 5, cvScalar(0,0,255), 3, 8, 0);
			speed[posmax][1]=0;
			speed[posmax][2]=0;
			//printf("check\t");
		}
		else if(speed[posmax][1] > 1 && speed[posmax][2] > 1 && oldtips[(oldtipflag+1)%FRAMERUN][posmax][2] == -1)
		{	
			//cvCircle(src, cvPoint(speed[posmax][4], speed[posmax][3]), 5, cvScalar(0,0,255), 3, 8, 0);
			speed[posmax][1]=speed[posmax][2];
			speed[posmax][2]=0;
			//printf("check\t");
		}*/
		
		//sprintf(framename, "./frames/frame%d.jpg", framecount++);
		//cvSaveImage(framename, src);
			
		//maxspeed = posmax;
		oldtipflag = (oldtipflag+1)%FRAMERUN;	
		
		//printf("%d\t%f\t3\t%f\n", posmax, speed[posmax][0], speed[3][0]);
		cvNamedWindow( "src",1);
		cvShowImage( "src", src);

		c = cvWaitKey( 10);
	}

	cvReleaseCapture( &capture);
	cvReleaseImage(&hsv_image);
	cvReleaseImage(&hsv_mask);
	cvReleaseImage(&handview);
	cvDestroyAllWindows();
}