int BEE::Background::tile_vertical(const SDL_Rect* r) const { if (r->w <= 0) { return -1; } SDL_Rect src = {0, 0, r->w, r->h}; SDL_Rect dest = {r->x, r->y, r->w, r->h}; int i=0; while (dest.y < game->get_room_height()) { draw_internal(&src, &dest); i++; src.h = r->h; dest.h = r->h; dest.y += r->h; } dest.y = r->y - dest.h; while (dest.y + dest.h > 0) { draw_internal(&src, &dest); i++; dest.y -= r->h; } return i; }
int BEE::Background::tile_horizontal(const SDL_Rect* r) const { if (r->w <= 0) { return -1; } SDL_Rect src = {0, 0, r->w, r->h}; SDL_Rect dest = {r->x, r->y, r->w, r->h}; int i=0; while (dest.x < game->get_room_width()) { draw_internal(&src, &dest); i++; src.w = r->w; dest.w = r->w; dest.x += dest.w; } dest.x = r->x; while (dest.x + dest.w > 0) { draw_internal(&src, &dest); i++; dest.x -= dest.w; } return i; }
TextData* BEE::Font::draw(int x, int y, std::string text, RGBA color) { if (is_loaded) { TextData *r = nullptr, *textdata = nullptr; std::map<int,std::string> lines = handle_newlines(text); if (lineskip == 0) { lineskip = TTF_FontLineSkip(font); } for (auto& l : lines) { r = draw_internal(x, y+lineskip*l.first, l.second, color); if (r != nullptr) { if (textdata == nullptr) { textdata = r; } else { textdata->sprite.insert(std::make_pair(textdata->sprite.size(), r->sprite[0])); delete r; } } } return textdata; } if (!has_draw_failed) { game->messenger_send({"engine", "font"}, BEE_MESSAGE_WARNING, "Failed to draw text with \"" + name + "\" because it is not loaded"); has_draw_failed = true; } return nullptr; }
int BEE::Background::draw(int x, int y, BackgroundData* b) { SDL_Rect rect; if (b->is_stretched) { rect.x = 0; rect.y = 0; rect.w = game->get_room_width(); rect.h = game->get_room_height(); draw_internal(nullptr, &rect); } else { int dx = b->horizontal_speed*(SDL_GetTicks()-animation_time)/game->fps_goal; int dy = b->vertical_speed*(SDL_GetTicks()-animation_time)/game->fps_goal; int mx = (width <= 0) ? 0 : game->get_room_width() - (game->get_room_width() % width); int my = (height <= 0) ? 0 : game->get_room_height() - (game->get_room_height() % height); if ((mx > 0)&&(my > 0)) { dx %= mx; dy %= my; } rect.x = x + dx; rect.y = y + dy; rect.w = width; rect.h = height; if ((rect.w > 0)&&(rect.h > 0)) { if (b->is_horizontal_tile && b->is_vertical_tile) { while (rect.y-rect.h < game->get_room_height()) { tile_horizontal(&rect); rect.y += rect.h; } rect.y = y + dy - rect.h; while (rect.y+rect.h > 0) { tile_horizontal(&rect); rect.y -= rect.h; } } else if (b->is_horizontal_tile) { tile_horizontal(&rect); } else if (b->is_vertical_tile) { tile_vertical(&rect); } else { draw_internal(nullptr, &rect); } } } return 0; }
int App::run() { try{init(); m_running = GL_TRUE;} catch(std::exception &e){LOG_ERROR<<e.what();} double timeStamp = 0.0; // Main loop while( m_running ) { // update application time timeStamp = getApplicationTime(); // poll io_service if no seperate worker-threads exist if(!m_main_queue.get_num_threads()) m_main_queue.io_service().poll(); // poll input events pollEvents(); // time elapsed since last frame double time_delta = timeStamp - m_lastTimeStamp; // call update callback update(time_delta); m_lastTimeStamp = timeStamp; if(needs_redraw()) { // call draw callback draw_internal(); // Swap front and back rendering buffers swapBuffers(); } // perform fps-timing timing(timeStamp); // Check if ESC key was pressed or window was closed or whatever m_running = checkRunning(); // fps managment float current_fps = 1.f / time_delta; if(current_fps > m_max_fps) { double sleep_secs = std::max(0.0, (1.0 / m_max_fps - time_delta)); this_thread::sleep_for(duration_t(sleep_secs)); } } // manage tearDown, save stuff etc. tearDown(); return EXIT_SUCCESS; }
void PictureWidget::static_init(std::string image_path) { _image = new WIPTexture(image_path.c_str()); _binit = true; _fbo->resize(_width,_height); draw_internal(); }
void PictureWidget::reset_pic(const char* path) { delete _image; _image = new WIPTexture(path); draw_internal(); /* if(!_fbo.isAllocated()) return; _fbo.begin(); ofClear(0,0,0,0); _font.drawString(_str,_x_space,_height - (_height-_line_height)/2.f); _fbo.end(); */ }
void ButtonWidget::update(float dt) { ActiveDrawableRect::update(dt); int mouse_x = Input::get_mouse_x(); int mouse_y = Input::get_mouse_y(); //if left button is pressed state.Ture for pressed. bool bpressed = Input::get_sys_key_pressed(WIP_MOUSE_LBUTTON); if(_last_mouse_state==0&&bpressed==1) set_mouse_state(mouse_x,mouse_y,1 ); else if(_last_mouse_state==1&&bpressed==0) set_mouse_state(mouse_x,mouse_y,2 ); update_button(mouse_x,mouse_y); //set_mouse_state(mouse_x,mouse_y,bpressed? 1 : 2 ); draw_internal(); _last_mouse_state = bpressed; }
/** * The method draws the selected curve with the polygon as an outline with * markers at the control points * * @param selected selected point that will be drawn differently */ void CubicSpline::draw_selected(const Point* selected) const { Color outline = model_->get_outline_color(); glColor3f(outline.get_red(), outline.get_green(), outline.get_blue()); Polygon::draw_internal(); // draw outline glColor3f(color_->get_red(), color_->get_green(), color_->get_blue()); draw_internal(); // draw curve //draw markers for(std::vector<Point>::iterator i = object_->begin(); i != object_->end(); ++i) { if(selected != NULL && selected == &*i) { marker_selected(*i); } else { marker(*i); } } }
/*! * \brief * Render the object * * The base class do basic matrix stuff: * set model view matrix to identity and do translation and rotation * if you need to manipulate the model matrix internally you have * to do this in the draw function */ void AbstractObjectBase::render() { draw_internal(); }
void PictureWidget::reshape(int width,int height,int x,int y) { ActiveDrawableRect::reshape(width,height,x,y); draw_internal(); }