📄 window.cpp
字号:
glTexCoord2f (0.0f, BOTTOM_HEIGHT/(float)tileHeight); glVertex2i (0, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glTexCoord2f (w/(float)tileWidth, BOTTOM_HEIGHT/(float)tileHeight); glVertex2i (w, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glTexCoord2f (w/(float)tileWidth, 0.0f); glVertex2i (w, topY + TOP_HEIGHT + openHeight); glEnd (); } else { glBegin (GL_QUADS); /* glTexCoord2f (0.0f, 0.0f); glVertex2i (0, topY); glTexCoord2f (0.0f, (TOP_HEIGHT + BOTTOM_HEIGHT + openHeight) /(float)tileHeight); glVertex2i (0, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glTexCoord2f (w/(float)tileWidth, (TOP_HEIGHT + BOTTOM_HEIGHT + openHeight)/(float)tileHeight); glVertex2i (w, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glTexCoord2f (w/(float)tileWidth, 0.0f); glVertex2i (w, topY); */ glTexCoord2f (0.0f, 0.0f); glVertex2i (0, topY); glTexCoord2f (0, (TOP_HEIGHT + BOTTOM_HEIGHT + openHeight) / (float)tileHeight); glVertex2i (0, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glTexCoord2f (1, (TOP_HEIGHT + BOTTOM_HEIGHT + openHeight) / (float)tileHeight); glVertex2i (w, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glTexCoord2f (1, 0); glVertex2i (w, topY); glEnd (); } glDisable( GL_TEXTURE_2D ); if(type == BASIC_WINDOW) { if(!isModal()) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } applyBackgroundColor(); glBegin (GL_QUADS); glVertex2i (0, topY + TOP_HEIGHT); glVertex2i (0, topY + TOP_HEIGHT + openHeight); glVertex2i (w, topY + TOP_HEIGHT + openHeight); glVertex2i (w, topY + TOP_HEIGHT); glEnd(); if(!isModal()) { glDisable( GL_BLEND ); } } // draw drop-shadow glEnable( GL_BLEND ); // glBlendFunc( GL_SRC_ALPHA, GL_DST_COLOR ); glBlendFunc( GL_SRC_COLOR, GL_DST_COLOR ); int n = 10; glColor4f( 0.15f, 0.15f, 0.15f, 0.25f ); glBegin(GL_QUADS); glVertex2i (n, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2i (n, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT + n); glVertex2i (w + n, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT + n); glVertex2i (w + n, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2i (w, topY + n); glVertex2i (w, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2i (w + n, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2i (w + n, topY + n); glEnd(); glDisable( GL_BLEND ); // add a border applyBorderColor(); glLineWidth( isModal() ? 3.0f : 2.0f ); glBegin(GL_LINES); glVertex2d(w, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2d(0, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2d(0, topY); glVertex2d(w, topY); glVertex2d(0, topY); glVertex2d(0, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glVertex2d(w, topY); glVertex2d(w, topY + TOP_HEIGHT + openHeight + BOTTOM_HEIGHT); glEnd(); glLineWidth( 1.0f ); if(type == BASIC_WINDOW) { glBegin(GL_LINES); glVertex2i (0, topY + TOP_HEIGHT); glVertex2i (w, topY + TOP_HEIGHT); glVertex2i (0, topY + TOP_HEIGHT + openHeight); glVertex2i (w, topY + TOP_HEIGHT + openHeight); glEnd(); } // print title if(title) { glPushMatrix(); glTranslated( 0, 0, 5 ); glColor3f( 1, 1, 1 ); sdlHandler->texPrint(10, topY + 13, "%s", title); glPopMatrix(); } // draw the close button if(closeButton) { // apply the window's color scheme closeButton->setColor( getColor() ); closeButton->setBackground( getBackgroundColor() ); closeButton->setSelectionColor( getSelectionColor() ); closeButton->setBorderColor( getBorderColor() ); glPushMatrix(); //glLoadIdentity(); glTranslated(w - (closeButton->getWidth() + 3), topY + 3, z + 5); closeButton->draw(this); glPopMatrix(); } // draw widgets if(isOpening()) { scissorToWindow(); } for(int i = 0; i < widgetCount; i++) { if(widget[i]->isVisible()) { glPushMatrix(); glLoadIdentity(); // if this is modified, also change handleWindowEvent glTranslated(x, y + TOP_HEIGHT, z + 5); widget[i]->draw(this); glPopMatrix(); } } if(isOpening()) { glDisable( GL_SCISSOR_TEST ); } glEnable( GL_TEXTURE_2D ); glPopMatrix(); //glEnable( GL_DEPTH_TEST );}Button *Window::createButton(int x1, int y1, int x2, int y2, char *label, bool toggle){ if(widgetCount < MAX_WIDGET){ Button * theButton; theButton = new Button(x1, y1, x2, y2, label); theButton->setToggle(toggle); addWidget((Widget *)theButton); return theButton; } else{ cerr<<"Gui/Window.cpp : max widget limit reached!" << endl; return NULL; }} Label * Window::createLabel(int x1, int x2, char * label, int color){ if(widgetCount < MAX_WIDGET){ Label * theLabel; theLabel = new Label(x1, x2, label); // addwidget call must come before setColor... addWidget((Widget *)theLabel); // set new color or keep default color (black) if(color == Constants::RED_COLOR){ theLabel->setColor( 0.8f, 0.2f, 0.0f, 1.0f ); } else if(color == Constants::BLUE_COLOR){ theLabel->setColor( 0.0f, 0.3f, 0.9f, 1.0f ); } return theLabel; } else{ cerr<<"Gui/Window.cpp : max widget limit reached!" << endl; return NULL; }} Checkbox * Window::createCheckbox(int x1, int y1, int x2, int y2, char *label){ if(widgetCount < MAX_WIDGET){ Checkbox * theCheckbox; theCheckbox = new Checkbox(x1, y1, x2, y2, strdup(label)); addWidget((Widget *)theCheckbox); return theCheckbox; } else{ cerr<<"Gui/Window.cpp : max widget limit reached!" << endl; return NULL; } } void Window::scissorToWindow() { GLint topY = ((h - (TOP_HEIGHT + BOTTOM_HEIGHT)) / 2) - (openHeight / 2); // scissor test: y screen coordinate is reversed, rectangle is // specified by lower-left corner. sheesh! glScissor(x, sdlHandler->getScreen()->h - (y + topY + TOP_HEIGHT + openHeight), w, openHeight); glEnable( GL_SCISSOR_TEST );}void Window::setVisible(bool b) { toTop(); Widget::setVisible(b); if(b) openHeight = 0;}void Window::toTop() { toTop(this);}void Window::toTop(Window *win) { for(int i = 0; i < windowCount; i++) { if(window[i] == win) { for(int t = i; t < windowCount - 1; t++) { window[t] = window[t + 1]; window[t]->setZ(window[t]->getZ() - 10); } window[windowCount - 1] = win; win->setZ(50 + (windowCount * 10)); break; } }}void Window::showMessageDialog(SDLHandler *sdlHandler, int x, int y, int w, int h, char *title, GLuint texture, char *message, char *buttonLabel) { if(message_dialog && message_dialog->isVisible()) { cerr << "*** Warning: Unable to display second message dialog: " << message << endl; return; } if(!message_dialog) { message_dialog = new Window( sdlHandler, x, y, w, h, title, texture, false ); message_label = message_dialog->createLabel(10, 30, message); message_button = message_dialog->createButton((w / 2) - 50, h - (40 + TOP_HEIGHT), (w / 2) + 50, h - (10 + TOP_HEIGHT), buttonLabel); message_dialog->setModal(true); } else { message_dialog->move(x, y); message_dialog->resize(w, h); message_label->setText(message); message_button->getLabel()->setText(buttonLabel); } message_dialog->setVisible(true);}// overridden so windows stay on screen and moving/rotating still worksvoid Window::move(int x, int y) { this->x = x; this->y = y; if(x< 5) this->x = 5; if(y < 5) this->y = 5; if(x >= sdlHandler->getScreen()->w - (w + 5)) this->x = sdlHandler->getScreen()->w - (w + 5 + 1); if(y >= sdlHandler->getScreen()->h - (h + 5)) this->y = sdlHandler->getScreen()->h - (h + 5 + 1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -