/* CTextureCanvas::draw * Draws the canvas contents *******************************************************************/ void CTextureCanvas::draw() { // Setup the viewport glViewport(0, 0, GetSize().x, GetSize().y); // Setup the screen projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Clear glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations) if (OpenGL::accuracyTweak()) glTranslatef(0.375f, 0.375f, 0); // Draw background drawCheckeredBackground(); // Pan by view offset glTranslated(offset.x, offset.y, 0); // Draw texture if (texture) drawTexture(); // Swap buffers (ie show what was drawn) SwapBuffers(); }
// ----------------------------------------------------------------------------- // Draw the canvas contents // ----------------------------------------------------------------------------- void CropCanvas::draw() { // Setup for 2d setup2D(); // Draw background drawCheckeredBackground(); // Determine graphic position & scale double width = GetSize().x; double height = GetSize().y; // Get image dimensions auto& tex_info = OpenGL::Texture::info(texture_); double x_dim = (double)tex_info.size.x; double y_dim = (double)tex_info.size.y; // Get max scale for x and y (including padding) double x_scale = ((double)width - UI::scalePx(24)) / x_dim; double y_scale = ((double)height - UI::scalePx(24)) / y_dim; // Set scale to smallest of the 2 (so that none of the texture will be clipped) double scale = std::min<double>(x_scale, y_scale); glPushMatrix(); glTranslated(width * 0.5, height * 0.5, 0); // Translate to middle of area glScaled(scale, scale, scale); // Scale to fit within area // Draw graphic double hw = 0; double hh = 0; if (texture_) { glEnable(GL_TEXTURE_2D); hw = x_dim * -0.5; hh = y_dim * -0.5; Drawing::drawTexture(texture_, hw, hh); } // Draw cropping rectangle OpenGL::setColour(0, 0, 0, 255, OpenGL::Blend::Normal); glDisable(GL_TEXTURE_2D); glTranslated(hw, hh, 0); // Translate to top-left of graphic Drawing::drawLine(crop_rect_.tl.x, -1000, crop_rect_.tl.x, 1000); // Left Drawing::drawLine(-1000, crop_rect_.tl.y, 1000, crop_rect_.tl.y); // Top Drawing::drawLine(crop_rect_.br.x, -1000, crop_rect_.br.x, 1000); // Right Drawing::drawLine(-1000, crop_rect_.br.y, 1000, crop_rect_.br.y); // Bottom // Shade cropped-out area OpenGL::setColour(0, 0, 0, 100, OpenGL::Blend::Normal); Drawing::drawFilledRect(-1000, -1000, crop_rect_.tl.x, 1000); // Left Drawing::drawFilledRect(crop_rect_.br.x, -1000, 1000, 1000); // Right Drawing::drawFilledRect(crop_rect_.tl.x, -1000, crop_rect_.br.x, crop_rect_.tl.y); // Top Drawing::drawFilledRect(crop_rect_.tl.x, crop_rect_.br.y, crop_rect_.br.x, 1000); // Bottom glPopMatrix(); SwapBuffers(); }
// ----------------------------------------------------------------------------- // Draws the image/background/etc // ----------------------------------------------------------------------------- void GfxCanvas::draw() { // Setup the viewport glViewport(0, 0, GetSize().x, GetSize().y); // Setup the screen projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Clear glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations) if (OpenGL::accuracyTweak()) glTranslatef(0.375f, 0.375f, 0); // Draw the background drawCheckeredBackground(); // Pan by view offset if (allow_scroll_) glTranslated(offset_.x, offset_.y, 0); // Pan if offsets if (view_type_ == View::Centered || view_type_ == View::Sprite || view_type_ == View::HUD) { int mid_x = GetSize().x / 2; int mid_y = GetSize().y / 2; glTranslated(mid_x, mid_y, 0); } // Scale by UI scale // glScaled(UI::scaleFactor(), UI::scaleFactor(), 1.); // Draw offset lines if (view_type_ == View::Sprite || view_type_ == View::HUD) drawOffsetLines(); // Draw the image drawImage(); // Swap buffers (ie show what was drawn) SwapBuffers(); }
/* SpriteTexCanvas::draw * Draws the canvas content *******************************************************************/ void SpriteTexCanvas::draw() { // Setup the viewport glViewport(0, 0, GetSize().x, GetSize().y); // Setup the screen projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Clear glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations) if (OpenGL::accuracyTweak()) glTranslatef(0.375f, 0.375f, 0); // Draw background drawCheckeredBackground(); // Draw texture OpenGL::setColour(col); if (texture && !icon) { // Sprite glEnable(GL_TEXTURE_2D); Drawing::drawTextureWithin(texture, 0, 0, GetSize().x, GetSize().y, 4, 2); } else if (texture && icon) { // Icon glEnable(GL_TEXTURE_2D); Drawing::drawTextureWithin(texture, 0, 0, GetSize().x, GetSize().y, 0, 0.25); } // Swap buffers (ie show what was drawn) SwapBuffers(); }
// ----------------------------------------------------------------------------- // Draws the canvas content // ----------------------------------------------------------------------------- void FlatTexCanvas::draw() { // Setup the viewport glViewport(0, 0, GetSize().x, GetSize().y); // Setup the screen projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Clear glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations) if (OpenGL::accuracyTweak()) glTranslatef(0.375f, 0.375f, 0); // Draw background drawCheckeredBackground(); // Draw texture if (texture_ && texture_ != OpenGL::Texture::missingTexture()) { glEnable(GL_TEXTURE_2D); Drawing::drawTextureWithin(texture_, 0, 0, GetSize().x, GetSize().y, 0, 100.0); } else if (texture_ == OpenGL::Texture::missingTexture()) { // Draw unknown icon auto tex = MapEditor::textureManager().editorImage("thing/unknown").gl_id; glEnable(GL_TEXTURE_2D); OpenGL::setColour(180, 0, 0); Drawing::drawTextureWithin(tex, 0, 0, GetSize().x, GetSize().y, 0, 0.25); } // Swap buffers (ie show what was drawn) SwapBuffers(); }
void draw() { drawCheckeredBackground(); SwapBuffers(); }
/* BrowserCanvas::draw * Handles drawing of the canvas content *******************************************************************/ void BrowserCanvas::draw() { // Setup the viewport glViewport(0, 0, GetSize().x, GetSize().y); // Setup the screen projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Setup colours rgba_t col_bg, col_text; bool text_shadow = true; if (browser_bg_type == 1) { // Get system panel background colour wxColour bgcolwx = Drawing::getPanelBGColour(); col_bg.set(bgcolwx.Red(), bgcolwx.Green(), bgcolwx.Blue()); // Get system text colour wxColour textcol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); col_text.set(textcol.Red(), textcol.Green(), textcol.Blue()); // Check text colour brightness, if it's dark don't draw text shadow rgba_t col_temp = col_text; wxColor::MakeGrey(&col_temp.r, &col_temp.g, &col_temp.b); if (col_temp.r < 60) text_shadow = false; } else { // Otherwise use black background col_bg.set(0, 0, 0); // And white text col_text.set(255, 255, 255); } // Clear glClearColor(col_bg.fr(), col_bg.fg(), col_bg.fb(), 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations) if (OpenGL::accuracyTweak()) glTranslatef(0.375f, 0.375f, 0); // Draw background if required if (browser_bg_type == 0) drawCheckeredBackground(); // Init for texture drawing glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glLineWidth(2.0f); // Draw items int x = item_border; int y = item_border; int col_width = GetSize().x / num_cols; int col = 0; top_index = -1; for (unsigned a = 0; a < items_filter.size(); a++) { // If we're not yet into the viewable area, skip if (y < yoff - fullItemSizeY()) { col++; if (col >= num_cols) { col = 0; y += fullItemSizeY(); // Canvas is filled, stop drawing if (y > yoff + GetSize().y) break; } continue; } // If we're drawing the first non-hidden item, save it if (top_index < 0) { top_index = a; top_y = y - yoff; } // Determine current x position int xgap = (col_width - fullItemSizeX()) * 0.5; x = item_border + xgap + (col * col_width); // Draw selection box if selected if (item_selected == items[items_filter[a]]) { // Setup glDisable(GL_TEXTURE_2D); glColor4f(0.3f, 0.5f, 1.0f, 0.3f); glPushMatrix(); glTranslated(x, y - yoff, 0); glTranslated(-item_border, -item_border, 0); // Selection background glBegin(GL_QUADS); glVertex2i(2, 2); glVertex2i(2, fullItemSizeY()-3); glVertex2i(fullItemSizeX()-3, fullItemSizeY()-3); glVertex2i(fullItemSizeX()-3, 2); glEnd(); // Selection border glColor4f(0.6f, 0.8f, 1.0f, 1.0f); glBegin(GL_LINE_LOOP); glVertex2i(2, 2); glVertex2i(2, fullItemSizeY()-3); glVertex2i(fullItemSizeX()-3, fullItemSizeY()-3); glVertex2i(fullItemSizeX()-3, 2); glEnd(); // Finish glPopMatrix(); glEnable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } // Draw item if (item_size <= 0) items[items_filter[a]]->draw(browser_item_size, x, y - yoff, font, show_names, item_type, col_text, text_shadow); else items[items_filter[a]]->draw(item_size, x, y - yoff, font, show_names, item_type, col_text, text_shadow); // Move over for next item col++; if (col >= num_cols) { col = 0; y += fullItemSizeY(); // Canvas is filled, stop drawing if (y > yoff + GetSize().y) break; } } // Swap Buffers SwapBuffers(); }