예제 #1
0
bool DropDown::ItemList::onEvent(Event::t e, GLV& g){
	const Keyboard& k = g.keyboard();
	const Mouse& m = g.mouse();

	switch(e){
	case Event::KeyDown:
		switch(k.key()){
		case Key::Enter:
		case Key::Return:
			dd.setValue(getValue());
			dd.onEvent(e,g);
			break;
		default:;
		}
		break;
	case Event::FocusLost:
		disable(Visible);
		break;
	case Event::MouseUp:
		//printf("setValue\n");
		//if(Rect(w,h).containsPoint(m.xRel(), m.yRel())){
		if(containsPoint(m.x(), m.y())){
			dd.setValue(getValue());
			dd.notify(&dd, Update::Action);
			//dd.onEvent(e,g);
		}
		disable(Visible);
		g.setFocus(&dd);
		return false;
	default:;
	}
	return ListView::onEvent(e,g);
}
예제 #2
0
bool SearchBox::ItemList::onEvent(Event::t e, GLV& g){
	const Keyboard& k = g.keyboard();
	const Mouse& m = g.mouse();

	switch(e){
	case Event::KeyDown:
		switch(k.key()){
		case Key::Enter:
		case Key::Return:
			//sb.setValue(getValue());
			sb.onEvent(e,g);
			break;
		default:;
		}
		break;

	case Event::FocusLost:
		disable(Visible);
		break;

	case Event::MouseUp:
		// ItemList is in absolute coordinates
		if(containsPoint(m.x(), m.y())){
			sb.setValue(getValue());
			sb.cursorEnd();
			sb.notify(&sb, Update::Action);
			sb.onEvent(e,g);
		}
		disable(Visible);
		g.setFocus(&sb);
		return false;

	default:;
	}
	return ListView::onEvent(e,g);
}
예제 #3
0
bool NumberDialers::onEvent(Event::t e, GLV& g){

	if(!Widget::onEvent(e,g)) return false;

	const Keyboard& k = g.keyboard();
	const Mouse& m    = g.mouse();

	switch(e){
	case Event::MouseDown:{
		mAcc = 0;
		int oldDig = dig();

		selectFromMousePos(g);
		float dxDig = font().advance('M');
		int d = (m.xRel() - (dx() * selectedX() + paddingX())) / dxDig;
		
//		printf("%2d (%2d, %2d)\n", d, selectedX(), selectedY());
		dig(d);
		if(dig() == 0 && oldDig == 0 && mShowSign) flipSign();
		return false;
	}
	
	case Event::MouseDrag:
		if(onNumber()){
			mAcc += 0.25f * fabs(m.dy());
			if(mAcc > 1){
				int mul = (int)mAcc;
				int digit = dig();
				/*if(m.left() && m.right() && digit < (numDigits()-1)){
					++digit;
				}*/
				valAdd((m.dy() > 0.f ? -mag(digit) : mag(digit))*mul);
				mAcc -= mul;
			}
		}
		return false;
	
	case Event::KeyDown:
		if(k.ctrl() || k.alt() || k.meta()){}
		else if(k.isNumber() && onNumber()){
			int vali = valInt(selected());
			int v = vali < 0 ? -vali : vali;
			int p = pow(10., numDigits()-1-dig());
			v += (k.keyAsNumber() - ((v / p) % 10)) * p;
			v = vali < 0 ? -v : v;
			setValue(v * pow(10., -mNF));
			if(!mOverwriteMode) dig(dig()+1);
			return false;
		}
		else{
			switch(k.key()){
			case 'a': onNumber() ? valAdd( mag()) : flipSign(); return false;
			case 'z': onNumber() ? valAdd(-mag()) : flipSign(); return false;
			case '-': flipSign(); return false;
			case 'c': setValue(0); return false;
			case '=':
			//case Key::Return:
				if(!mTextEntryMode){ // bring up the text entry box
					mTextEntryMode=true;
					mTextEntry.filter(TextView::filterNumeric).paddingY(2);
					(*this) << mTextEntry;
					mTextEntry.setValue(toString(getValue()));
					mTextEntry.selectAll();
					g.setFocus(&mTextEntry);
				}
				else{				// set value from text entry box, then remove it
					mTextEntryMode=false;
					g.setFocus(this);
					mTextEntry.remove();
					if(!mTextEntry.getValue().empty()){				
						setValue(mTextEntry.data().at<double>(0));
					}
				}
				return false;
			case '.': dig(numDigits()-mNF); return false; // go to first fraction digit (if any)
			case Key::Left:
			case 's': dig(dig()-1); return false;
			case Key::Right:
			case 'd': dig(dig()+1); return false;
			case 'o': mOverwriteMode^=true; return false;
			}
		}
		break;

	default:;
	}

	return true;
}
예제 #4
0
void DropDown::hideList(GLV& g){
	mItemList.disable(Visible);
	g.setFocus(this);
}