void Light::init(const int &range, const Uint32 &color) { this->range = range; colorMap = new Uint32[range]; pixelLock = NULL; SCREEN_WIDTH_old = -1; setScreenSize(); Uint8* colorMapIt = (Uint8*)colorMap; Uint8* colorIt = (Uint8*)&color; for (int i=0; i<range; i++) { colorIt = (Uint8*)&color; for (int j=0; j<4; j++) { (*colorMapIt) = ((*colorIt)*range - (*colorIt)*i)/range; colorMapIt++; colorIt++; } } updatePrecision(); }
void Crafting::draw() { setScreenSize(); apply_surface(craftingX, craftingY, load_image("CraftingGUI/G_W_crafting_liste.png"), screen); unsigned int pos = 0; for (unsigned int i=craftingListPage*craftingListEntriesPerPage; i<recipes.size() && pos<craftingListEntriesPerPage; i++, pos++) { recipes[i]->draw(craftingX+listOffsetX, craftingY+listOffsetY + pos*craftingRecipeHeight); } if (activeRecipeIndex != -1) { recipes[activeRecipeIndex]->drawActive(craftingX+activeOffsetX, craftingY+activeOffsetY); } if (craftingListPage > 0) { apply_surface(craftingX+pagginationXButtonLeft, craftingY+pagginationYButton, load_image("CraftingGUI/left.jpg"), screen); } if (craftingListPage < craftingListPages) { apply_surface(craftingX+pagginationXButtonRight, craftingY+pagginationYButton, load_image("CraftingGUI/right.jpg"), screen); } SDL_Color color = {0,0,0}; apply_font(craftingX+pagginationXButtonLeft+35, craftingY+pagginationYButton, screen, load_font("arial.ttf", 15), to_string(craftingListPage) + "/" + to_string(craftingListPages), color); }
void ClientEntity::setAnimationType (const Animation& animation) { _animation = &animation; SoundControl.halt(_animationSound); _animationSound = -1; SoundMappingConstIter soundIter = _soundMapping.find(_animation); if (soundIter != _soundMapping.end()) { _animationSound = SoundControl.play(soundIter->second, getPos(), _animation->loop); } const std::string name = SpriteDefinition::get().getSpriteName(_type, *_animation); if (name.empty()) return; SpritesMapConstIter i = _sprites.find(_animation); if (i == _sprites.end()) { _currSprite = SpritePtr(UI::get().loadSprite(name)->copy()); _currSprite->setLoop(_animation->loop); _sprites[_animation] = _currSprite; } else { _currSprite = i->second; } if (!_animation->loop) _currSprite->setCurrentFrame(0); setScreenSize(_currSprite->getMaxWidth(), _currSprite->getMaxHeight()); }
void SDeclarativeScreenPrivateResize::privateSetOrientation(int orientation) { if (orientation == SDeclarativeScreen::All || orientation == SDeclarativeScreen::LandscapeInverted || orientation == SDeclarativeScreen::PortraitInverted) return; if (m_allowedOrientations != SDeclarativeScreen::Default && !(m_allowedOrientations & orientation)) return; QSize newScreenSize = m_displaySize; if(orientation == SDeclarativeScreen::Default) orientation = portraitDisplay() ? SDeclarativeScreen::Portrait : SDeclarativeScreen::Landscape; if (orientation == SDeclarativeScreen::Portrait && !portraitDisplay()) newScreenSize.transpose(); else if (orientation == SDeclarativeScreen::Landscape && portraitDisplay()) newScreenSize.transpose(); if (m_view) m_view->resize(newScreenSize); else setScreenSize(newScreenSize); }
EJCanvasContext::EJCanvasContext(short widthp, short heightp) : viewFrameBuffer(0), viewRenderBuffer(0), msaaFrameBuffer(0), msaaRenderBuffer(0), stencilBuffer(0),vertexBufferIndex(0) { memset(stateStack, 0, sizeof(stateStack)); stateIndex = 0; state = &stateStack[stateIndex]; state->globalAlpha = 1; state->globalCompositeOperation = kEJCompositeOperationSourceOver; state->transform = CGAffineTransformIdentity; state->lineWidth = 1; state->lineCap = kEJLineCapButt; state->lineJoin = kEJLineJoinMiter; state->miterLimit = 10; state->textBaseline = kEJTextBaselineAlphabetic; state->textAlign = kEJTextAlignStart; //state->font = [[UIFont fontWithName:@"Helvetica" size:10] retain]; state->font = new UIFont(NSStringMake("simsun.ttc"),32); state->clipPath = NULL; setScreenSize(widthp, heightp); path = new EJPath(); backingStoreRatio = 1; fontCache = new NSCache(); fontCache->setCountLimit(8); imageSmoothingEnabled = true; msaaEnabled = false; msaaSamples = 2; }
void Light::shine(int x, int y) { if (lightPrecision != precisionShift) { updatePrecision(); } setScreenSize(); for (int i = pixelCount - 1; i >= 0 ; i--) { pixelLock[i] = range; } x -= ((int32_t)world.player.x)%precisionAdd; y -= ((int32_t)world.player.y)%precisionAdd; this->x = x; this->y = y; int offset = y*SCREEN_WIDTH + x; pushIfValid(new LightHelper(this, x, y, 0, distanceMap, pixelLock+offset, lightMap+offset, ((Uint32*)lightScreen->pixels)+offset)); LightHelper* LightHelper; while (!queue.empty()) { LightHelper = queue.top(); queue.pop(); LightHelper->shine(); delete LightHelper; } }
void SunLight::init() { SDL_Surface* dayTime = load_image("Paralax/Tageszeiten.png"); dayTimePixelCount = dayTime->h * dayTime->w; range = 100; dayTimeColorMap = new Uint32[range * dayTimePixelCount]; pixelLock = NULL; SCREEN_WIDTH_old = -1; setScreenSize(); Uint32* dayTimePixels = (Uint32*)dayTime->pixels; Uint8* dayTimeColorMapIt = (Uint8*)dayTimeColorMap; Uint8* colorIt = (Uint8*)&dayTimePixels; for (int colorI = 0; colorI<dayTimePixelCount; colorI++) { for (int i=0; i<range; i++) { colorIt = (Uint8*)&dayTimePixels[colorI]; for (int j=0; j<4; j++) { (*dayTimeColorMapIt) = ((*colorIt)*range - (*colorIt)*i)/range; dayTimeColorMapIt++; colorIt++; } } } updatePrecision(); }
ClientMapTile::ClientMapTile (const EntityType& type, uint16_t id, const std::string& sprite, const Animation& animation, float x, float y, float sizeX, float sizeY, EntityAngle angle, const SoundMapping& soundMapping, EntityAlignment align) : ClientEntity(type, id, x, y, sizeX, sizeY, soundMapping, align, angle) { _currSprite = UI::get().loadSprite(sprite); if (_currSprite->getFrameCount() > 1) _currSprite = SpritePtr(_currSprite->copy()); setScreenSize(_currSprite->getMaxWidth(), _currSprite->getMaxHeight()); }
bool SDeclarativeScreenPrivateResize::eventFilter(QObject *obj, QEvent *event) { Q_UNUSED(obj); if (m_initialized && event->type() == QEvent::Resize) { QSize size = static_cast<QResizeEvent*>(event)->size(); setScreenSize(size); } return QObject::eventFilter(obj, event); }
void SDeclarativeScreenPrivateResize::setAllowedOrientations(SDeclarativeScreen::Orientations orientations) { #ifdef Q_DEBUG_SCREEN qDebug() << "SDeclarativeScreenPrivateResize::setAllowedOrientations" << orientations; #endif #if defined(Q_OS_SYMBIAN) if((orientations != SDeclarativeScreen::Landscape) && deviceSupportsOnlyLandscape()) return; #endif SDeclarativeScreenPrivate::setAllowedOrientations(orientations); if (!m_initialized) return; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR) if (portraitAllowed() && landscapeAllowed() && m_view) m_view->setAttribute(Qt::WA_AutoOrientation, true); else if (portraitAllowed() && !landscapeAllowed() && m_view) m_view->setAttribute(Qt::WA_LockPortraitOrientation, true); else if (!portraitAllowed() && landscapeAllowed() && m_view) m_view->setAttribute(Qt::WA_LockLandscapeOrientation, true); setScreenSize(enforceFixedOrientation(systemScreenSize())); #else QSize newScreenSize = m_displaySize; if (portraitAllowed() && landscapeAllowed() && !portraitDisplay()) newScreenSize.transpose(); else if (portraitAllowed() && !landscapeAllowed() && !portraitDisplay()) newScreenSize.transpose(); else if (!portraitAllowed() && landscapeAllowed() && portraitDisplay()) newScreenSize.transpose(); if (m_view) m_view->resize(newScreenSize); else setScreenSize(newScreenSize); #endif }
//-------------------------------------------------------------- // initialize for scene rendering void mgGL33Services::initView() { int windowX, windowY, windowWidth, windowHeight; mgPlatform->getWindowBounds(windowX, windowY, windowWidth, windowHeight); setScreenSize(windowWidth, windowHeight); setDPI(mgPlatform->getDPI()); // if window is still 0 by 0, it's too early. wait for real resize if (m_graphicsWidth <= 0 || m_graphicsHeight <= 0) return; mgDebug("view size is %d by %d", m_graphicsWidth, m_graphicsHeight); setProjection(); }
LevelEditor::LevelEditor(string fileName, Window* window) { this->window = window; texture = new sf::Texture; texture->loadFromFile(fileName + ".png"); textureBackground = new sf::Texture; textureBackground->loadFromFile(fileName + 'b' + ".png"); offsetHider = new sf::RectangleShape; offsetHider->setFillColor(sf::Color(0, 0, 0, 255)); sprite = new sf::RectangleShape(sf::Vector2f(tileSize.x, tileSize.y)), sprite->setTexture(texture); spriteBackground = new sf::RectangleShape(sf::Vector2f(tileSize.x, tileSize.y)); spriteBackground->setTexture(textureBackground); setScreenSize(); }
int main(int argc, char* argv[]) { getScreenshot(std::string(SCRSHOT_NAME)); std::this_thread::sleep_for(std::chrono::microseconds(10000)); //give the screenshot script time to run int h=0; if (SDL_Init(SDL_INIT_VIDEO) < 0 ) { printf("Unable to initialize SDL"); return 1; } if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL))) { SDL_Quit(); return 1; } #if startFullscreen toggleFullscreen(); #endif //set up SDL's OpenGL defaults SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); setScreenSize(getImageSize(SCRSHOT_NAME)); WIDTH = getScreenSize().w; HEIGHT = getScreenSize().h; printf("Screen size detected as: (%d,%d)\n",getScreenSize().w,getScreenSize().h); loadGame(); running = true; startFPSCounter(); startInputListener(); startAutomaticFiring(); while(running) { drawScreen(screen,h++); } SDL_Quit(); return 0; }
Graphics::Graphics(Profile &profile) : mMinAspect(0.0f), mMaxAspect(0.0f), mVSync(true), mFPSTime(0), mNumFrames(0), mFPS(0.0f), mBlendMode(BLEND_ALPHA) { // setup the graphics settings CL_DisplayWindowDescription desc; desc.set_title("Balance"); desc.set_size(CL_Size(profile.getInt("width", 1024), profile.getInt("height", 768)), true); desc.set_swap_interval(mVSync ? 1 : 0); if (profile.getBool("fullscreen", true)) { desc.set_decorations(false); desc.set_fullscreen(true); } else { desc.set_allow_resize(true); } mWindow = CL_DisplayWindow(desc); // make window visible while debugging under SciTE mWindow.show(); // connect window signals mSlots.connect(Application::getSingleton().getSigUpdate(), this, &Graphics::onUpdate); mSlots.connect(mWindow.get_ic().get_mouse().sig_key_down(), this, &Graphics::onMouseDown); mSlots.connect(mWindow.get_ic().get_mouse().sig_key_dblclk(), this, &Graphics::onMouseDown); mSlots.connect(mWindow.get_ic().get_mouse().sig_key_up(), this, &Graphics::onMouseUp); mSlots.connect(mWindow.sig_resize(), this, &Graphics::onResize); mSlots.connect(mWindow.sig_window_close(), this, &Graphics::onClose); // initialize the graphics settings mWindow.get_gc().set_map_mode(cl_user_projection); setScreenSize(1024.0f, 768.0f); setBlendMode(mBlendMode); // save the current settings profile.setBool("fullscreen", desc.is_fullscreen()); profile.setInt("width", desc.get_size().width); profile.setInt("height", desc.get_size().height); }
/* X thread that processes X events in parallel to kernel device loop */ void handleXEvent() { XEvent ev; XNextEvent(display, &ev); //if(debugMode) printf("Handle event\n"); if (XGetEventData(display, &(ev.xcookie))) { XGenericEventCookie *cookie = &(ev.xcookie); // Touch events don't work right now //if (cookie->evtype == XI_TouchBegin) { // if(debugMode) printf("Touch begin\n"); //} else if (cookie->evtype == XI_TouchUpdate) { // if(debugMode) printf("Touch update\n"); //} else if (cookie->evtype == XI_TouchEnd) { // if(debugMode) printf("Touch end\n"); if (cookie->evtype == XI_Motion) { if(debugMode) printf("Motion event\n"); //int r = XIAllowEvents(display, deviceID, XIReplayDevice, CurrentTime); //printf("XIAllowEvents result: %i\n", r); } else if (cookie->evtype == XI_PropertyEvent) { /* Device properties changed -> recalibrate. */ if(debugMode) printf("Device properties changed.\n"); readCalibrationData(0); } else if(cookie->evtype == XI_ButtonPress) { if(debugMode) printf("Button Press\n"); //int r = XIAllowEvents(display, deviceID, XIReplayDevice, CurrentTime); //printf("XIAllowEvents result: %i\n", r); } // In an ideal world, the following would work. But unfortunately the touch events // delivered by evdev are often crap on the eGalax screen, with missing events when there // should be some. So we still have to read directly from the input device, as bad as that is. //if (cookie->evtype == XI_TouchBegin || cookie->evtype == XI_TouchUpdate || cookie->evtype == XI_TouchEnd) { // XIDeviceEvent * devEvt = (XIDeviceEvent*) cookie->data; // printf("Detail: %i\n", devEvt->detail); // printf("Mask[0]: %i\n", (int) devEvt->valuators.mask[0]); // // /* Look for slot to put the data into by looking at the tracking ids */ // int index = -1; // int i; // for(i = 0; i < 2; i++) { // if(fingerInfos[i].id == devEvt->detail) { // index = i; // break; // } // } // // /* No slot for this id found, look for free one */ // if(index == -1) { // for(i = 0; i < 2; i++) { // if(!fingerInfos[i].slotUsed) { // /* "Empty" slot, so we can add it. */ // index = i; // fingerInfos[i].id = devEvt->detail; // break; // } // } // } // // /* We have found a slot */ // if(index != -1) { // fingerInfos[index].slotUsed = (cookie->evtype != XI_TouchEnd ? 1 : 0); // // i = 0; // if((devEvt->valuators.mask[0] & 1) == 1) // { // fingerInfos[index].rawX = (int) devEvt->valuators.values[i++]; // } // if((devEvt->valuators.mask[0] & 2) == 2) // { // fingerInfos[index].rawY = (int) devEvt->valuators.values[i++]; // } // if((devEvt->valuators.mask[0] & 4) == 4) // { // fingerInfos[index].rawZ = (int) devEvt->valuators.values[i++]; // } // } // // processFingers(); //} XFreeEventData(display, &(ev.xcookie)); } else { if(ev.type == 101) { /* Why isn't this magic constant explained anywhere?? */ setScreenSize((XRRScreenChangeNotifyEvent *) &ev); } } }
void TextRendererTTF::setScreenSize(sf::Vector2u size) { setScreenSize(size.x, size.y); }
void setup_glut(int argc, char **argv){ int i; char *smoketempdir; size_t lensmoketempdir; #ifdef pp_OSX char workingdir[1000]; #endif // get smokeview bin directory from argv[0] which contains the full path of the smokeview binary NewMemory((void **)&smokeviewini, (unsigned int)(strlen(smokeview_bindir)+14)); STRCPY(smokeviewini,smokeview_bindir); STRCAT(smokeviewini,"smokeview.ini"); startup_pass=2; smoketempdir=getenv("SVTEMPDIR"); if(smoketempdir==NULL)smoketempdir=getenv("svtempdir"); if(smoketempdir==NULL)smoketempdir=getenv("TEMP"); if(smoketempdir==NULL)smoketempdir=getenv("temp"); if(smoketempdir==NULL){ NewMemory((void **)&smoketempdir,8); #ifdef pp_LINUX strcpy(smoketempdir,"/tmp"); #endif #ifdef pp_OSX strcpy(smoketempdir,"/tmp"); #endif #ifdef WIN32 strcpy(smoketempdir,"c:\temp"); #endif } if(smoketempdir != NULL){ lensmoketempdir = strlen(smoketempdir); if(NewMemory((void **)&smokeviewtempdir,(unsigned int)(lensmoketempdir+2))!=0){ STRCPY(smokeviewtempdir,smoketempdir); if(strncmp(smokeviewtempdir+lensmoketempdir-1,dirseparator,1)!=0){ STRCAT(smokeviewtempdir,dirseparator); } PRINTF("%s",_("Scratch directory:")); PRINTF(" %s\n",smokeviewtempdir); } } #ifdef pp_BETA fprintf(stderr,"%s\n",_("*** This version of Smokeview is intended for review and testing ONLY. ***")); #endif #ifdef pp_OSX getcwd(workingdir,1000); #endif if(use_graphics==1){ PRINTF("\n"); PRINTF("%s",_("Initializing Glut\n")); glutInit(&argc, argv); PRINTF("%s\n",_("Glut initialization completed\n")); } #ifdef pp_OSX chdir(workingdir); #endif if(use_graphics==1){ #ifdef _DEBUG PRINTF("%s",_("Initializing Smokeview graphics window - ")); #endif glutInitWindowSize(screenWidth, screenHeight); #ifdef _DEBUG PRINTF("%s\n",_("initialized")); #endif max_screenWidth = glutGet(GLUT_SCREEN_WIDTH); max_screenHeight = glutGet(GLUT_SCREEN_HEIGHT); if(trainer_mode==1){ int TRAINER_WIDTH; int scrW, scrH; TRAINER_WIDTH=300; scrW = glutGet(GLUT_SCREEN_WIDTH)-TRAINER_WIDTH; scrH = glutGet(GLUT_SCREEN_HEIGHT)-50; setScreenSize(&scrW,&scrH); max_screenWidth = screenWidth; max_screenHeight = screenHeight; } InitOpenGL(); } NewMemory((void **)&rgbptr,MAXRGB*sizeof(float *)); for(i=0;i<MAXRGB;i++){ rgbptr[i]=&rgb[i][0]; } NewMemory((void **)&rgb_plot3d_contour,MAXRGB*sizeof(float *)); for(i=0;i<nrgb-2;i++){ int ii; float factor; factor=256.0/(float)(nrgb-2); ii = factor*((float)i+0.5); if(ii>255)ii=255; rgb_plot3d_contour[i]=&rgb_full[ii][0]; } rgb_plot3d_contour[nrgb-2]=&rgb_full[0][0]; rgb_plot3d_contour[nrgb-1]=&rgb_full[255][0]; }
void SunLight::shine() { if (lightPrecision != precisionShift) { updatePrecision(); } setScreenSize(); int64_t xy64; unordered_map<int64_t, FieldBack*>::const_iterator backIt; int32_t worldXStart = (int32_t)world.player.x - SCREEN_WIDTH/2; int32_t worldXStartGridded = (int32_t)floor(worldXStart / GRID_SIZE) - 1; int32_t worldXEndGridded = worldXStartGridded + (int32_t)ceil(SCREEN_WIDTH / GRID_SIZE) + 1; int32_t worldYStart = (int32_t)world.player.y - SCREEN_HEIGHT/2; int32_t worldYStartGridded = (int32_t)floor(worldYStart / GRID_SIZE); int32_t worldYEndGridded = worldYStartGridded + (int32_t)ceil(SCREEN_HEIGHT / GRID_SIZE); int dayTimeIndex = (int)((double)dayTime/dayTimeMax * (dayTimePixelCount-1)); colorMap = &dayTimeColorMap[dayTimeIndex * range]; for (int i = pixelCount - 1; i >= 0 ; i--) { pixelLock[i] = range; } for(int32_t xGriddedWorld = worldXStartGridded; xGriddedWorld <= worldXEndGridded; xGriddedWorld++) { int wallness = 0; for (int32_t worldYGridded = worldYStartGridded-300; worldYGridded < worldYStartGridded; worldYGridded++) { //collsion test outside viewport xy64 = world.int64FromXY(xGriddedWorld, worldYGridded); backIt = world.mapBack.find(xy64); if (backIt != world.mapBack.end()) { if (backIt->second != NULL) { for (int i = 0; i<backIt->second->metricsLength; i++) { if (backIt->second->metrics[i].collidesWith(xGriddedWorld*GRID_SIZE, worldYGridded*GRID_SIZE)) { wallness += GRID_SIZE; } } } } if (wallness >= range) { break; } } //collsion test inside viewport xy64 = world.int64FromXY(xGriddedWorld, worldYStartGridded); backIt = world.mapBack.find(xy64); if (backIt != world.mapBack.end()) { if (backIt->second != NULL) { for (int i = 0; i<backIt->second->metricsLength; i++) { if (backIt->second->metrics[i].intersectsWith(xGriddedWorld*GRID_SIZE, worldYStartGridded*GRID_SIZE)) { wallness += precisionAdd - worldYStart%precisionAdd; } } } } if (wallness < range) { int yOffset = -((int32_t)world.player.y)%precisionAdd; int yOffsetTimesWidth = yOffset*SCREEN_WIDTH; //push start nodes int xStart = xGriddedWorld*GRID_SIZE-worldXStart; int xEnd = xGriddedWorld*GRID_SIZE-worldXStart+GRID_SIZE; for (int x = xStart; x < xEnd; x += precisionAdd) { pushIfValid(new SunLightHelper(this, x, yOffset, wallness, pixelLock+yOffsetTimesWidth+x, lightMap+yOffsetTimesWidth+x, ((Uint32*)lightScreen->pixels)+yOffsetTimesWidth+x)); } } } SunLightHelper* sunLightHelper; Uint32 start = SDL_GetTicks(); while (!queue.empty()) { sunLightHelper = queue.top(); queue.pop(); sunLightHelper->shine(); delete sunLightHelper; } }