void Number::paint(void) { int x, y, w, h; getScreenPos(&x, &y, &w, &h); assert(parent); assert(parent->getSurface()); parent->getSurface()->drawLine(x+m, y, x+m, y+h, Style::style->frameColor); parent->getSurface()->drawLine(x+w-m, y, x+w-m, y+h, Style::style->frameColor); assert(nth>=0); assert(nth<(int)numbers.size()); int dy=(h-textHeight)/2; if (nth<(int)numbers.size()) { // We center the string std::stringstream s; s << numbers[nth]; int tw=fontPtr->getStringWidth(s.str().c_str()); parent->getSurface()->drawString(x+m+(w-2*m-tw)/2, y+dy, fontPtr, s.str().c_str()); } int dx1=(m-fontPtr->getStringWidth("-"))/2; parent->getSurface()->drawString(x+dx1, y+dy, fontPtr, "-"); int dx2=(m-fontPtr->getStringWidth("+"))/2; parent->getSurface()->drawString(x+dx2+w-m, y+dy, fontPtr, "+"); HighlightableWidget::paint(); }
void ColourPicker::onExpand(Widget*) { Anchors anchors = Anchors::getFillAnchors(); Vec2i bdims = g_widgetConfig.getBorderStyle(WidgetType::COLOUR_PICKER).getBorderDims(); Vec2i size(4 * 32 + bdims.w, 4 * 32 + bdims.h); Vec2i pos(getScreenPos()); pos += getSize() / 2; pos -= size / 2; m_dropDownPanel = new FloatingStrip(m_rootWindow, Orientation::VERTICAL, Origin::FROM_TOP, 4); m_dropDownPanel->setPos(pos); m_dropDownPanel->setSize(size); for (int i=0; i < 4; ++i) { CellStrip *strip = new CellStrip(m_dropDownPanel, Orientation::HORIZONTAL, 4); strip->setCell(i); strip->setAnchors(anchors); for (int j=0; j < 4; ++j) { const int ndx = i * 4 + j; m_colourButtons[ndx] = new ColourButton(strip); m_colourButtons[ndx]->setCell(j); m_colourButtons[ndx]->setAnchors(anchors); m_colourButtons[ndx]->setColour(factionColours[ndx], factionColoursOutline[ndx]); m_colourButtons[ndx]->Clicked.connect(this, &ColourPicker::onSelect); } } getRootWindow()->setFloatingWidget(m_dropDownPanel); }
void Number::onSDLMouseButtonDown(SDL_Event *event) { assert(event->type == SDL_MOUSEBUTTONDOWN); int x, y, w, h; getScreenPos(&x, &y, &w, &h); bool inc = false; bool dec = false; // We can't use isOnWidget since x, y, w, h are needed // out of the test if (isPtInRect(event->button.x, event->button.y, x, y, w, h)) { if(event->button.button == SDL_BUTTON_LEFT) { if (event->button.x-x<m) { dec = true; } else if (x+w-event->button.x<m) { inc = true; } } else if(event->button.button == SDL_BUTTON_WHEELUP) { inc = true; } else if(event->button.button == SDL_BUTTON_WHEELDOWN) { dec = true; } } if (dec) { // a "Less" click if (nth>0) { nth--; if (numbers.size()>0) { parent->onAction(this, NUMBER_ELEMENT_SELECTED, nth, 0); } } } else if (inc) { // a "More" click if (nth<((int)numbers.size()-1)) { nth++; parent->onAction(this, NUMBER_ELEMENT_SELECTED, nth, 0); } } }
/** * Draw model. * Care about model shift during move. */ void View::drawModel(Cube *model) { if (!model->isLost()) { V2 screenPos = getScreenPos(model); Anim::eSide side = Anim::SIDE_LEFT; if (!model->isLeft()) { side = Anim::SIDE_RIGHT; } model->anim()->drawAt(m_screen, screenPos.getX(), screenPos.getY(), side); } }
// -------------------------------------------------------------------------------------------------------- bool KProjectionWidget::pick ( const KMouseEvent & event ) { if (KWidget::flags[KDL_WIDGET_FLAG_VISIBLE] == false) return false; KPosition widgetMousePos = event.pos - getScreenPos(); if ( widgetMousePos.x > 0 && widgetMousePos.x < (int)size.w && widgetMousePos.y > 0 && widgetMousePos.y < (int)size.h) { getWindow()->unpick(); KPickHandler::pick(event); return true; } else { return false; } }
// -------------------------------------------------------------------------------------------------------- void KProjectionWidget::display () { if (KWidget::flags[KDL_WIDGET_FLAG_VISIBLE] == false) return; KWidget::display(); glPushAttrib( GL_CURRENT_BIT | GL_POLYGON_BIT | GL_LIGHTING_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(matrix); glEnable (GL_DEPTH_TEST); glDisable(GL_LIGHTING); glColor4f(0.0, 0.0, 0.0, 0.75); glRasterPos2i(1, -1); glPixelZoom(size.w-2, -(size.h-2)); GLuint depth = (GLuint)-1; glDepthFunc(GL_ALWAYS); glDrawPixels(1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &depth); glDepthFunc(GL_LESS); glPixelZoom(1, 1); glPolygonMode(GL_FRONT_AND_BACK, KEventHandler::flags[KDL_DISPLAY_MODE_WIREFRAME] ? GL_LINE : GL_FILL); KEventHandler::resetLighting(); KPosition screenPos = getScreenPos(); KSize screenSize = KEventHandler::getScreenSize(); projection->setViewportBorder ( screenPos.x + 1, screenPos.y + 1, screenSize.w - (screenPos.x + size.w) + 1, screenSize.h - (screenPos.y + size.h) + 1); glMatrixMode(GL_PROJECTION); glPushMatrix(); projection->initProjection(); displayContent(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); }
// -------------------------------------------------------------------------------------------------------- bool KFileTreeWidget::pick ( const KMouseEvent & event ) { if (KWidget::flags[KDL_WIDGET_FLAG_VISIBLE] == false) return false; KPosition mouseWidgetPos = event.pos - getScreenPos(); if ((mouseWidgetPos.x > 0) && (mouseWidgetPos.x < size.w) && (mouseWidgetPos.y > 0) && (mouseWidgetPos.y < size.h)) { deleteDisplayList(); getWindow()->unpick(); KPickHandler::pick(event); return true; } else { return false; } }
void SoMinimalEnclosingCircle::compute(SoGLRenderAction* action) { SoState* state = action->getState(); int counter = 0; // Get the matrices from the state to convert from object to screen space _objToScreen = (SoViewingMatrixElement::get(state) * SoProjectionMatrixElement::get(state)); // Get the size of the window from the state // Resize the pixelmatrix only if the window size has changed if (SbVec2s(_winSize[0], _winSize[1]) != SoViewportRegionElement::get(state).getWindowSize()) { _winSize[0] = SoViewportRegionElement::get(state).getWindowSize()[0]; _winSize[1] = SoViewportRegionElement::get(state).getWindowSize()[1]; if (_pixelMatrix) delete[] _pixelMatrix; _pixelMatrix = new SbBool[static_cast<int>((_winSize[0] + 1) * (_winSize[1] + 1))]; } // iniatilize the raster for (counter = 0; counter < _winSize[0] * _winSize[1]; counter++) _pixelMatrix[counter] = false; SbVec3f temp; _zValue = 0; // project the vertices onto the screen for (counter = 0; counter < _size3D; counter++) { temp = getScreenPos(_pointSet3D[counter]); _pointSet2D[counter].setValue(temp[0], temp[1]); _zValue += temp[2]; } _zValue /= _size3D; rasterizeAndSort(); if (_sizeRaster > 2) { screenSpaceBoundingBox(); } else { center.setValue(-1, -1, -1); radius.setValue(-1); } }
/******************************************************** * * * Draw Robot * * ********************************************************/ void Virtual3dCharacterViewer::glDrawBody(Character3DBody& body) { glPushMatrix(); // getHipPos() ; // get Hip's Position from the IK calculator . LocateHip (body); body.HipPosInCamera = getCurTranslation () ; body.HipPosInScreen = getScreenPos(body.HipPosInCamera) ; RotateHip(body) ; glPushMatrix(); // save the Hip Matrix drawHip (body) ; glTranslatef( 0.0, body.Model.LenHipToChest, 0.0 ) ; RotateChest (body); drawChest (body) ; glTranslatef(0.0, body.Model.LenChestToNeck, 0.0); body.NeckPosInCamera = getCurTranslation () ; body.NeckPos = TransformVector( WorldMatInv, body.NeckPosInCamera ) ; body.NeckPosInScreen = getScreenPos(body.NeckPosInCamera) ; glPushMatrix(); // save the Neck Matrix RotateLeftShoulder(body); drawLeftShoulder(body); glTranslatef(body.Model.LenNeckToShoulder, 0.0, 0.0); RotateLeftUpperArm(body); drawLeftUpperArm(body); glTranslatef(body.Model.LenShoulderToElbow, 0.0, 0.0); RotateLeftLowerArm(body); drawLeftLowerArm(body); glTranslatef(body.Model.LenElbowToWrist, 0.0, 0.0); body.LeftWristPosInCamera = getCurTranslation () ; Vector3D bias(-1,0,0) ; body.LeftWristPos = TransformVector( WorldMatInv, body.LeftWristPosInCamera ); body.LeftWristPosInScreen = getScreenPos(body.LeftWristPosInCamera) ; RotateLeftHand(body); drawLeftHand(body); glPopMatrix(); // reload the Neck Matrix glPushMatrix(); // restore the Neck Matrix again . RotateRightShoulder(body); drawRightShoulder(body); glTranslatef(-body.Model.LenNeckToShoulder, 0.0, 0.0); RotateRightUpperArm(body); drawRightUpperArm(body); glTranslatef(-body.Model.LenShoulderToElbow, 0.0, 0.0); RotateRightLowerArm(body); drawRightLowerArm(body); glTranslatef(-body.Model.LenElbowToWrist, 0.0, 0.0); body.RightWristPosInCamera = getCurTranslation () ; body.RightWristPos = TransformVector( WorldMatInv, body.RightWristPosInCamera ) ; body.RightWristPosInScreen = getScreenPos(body.RightWristPosInCamera) ; RotateRightHand(body); drawRightHand(body); glPopMatrix(); // reload the Neck Matrix again . RotateHead(body); drawHead (body); glTranslatef(0.0, body.Model.LenNeckToHead, 0.0); body.HeadPosInCamera = getCurTranslation () ; body.HeadPos = TransformVector( WorldMatInv, body.HeadPosInCamera ) ; body.HeadPosInScreen = getScreenPos(body.HeadPosInCamera) ; glPopMatrix(); // reload the Hip Matrix . glPushMatrix(); // restore the Hip Matrix again. RotateLeftThighRoot (body); drawLeftThighRoot(body); glTranslatef(body.Model.LenHipToThigh, 0.0, 0.0); RotateLeftThigh (body) ; drawLeftThigh(body); glTranslatef(0.0, -body.Model.LenThighToKnee, 0.0); RotateLeftShank(body); drawLeftShank(body); glTranslatef(0.0, -body.Model.LenKneeToAnkle, 0.0); body.LeftAnklePosInCamera = getCurTranslation(); body.LeftAnklePos = TransformVector( WorldMatInv, body.LeftAnklePosInCamera ) ; body.LeftAnklePosInScreen = getScreenPos(body.LeftAnklePosInCamera) ; RotateLeftFoot (body); drawLeftFoot(body); glPopMatrix(); // reload the Hip Matrix again. RotateRightThighRoot (body); drawRightThighRoot(body); glTranslatef(-body.Model.LenHipToThigh, 0.0, 0.0); RotateRightThigh (body) ; drawRightThigh(body); glTranslatef(0.0, -body.Model.LenThighToKnee, 0.0); RotateRightShank(body); drawRightShank(body); glTranslatef(0.0, -body.Model.LenKneeToAnkle, 0.0); body.RightAnklePosInCamera = getCurTranslation(); body.RightAnklePos = TransformVector( WorldMatInv, body.RightAnklePosInCamera ) ; body.RightAnklePosInScreen = getScreenPos(body.RightAnklePosInCamera) ; RotateRightFoot (body); drawRightFoot(body); glPopMatrix(); }
void snap( sf::Font& font ) { sf::RenderWindow window( sf::VideoMode( getScreenSize().x, getScreenSize().y ), "QuickSnap - Snap", sf::Style::None ); window.setFramerateLimit( 30 ); setTransparent( window, 128 ); moveToPos( window, getScreenPos() ); sf::CircleShape circ; circ.setRadius( 4 ); circ.setFillColor( sf::Color::Black ); circ.setOrigin( 4, 4 ); sf::RectangleShape rect; rect.setOutlineColor( sf::Color::Black ); rect.setOutlineThickness( 3 ); rect.setFillColor( sf::Color( 255, 255, 255, 64 ) ); bool didFirstClick = false; bool didFirstRelease = false; bool isRunning = true; while ( isRunning ) { moveToTop( window ); focus( window ); sf::Event event; while ( window.pollEvent( event ) ) { if ( event.type == sf::Event::KeyPressed ) { if ( event.key.code == sf::Keyboard::Return ) { window.close(); takeSnapshot( rect ); isRunning = false; } else if ( event.key.code == sf::Keyboard::Escape ) { isRunning = false; } } else if ( event.type == sf::Event::MouseButtonPressed ) { if ( event.mouseButton.button == sf::Mouse::Left ) { didFirstClick = true; didFirstRelease = false; rect.setPosition( event.mouseButton.x, event.mouseButton.y ); } } else if ( event.type == sf::Event::MouseButtonReleased ) { if ( event.mouseButton.button == sf::Mouse::Left ) { didFirstRelease = true; fixRect( window, rect ); } } } fixCircle( window, circ ); if ( !didFirstRelease ) { fixRect( window, rect ); } window.clear( sf::Color( 255, 255, 255, 64 ) ); if ( didFirstClick ) { window.draw( rect ); } window.draw( circ ); window.display(); } }
static void editfile(char *filename){ int mode = 0; //1 edit mode printbuffer(); int location = k_strlen(file_buffer); typeOffset =(location+1)*2; updateCursor(typeOffset/2); typeTeBottom(); key next; while(1){ if(key_queue_is_empty()) continue; next = remove_key(); if(mode){ if(next.scancode==75 && location>0){ location--; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//left arrow if(next.scancode==77 && location<fileBufferLength()-1){ location++; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//right arrow if(next.scancode==72 && getScreenPos(location)>VGA_W){ int desired = getScreenPos(location)-VGA_W; while(getScreenPos(location)>desired) location--; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//up arrow if(next.scancode==80 && getScreenPos(location)/VGA_W<getScreenPos(fileBufferLength())/VGA_W){ int desired = getScreenPos(location)+VGA_W; while(getScreenPos(location)<desired && location<fileBufferLength()-1) location++; if(getScreenPos(location)>desired) location--; typeOffset =2*getScreenPos(location); updateCursor(typeOffset/2);}//down arrow if(next.key==27) { mode =0; typeTeBottom(); continue; } if(next.key==0) continue; if(next.key!='\b') addToFileBuff(next.key, location++);//file_buffer[location++]=next.key; else removeFromFileBuff(location--);//file_buffer[--location]=0; clearScreen(); printbuffer(); typeOffset = 2*getScreenPos(location); updateCursor(typeOffset/2); } else{ if(next.key=='q') break; else if(next.key=='w') createorreplacefile(filename, file_buffer); else if(next.key=='e') { mode = 1; clearScreen(); printbuffer();} } } }
/* returns the position of the locator relative to the lower left corner of the widget */ KPosition KWidget::getLocatorWidgetPos () const { return KEventHandler::getMousePos() - getScreenPos(); }
// -------------------------- void GuiLabel::draw() const { iPoint p = getScreenPos(); app->render->blit(texture, p.x, p.y, NULL, 0.0f); }
static inline int getScreenY () { return getScreenPos().y; }
static inline int getScreenX () { return getScreenPos().x; }