Exemplo n.º 1
0
void PeerListWidget::updateSelection() {
	auto selected = -1;
	auto selectedKick = false;

	auto mouse = mapFromGlobal(_mousePosition);
	if (rtl()) mouse.setX(width() - mouse.x());
	auto left = getListLeft();
	auto top = getListTop();
	auto memberRowWidth = rowWidth();
	if (mouse.x() >= left && mouse.x() < left + memberRowWidth && mouse.y() >= top) {
		selected = (mouse.y() - top) / _st.height;
		if (selected >= _items.size()) {
			selected = -1;
		} else if (_items[selected]->hasRemoveLink) {
			int skip = _st.photoPosition.x();
			int nameLeft = left + _st.namePosition.x();
			int nameTop = top + _selected * _st.height + _st.namePosition.y();
			int nameWidth = memberRowWidth - _st.namePosition.x() - skip;
			if (mouse.x() >= nameLeft + nameWidth - _removeWidth && mouse.x() < nameLeft + nameWidth) {
				if (mouse.y() >= nameTop && mouse.y() < nameTop + st::normalFont->height) {
					selectedKick = true;
				}
			}
		}
	}

	setSelected(selected, selectedKick);
}
Exemplo n.º 2
0
void PeerListWidget::paintContents(Painter &p) {
	auto ms = getms();
	auto left = getListLeft();
	auto top = getListTop();
	auto memberRowWidth = rowWidth();

	auto from = floorclamp(_visibleTop - top, _st.height, 0, _items.size());
	auto to = ceilclamp(_visibleBottom - top, _st.height, 0, _items.size());
	for (auto i = from; i < to; ++i) {
		auto y = top + i * _st.height;
		auto selected = (_pressed >= 0) ? (i == _pressed) : (i == _selected);
		auto selectedRemove = selected && _selectedRemove;
		if (_pressed >= 0 && !_pressedRemove) {
			selectedRemove = false;
		}
		paintItem(p, left, y, _items[i], selected, selectedRemove, ms);
	}
}
Exemplo n.º 3
0
void PeerListWidget::mousePressEvent(QMouseEvent *e) {
	_mousePosition = e->globalPos();
	updateSelection();

	_pressButton = e->button();
	_pressed = _selected;
	_pressedRemove = _selectedRemove;
	if (_pressed >= 0 && !_pressedRemove) {
		auto item = _items[_pressed];
		if (!item->ripple) {
			auto memberRowWidth = rowWidth();
			auto mask = Ui::RippleAnimation::rectMask(QSize(memberRowWidth - _st.button.outlineWidth, _st.height));
			item->ripple = std::make_unique<Ui::RippleAnimation>(_st.button.ripple, std::move(mask), [this, index = _pressed] {
				repaintRow(index);
			});
		}
		auto left = getListLeft() + _st.button.outlineWidth;
		auto top = getListTop() + _st.height * _pressed;
		item->ripple->add(e->pos() - QPoint(left, top));
	}
}
Exemplo n.º 4
0
void mesh3DS::draw(int textureID, bool pregenetateList){
		
	if (m_specialTransform){
		++m_specialTransformTick;
	}
	assert(getNumFaces()!=0);
	if (!pregenetateList && !m_specialTransform)
		glCallList(glutGetWindow()==1?getListLeft():getListRight());  // uruchomienie rysowania ze swap'a
	else 
		//currentMaterial.setList(glGenLists(1));// wygenerowanie miejsca dla jednej listy i zwr�cenie do niej uchwytu - mozliwe jest generowanie szeregu list, pod kolejnymi (+1) wartosciami uchwytow, wtedy metoda zwraca uchwyt do pierwszej z nich
		for (int window=1;window < (m_parentModel->getStereo()?3:2);window++){
			if (m_parentModel->getStereo()) glutSetWindow(window);
			if (!m_specialTransform) {
				if (window==1)setListLeft(glGenLists(1)); else setListRight(glGenLists(1));
				glNewList(window==1?getListLeft():getListRight(),GL_COMPILE); //definicja zawarto�ci listy("cube")
			}
			int face, numFaces, vertexIndex, texcoordIndex;
			GLuint materialFaces; //GL_FRONT or GL_FRONT_AND_BACK

			std::map<std::string, std::vector<ushort> >::iterator materialsIter;
			for(materialsIter=m_materialFaces.begin(); materialsIter!=m_materialFaces.end(); ++materialsIter){
				const material3DS& currentMaterial = m_parentModel->getMaterial(materialsIter->first);

				// Bind texture map (if any)
				bool hasTextureMap = currentMaterial.hasTextureMap();
				if (textureID) glBindTexture(GL_TEXTURE_2D, textureID);
				else if(hasTextureMap) glBindTexture(GL_TEXTURE_2D, currentMaterial.getTextureMapId());
				else glBindTexture(GL_TEXTURE_2D, 0);

				const GLfloat *specular = currentMaterial.getSpecularColor();
				float shininess = currentMaterial.getShininess();
				float adjustedSpecular[4] = {specular[0]*shininess, specular[1]*shininess, specular[2]*shininess, 1};

				glPushAttrib(GL_LIGHTING_BIT);
				if(currentMaterial.isTwoSided()){
					glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);
					materialFaces = GL_FRONT_AND_BACK;
				}
				else{
					glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
					materialFaces = GL_FRONT;
				}
				
				// Apply material colors
				if(glIsEnabled(GL_LIGHTING)){
					 GLfloat matOne[4]={1,1,1,1};
					 GLfloat matLow[4]={0.20,0.20,0.20,0.20};
					 GLfloat matDiffuse[4]; // tworzenie diffuseColor z parametrem alfa pochodzacym z opacity
					 memcpy(matDiffuse,currentMaterial.getDiffuseColor(),sizeof(float)*3);
					 matDiffuse[3] = 1 - currentMaterial.getOpacity();
					if(hasTextureMap){ //replace only color with texture, but keep lighting contribution
						glMaterialfv(materialFaces, GL_DIFFUSE, matOne); 
					}
					else glMaterialfv(materialFaces, GL_DIFFUSE, matDiffuse);
					glMaterialfv(materialFaces, GL_AMBIENT, matLow);
					glMaterialfv(materialFaces, GL_SPECULAR, matLow);
					glMaterialf(materialFaces, GL_SHININESS, 2.0f);
				}
				else glColor3fv(currentMaterial.getDiffuseColor());
			
				if (currentMaterial.getOpacity() < 1){
					glEnable(GL_BLEND);
					glDepthMask(GL_FALSE);
					glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
					//glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
				}

				std::vector<ushort> *currentMatFaces = &(materialsIter->second);
				numFaces = (int)currentMatFaces->size(); //number of faces in this material

				switch(m_drawMode){
					case DRAW_IMMEDIATE_MODE:

						glBegin(GL_TRIANGLES);
						for(face=0; face<numFaces; face+=3){
							if(hasTextureMap){
								texcoordIndex = (*currentMatFaces)[face]*2;
								glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
							}
							vertexIndex = (*currentMatFaces)[face]*3;
							glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
							glVertex3f(m_vertices[vertexIndex]+calculateSpecialTransformX(vertexIndex), m_vertices[vertexIndex+1]+calculateSpecialTransformY(vertexIndex), m_vertices[vertexIndex+2]+calculateSpecialTransformZ(vertexIndex));
							if(hasTextureMap){
								texcoordIndex = (*currentMatFaces)[face+1]*2;
								glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
							}
							vertexIndex = (*currentMatFaces)[face+1]*3;
							glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
							glVertex3f(m_vertices[vertexIndex]+calculateSpecialTransformX(vertexIndex), m_vertices[vertexIndex+1]+calculateSpecialTransformY(vertexIndex), m_vertices[vertexIndex+2]+calculateSpecialTransformZ(vertexIndex));
							if(hasTextureMap){
								texcoordIndex = (*currentMatFaces)[face+2]*2;
								glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
							}
							vertexIndex = (*currentMatFaces)[face+2]*3;
							glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
							glVertex3f(m_vertices[vertexIndex]+calculateSpecialTransformX(vertexIndex), m_vertices[vertexIndex+1]+calculateSpecialTransformY(vertexIndex), m_vertices[vertexIndex+2]+calculateSpecialTransformZ(vertexIndex));

						}
						glEnd();

						break;
					
					case DRAW_VERTEX_ARRAY:
						
						glEnableClientState( GL_VERTEX_ARRAY );
						glEnableClientState( GL_NORMAL_ARRAY );
						
						if(hasTextureMap){
							glTexCoordPointer( 2, GL_FLOAT, 0, &m_texcoords[0] );
							glEnableClientState( GL_TEXTURE_COORD_ARRAY );
						}

						glVertexPointer( 3, GL_FLOAT, 0, &m_vertices[0] );
						glNormalPointer(GL_FLOAT, 0, &m_normals[0] );
						glDrawElements(GL_TRIANGLES, numFaces, GL_UNSIGNED_SHORT, &(materialsIter->second[0]));

						glDisableClientState( GL_VERTEX_ARRAY );
						glDisableClientState( GL_NORMAL_ARRAY );
						if(hasTextureMap){
							glDisableClientState( GL_TEXTURE_COORD_ARRAY );
						}

						break;

					case DRAW_VBO:

						break;
					
					default:
						std::cout<<"[3DS] ERROR: Invalid mesh draw mode specified"<<std::endl;
						break;
				} // switch
				if (currentMaterial.getOpacity() <1){
					glDepthMask(GL_TRUE);
					glDisable(GL_BLEND);
				}
				glPopAttrib(); // GL_LIGHTING_BIT
			}
			if (!m_specialTransform) glEndList(); //koniec definicji zawarto�ci listy
		}//for po window
}
Exemplo n.º 5
0
int PeerListWidget::rowWidth() const {
	return _st.maximalWidth
		? qMin(width() - getListLeft(), _st.maximalWidth)
		: width() - getListLeft();
}
Exemplo n.º 6
0
void PeerListWidget::repaintRow(int index) {
	if (index >= 0) {
		auto left = getListLeft();
		rtlupdate(left, getListTop() + index * _st.height, width() - left, _st.height);
	}
}