bool onEvent(Event::t e, GLV& g){
		if(e == Event::KeyDown){
			switch(g.keyboard().key()){
				case '`': toggle(Visible); return false;
			}
		}
		if (e == Event::MouseDrag){
			if (g.keyboard().ctrl()) printf("ctrl");
			if (g.keyboard().shift()) printf("shift");
		}
		return true;
	}
	bool onEvent(Event::t e, GLV& g){

		//Plot::onEvent(e,g);	// "inherit" mouse/keyboard controls

		float gx = pixToGrid(0, g.mouse().xRel());	// convert mouse to grid position
		float gy = pixToGrid(1, g.mouse().yRel());	// convert mouse to grid position
		int cx = (gx*0.5+0.5) * P.size(0);			// convert grid to cell position
		int cy = (gy*0.5+0.5) * P.size(1);			// convert grid to cell position

		switch(e){
		case Event::MouseDown:
		case Event::MouseDrag:
			if(P.inBounds(cx, cy)){
				P.elem<float>(cx,cy,iz) = g.mouse().button() ? -1:1;
			}
			break;
		case Event::KeyDown:
			switch(g.keyboard().key()){
			case 'c': P.assignAll(0); break;
			}
			break;
		default:;
		}
		
		return true;
	}
Esempio n. 3
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);
}
Esempio n. 4
0
bool ListView::onEvent(Event::t e, GLV& g){

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

	switch(e){
	case Event::MouseDown:
	case Event::MouseDrag:
		selectFromMousePos(g);
		return false;

//		case Event::MouseMove:
//			if(containsPoint(g.mouse().xRel(), g.mouse().yRel())){
//				selectFromMousePos(g);
//				return false;
//			}
//			break;
	
	case Event::KeyDown:
		switch(g.keyboard().key()){
			case Key::Enter:
			case Key::Return:
				notify(this, Update::Action);
//				printf("action on %d\n", selected());
				return false;
		default:;
		}
		break;
	
	default:;
	}
	

	return true;
}
Esempio n. 5
0
bool Plot::onEvent(Event::t e, GLV& g){
	if(Grid::onEvent(e,g)){
		
		const Keyboard& k = g.keyboard();
		
		if(e == Event::KeyDown){
			if(k.ctrl() && k.alt() && k.isNumber()){
				unsigned i = k.keyAsNumber();
				i = i>0 ? i-1 : 10; 
				if(i < plottables().size() && plottables()[i]){
					mActive[i] ^= 1;
				}
				return false;
			}
		}
		
		return true;
	}
	return false;
}
Esempio n. 6
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);
}
bool keyDownCB(View * v, GLV& glv){
	switch(glv.keyboard().key()){
		case '`': glv.toggle(Visible); break;
	}
	return false;
}
Esempio n. 8
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;
}
Esempio n. 9
0
bool SearchBox::onEvent(Event::t e, GLV& g){

//	printf("SearchBox::onEvent %s\n", toString(e));

	bool showList = true;
	const Keyboard& k = g.keyboard();

	switch(e){
	case Event::KeyDown:
		switch(k.key()){
		case Key::Down:	// pass on up/down arrows to search list...
		case Key::Up:
			mItemList.onEvent(e,g);
			return false;
		case Key::Enter:
		case Key::Return:
			if(mItemList.visible()){
				setValue(mItemList.getValue());
				cursorEnd();
			}
			mItemList.disable(Visible);
			showList = false;
			break; // pass event on to TextView
			//return false;
		case Key::Tab:
			if(!empty()){
				const std::string& tstr = getValue();
				for(unsigned i=0; i<mItems.size(); ++i){
					const std::string& s = mItems[i];
					int r = strncmp(s.c_str(), tstr.c_str(), tstr.size());
					if(0 == r){
						setValue(s);
						cursorEnd();
						break;
					}
				}
			}
			return false;
		default:;
		}
		break;
	case Event::FocusLost:
		if(!mItemList.enabled(Focused)) mItemList.disable(Visible);
		return false;
	default:;
	}
	
	bool res = TextView::onEvent(e,g);

	if(Event::KeyDown == e || Event::MouseDown == e){

		mItemList.disable(Visible);
		if(showList && !empty()){
			std::vector<std::string> listItems;
			const std::string& tstr = getValue();
			for(unsigned i=0; i<mItems.size(); ++i){
				const std::string& s = mItems[i];
				//int r = strncasecmp(s.c_str(), tstr.c_str(), tstr.size());
				size_t res = s.find(tstr);
				if(res != std::string::npos){
//					printf("%s, %d\n", s.c_str(), res);
					listItems.push_back(s);
				}
			}

			if(listItems.size()){
				if(!((listItems.size() == 1) && (listItems[0].size() == tstr.size()))){
					space_t ax = 0, ay = height();
					const View& top = *toAbs(ax, ay);
					
					mItemList.data().resize(1, listItems.size());
					mItemList.data().assignFromArray(&listItems[0], listItems.size());
					mItemList.clipIndices();
					mItemList.fitExtent();

					if(ay > top.height()/2){
						ay -= mItemList.height() + height();
					}

					mItemList.pos(ax,ay);
					mItemList.enable(Visible);
					mItemList.bringToFront();
				}
			}
			if(mItemList.parent == 0) root() << mItemList;			
		}
	}

	return res;
}
Esempio n. 10
0
bool DropDown::onEvent(Event::t e, GLV& g){
//printf("DropDown::onEvent %s\n", toString(e));

/*
	From ListSelect:

		switch(e){
		case Event::KeyDown:
			if(!k.ctrl() && !k.alt() && isgraph(k.key())){
				char c = tolower(k.key());
				for(unsigned i=0; i<mItems.size(); ++i){
					if(mItems[i][0] == c){
						select(i); break;
					}
				}
				return false;
			}
			else{
				switch(k.key()){
				case Key::Up:	select(selected()-1); return false;
				case Key::Down:	select(selected()+1); return false;
				default:;
				}
			}
			break;
		case Event::MouseDown:
			return false;
		case Event::KeyUp:
		case Event::MouseUp: return false;

		case Event::MouseDrag:{
			int dy = m.y() - m.y(m.button());
			int inc = ((dy+800000) % 8 == 0) * (dy<0?-1:1);
			select(selected()+inc);
			return false;
		}
			
		default:;
		}
		return true;
	}

*/

	const Keyboard& k = g.keyboard();

	switch(e){
	case Event::KeyDown:
		// bubble if modifier key down
		if(k.ctrl() || k.alt() || k.meta()){}
		
		// printable keys search list and select first matching item
		else if(k.isPrint()){
			unsigned char lkey = tolower(k.key());
			for(unsigned i=0; i<items().size(); ++i){
				if(lkey == tolower(items()[i][0])){
					mItemList.select(i);
					showList();
					break;
				}
			}
			return false;
		}
		
		// switch on other keys...
		else{
			switch(k.key()){
			case Key::Down:
			case Key::Up:
				if(!mItemList.visible()){
					mItemList.selectValue(getValue());
				}
				else{ // pass on up/down arrows to item list...
					mItemList.onEvent(e,g);
				}
				showList();
				return false;
			case Key::Enter:
			case Key::Return:
				if(mItemList.visible()) setValue(mItemList.getValue());
				hideList(g);
				return TextView::onEvent(e,g); // let base class handle it from here
			default:;
			}
		}
		break;
	case Event::MouseUp:
		return false;
	case Event::MouseDown:
		if(mItemList.visible())	hideList(g);
		else{					showList(); //g.setFocus(&mItemList); // momentary
		}
		return false;
	case Event::FocusLost:
		if(!mItemList.enabled(Focused)) mItemList.disable(Visible);
		return false;
	default:;
	}

	return true;
}
Esempio n. 11
0
bool TextView::onEvent(Event::t e, GLV& g){

	const Keyboard& k = g.keyboard();
	int key = k.key();
	float mx = g.mouse().xRel();

	switch(e){
		case Event::KeyDown:
			if(k.ctrl()){
				switch(key){
				case 'a': selectAll(); return false;
				}
			}
			else if(k.alt() || k.meta()){} // bubble if control key down

			else if(k.isPrint()){

				// preserve current text if something is selected
				std::string oldText;
				int oldSel = mSel;
				int oldPos = mPos;
				if(mSel){
					oldText = mText;
					deleteSelected();
				}

				// No filter assigned or filter returns true
				if(!mFilter || mFilter(getValue(), mPos, key)){
					mText.insert(mPos, 1, k.key());
					setValue(mText);
					cursorPos(mPos+1);
					return false;
				}

				// restore old text if the new character is invalid
				if(!oldText.empty()){
					mText = oldText;
					mPos = oldPos;
					mSel = oldSel;
				}
			}
			else{
				switch(key){
				case Key::Backspace:
					if(textSelected()) deleteSelected();
					else if(validPos()){
						deleteText(mPos-1, 1);
						cursorPos(mPos-1);
					}
					return false;
					
				case Key::Delete:
					if(textSelected()) deleteSelected();
					else if(mText.size()){
						deleteText(mPos, 1);
						cursorPos(mPos);
					}
					return false;
				
				case Key::Left:
					if(k.shift()) select(mSel-1);
					else cursorPos(mPos-1);
					return false;
					
				case Key::Right:
					if(k.shift()) select(mSel+1);
					else cursorPos(mPos+1);
					return false;
					
				case Key::Down:	cursorPos(mText.size()); return false;
				case Key::Up:	cursorPos(0); return false;
					
				case Key::Enter:
				case Key::Return:
					notify(this, Update::Action);
					return false;
				}
			}
			break;

		case Event::MouseDown:
			cursorPos(xToPos(mx));
		case Event::MouseUp:
			return false;

		case Event::MouseDrag:
			{
				int p = xToPos(mx);
				if(p >= mPos) select(p-mPos+1);
				else select(p-mPos);
				//printf("%d\n", mSel);
			}
			return false;

		default:;
	}

	return true;
}