コード例 #1
0
ファイル: button.cpp プロジェクト: x2f/wesciv
bool button::handle_event(const SDL_Event& event, bool claimed)
{
    if(claimed) {
        current_texture_ = &normal_texture_;
    }

	if(event.type == SDL_MOUSEMOTION) {
		const SDL_MouseMotionEvent& e = event.motion;
		if(current_texture_ == &depressed_texture_) {
			//pass
		} else if(in_button(e.x,e.y)) {
			current_texture_ = &focus_texture_;
		} else {
			current_texture_ = &normal_texture_;
		}
	} else if(event.type == SDL_MOUSEBUTTONDOWN) {
		const SDL_MouseButtonEvent& e = event.button;
		if(in_button(e.x,e.y)) {
			current_texture_ = &depressed_texture_;
		}
	} else if(event.type == SDL_MOUSEBUTTONUP) {
		const SDL_MouseButtonEvent& e = event.button;
		if(current_texture_ == &depressed_texture_) {
			if(in_button(e.x,e.y)) {
				current_texture_ = &focus_texture_;
				onclick_();
				claimed = true;
			} else {
				current_texture_ = &normal_texture_;
			}
		}
	}
	return claimed;
}
コード例 #2
0
void checkbox::on_click()
{
	checked_ = !checked_;
	const int w = width();
	const int h = height();
	set_label(create_checkbox_widget(label_, checked_));
	set_dim(w, h);
	onclick_(checked_);
}
コード例 #3
0
bool button::handle_event(const SDL_Event& event, bool claimed)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
	if((event.type == SDL_MOUSEWHEEL) 
#else
	if((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) 
		&& (event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN)
#endif
		&& in_widget(event.button.x, event.button.y)) {
		// skip processing if mousewheel event
		return claimed;
	}

    if(claimed) {
		current_button_image_set_ = normal_button_image_set_;
		down_ = false;
    }

	if(event.type == SDL_MOUSEMOTION) {
		const SDL_MouseMotionEvent& e = event.motion;
		if(in_widget(e.x,e.y)) {
			current_button_image_set_ = down_ ? depressed_button_image_set_ : focus_button_image_set_;
		} else {
			current_button_image_set_ = normal_button_image_set_;
		}
	} else if(event.type == SDL_MOUSEBUTTONDOWN) {
		const SDL_MouseButtonEvent& e = event.button;
		if(in_widget(e.x,e.y)) {
		std::cerr << "ZZZ: Widget: " << e.x << ", " << e.y << ": ";
		if(clip_area()) {
			std::cerr << *clip_area() << "\n";
		} else {
			std::cerr << "(null)\n";
		}
			current_button_image_set_ = depressed_button_image_set_;
			down_ = true;
			claimed = claim_mouse_events();
		}
	} else if(event.type == SDL_MOUSEBUTTONUP) {
		down_ = false;
		const SDL_MouseButtonEvent& e = event.button;
		if(current_button_image_set_ == depressed_button_image_set_) {
			if(in_widget(e.x,e.y)) {
				current_button_image_set_ = focus_button_image_set_;
				onclick_();
				claimed = claim_mouse_events();
			} else {
				current_button_image_set_ = normal_button_image_set_;
			}
		}
	}
	return claimed;
}
コード例 #4
0
bool button::handle_event(const SDL_Event& event, bool claimed)
{
	if((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) 
		&& (event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN)
		&& in_button(event.button.x, event.button.y)) {
		// skip processing if mousewheel event
		return claimed;
	}

    if(claimed) {
		current_button_image_set_ = normal_button_image_set_;
		down_ = false;
    }

	if(event.type == SDL_MOUSEMOTION) {
		const SDL_MouseMotionEvent& e = event.motion;
		if(in_button(e.x,e.y)) {
			current_button_image_set_ = down_ ? depressed_button_image_set_ : focus_button_image_set_;
		} else {
			current_button_image_set_ = normal_button_image_set_;
		}
	} else if(event.type == SDL_MOUSEBUTTONDOWN) {
		const SDL_MouseButtonEvent& e = event.button;
		if(in_button(e.x,e.y)) {
			current_button_image_set_ = depressed_button_image_set_;
			down_ = true;
			claimed = true;
		}
	} else if(event.type == SDL_MOUSEBUTTONUP) {
		down_ = false;
		const SDL_MouseButtonEvent& e = event.button;
		if(current_button_image_set_ == depressed_button_image_set_) {
			if(in_button(e.x,e.y)) {
				current_button_image_set_ = focus_button_image_set_;
				onclick_();
				claimed = true;
			} else {
				current_button_image_set_ = normal_button_image_set_;
			}
		}
	}
	return claimed;
}
コード例 #5
0
ファイル: button.cpp プロジェクト: KitoHo/anura
void button::do_execute()
{ 
	if(onclick_) { 
		onclick_();
	} 
}