LRESULT WebPopupMenuProxyWin::onLButtonDown(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled) { handled = true; IntPoint mousePoint(MAKEPOINTS(lParam)); if (scrollbar()) { IntRect scrollBarRect = scrollbar()->frameRect(); if (scrollBarRect.contains(mousePoint)) { // Put the point into coordinates relative to the scroll bar mousePoint.move(-scrollBarRect.x(), -scrollBarRect.y()); PlatformMouseEvent event(hWnd, message, wParam, MAKELPARAM(mousePoint.x(), mousePoint.y())); scrollbar()->mouseDown(event); setScrollbarCapturingMouse(true); return 0; } } // If the mouse is inside the window, update the focused index. Otherwise, // hide the popup. RECT bounds; ::GetClientRect(m_popup, &bounds); if (::PtInRect(&bounds, mousePoint)) setFocusedIndex(listIndexAtPoint(mousePoint), true); else hide(); return 0; }
LRESULT WebPopupMenuProxyWin::onLButtonUp(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled) { handled = true; IntPoint mousePoint(MAKEPOINTS(lParam)); if (scrollbar()) { IntRect scrollBarRect = scrollbar()->frameRect(); if (scrollbarCapturingMouse() || scrollBarRect.contains(mousePoint)) { setScrollbarCapturingMouse(false); // Put the point into coordinates relative to the scroll bar mousePoint.move(-scrollBarRect.x(), -scrollBarRect.y()); PlatformMouseEvent event(hWnd, message, wParam, MAKELPARAM(mousePoint.x(), mousePoint.y())); scrollbar()->mouseUp(); // FIXME: This is a hack to work around Scrollbar not invalidating correctly when it doesn't have a parent widget RECT r = scrollBarRect; ::InvalidateRect(m_popup, &r, TRUE); return 0; } } // Only hide the popup if the mouse is inside the popup window. RECT bounds; ::GetClientRect(m_popup, &bounds); if (::PtInRect(&bounds, mousePoint)) { hide(); int index = focusedIndex(); if (index >= 0) { // FIXME: Do we need to send back the index right away? m_newSelectedIndex = index; } } return 0; }
void cmdscroll(Win *w, int l) { int r; if(l == 0) return; if(l > 0){ for(r = w->toprune; r < w->nrunes && l != 0; r++) if(w->runes[r] == '\n') l--; w->toprune = r; }else{ for(r = w->toprune; r > 0; r--) if(w->runes[r] == '\n' && ++l == 0){ r++; break; } w->toprune = r; } frdelete(&w->fr, 0, w->fr.nchars); frinsert(&w->fr, w->runes + w->toprune, w->runes + w->nrunes, 0); scrollbar(w); }
void uimenu::apply_scrollbar() { if ( !scrollbar_auto ) { return; } int sbside = ( scrollbar_side == 0 ? 0 : w_width - 1 ); int estart = textformatted.size(); if( estart > 0 ) { estart += 2; } else { estart = 1; } scrollbar() .offset_x( sbside ) .offset_y( estart ) .content_size( fentries.size() ) .viewport_pos( vshift ) .viewport_size( vmax ) .border_color( border_color ) .arrow_color( border_color ) .slot_color( scrollbar_nopage_color ) .bar_color( scrollbar_page_color ) .scroll_to_last( false ) .apply( window ); }
void Console::print(std::string const& msg) { CEGUI::Scrollbar& scrollbar(*m_content->getVertScrollbar()); float pos(scrollbar.getScrollPosition()); bool stick_down(pos >= scrollbar.getDocumentSize() - scrollbar.getPageSize()); m_content->appendText(msg); scrollbar.setScrollPosition((stick_down) ? scrollbar.getDocumentSize() - scrollbar.getPageSize() : pos); }
static void cmddraw(Win *w) { Rectangle r; frclear(&w->fr, 0); r = insetrect(w->inner, 1); r.min.x += SCRTSIZ; scrollbar(w); frinit(&w->fr, r, display->defaultfont, w->im, w->tab->cols); frinsert(&w->fr, w->runes + w->toprune, w->runes + w->nrunes, 0); }
LRESULT WebPopupMenuProxyWin::onMouseMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled) { handled = true; IntPoint mousePoint(MAKEPOINTS(lParam)); if (scrollbar()) { IntRect scrollBarRect = scrollbar()->frameRect(); if (scrollbarCapturingMouse() || scrollBarRect.contains(mousePoint)) { // Put the point into coordinates relative to the scroll bar mousePoint.move(-scrollBarRect.x(), -scrollBarRect.y()); PlatformMouseEvent event(hWnd, message, wParam, MAKELPARAM(mousePoint.x(), mousePoint.y())); scrollbar()->mouseMoved(event); return 0; } } BOOL shouldHotTrack = FALSE; ::SystemParametersInfo(SPI_GETHOTTRACKING, 0, &shouldHotTrack, 0); RECT bounds; ::GetClientRect(m_popup, &bounds); if (!::PtInRect(&bounds, mousePoint) && !(wParam & MK_LBUTTON)) { // When the mouse is not inside the popup menu and the left button isn't down, just // repost the message to the web view. // Translate the coordinate. translatePoint(lParam, m_popup, m_webView->window()); ::PostMessage(m_popup, WM_HOST_WINDOW_MOUSEMOVE, wParam, lParam); return 0; } if ((shouldHotTrack || wParam & MK_LBUTTON) && ::PtInRect(&bounds, mousePoint)) setFocusedIndex(listIndexAtPoint(mousePoint), true); return 0; }
//####################################################################################### bool free_scrollbar(tScrollBar *settings) { if(!settings) return false; if(!free_button(settings->Internals.BtnDnSettings)) return false; if(!free_button(settings->Internals.BtnSettings)) return false; if(!free_button(settings->Internals.BtnUpSettings)) return false; tControlCommandData comand; memset(&comand, 0x00, sizeof(tControlCommandData)); settings->Visible = false; scrollbar(settings, &comand); if(settings) free(settings); return true; }
void ScrollView::parse(XmlReader& reader) { // parse xml attributes XmlReader::AttributeIterator iter(reader); while(iter.next()) { const char* attribute = (const char*) iter.getName(); const char* value = (const char*) iter.getValue(); if(parseAttribute(attribute, value)) { continue; } else { std::cerr << "Skipping unknown attribute '" << attribute << "'.\n"; } } // we need 2 child components childs.assign(2, Child()); // parse xml contents int depth = reader.getDepth(); while(reader.read() && reader.getDepth() > depth) { if(reader.getNodeType() == XML_READER_TYPE_ELEMENT) { std::string element = (const char*) reader.getName(); if(element == "scrollbar") { std::auto_ptr<ScrollBar> scrollbar (new ScrollBar()); scrollbar->parse(reader); resetChild(scrollBar(), scrollbar.release()); } else if(element == "contents") { resetChild(contents(), parseEmbeddedComponent(reader)); } else { std::cerr << "Skipping unknown element '" << element << "'.\n"; } } } if(scrollBar().getComponent() == 0) { throw std::runtime_error("No ScrollBar specified in ScrollView"); } ScrollBar* scrollBarComponent = (ScrollBar*) scrollBar().getComponent(); scrollBarComponent->valueChanged.connect( makeCallback(*this, &ScrollView::scrollBarChanged)); setFlags(FLAG_RESIZABLE); }
LRESULT WebPopupMenuProxyWin::onSize(HWND hWnd, UINT message, WPARAM, LPARAM lParam, bool& handled) { handled = true; if (!scrollbar()) return 0; IntSize size(LOWORD(lParam), HIWORD(lParam)); scrollbar()->setFrameRect(IntRect(size.width() - scrollbar()->width(), 0, scrollbar()->width(), size.height())); int visibleItems = this->visibleItems(); scrollbar()->setEnabled(visibleItems < m_items.size()); scrollbar()->setSteps(1, max(1, visibleItems - 1)); scrollbar()->setProportion(visibleItems, m_items.size()); return 0; }
LRESULT WebPopupMenuProxyWin::onMouseWheel(HWND hWnd, UINT message, WPARAM wParam, LPARAM, bool& handled) { handled = true; if (!scrollbar()) return 0; int i = 0; for (incrementWheelDelta(GET_WHEEL_DELTA_WPARAM(wParam)); abs(wheelDelta()) >= WHEEL_DELTA; reduceWheelDelta(WHEEL_DELTA)) { if (wheelDelta() > 0) ++i; else --i; } ScrollableArea::scroll(i > 0 ? ScrollUp : ScrollDown, ScrollByLine, abs(i)); return 0; }
BOOL command(int commandc) { char filename[PATHLEN + 1]; /* file path name */ MOUSEEVENT *p; /* mouse data */ int c, i; FILE *file; HISTORY *curritem, *item; /* command history */ char *s; switch (commandc) { case ctrl('C'): /* toggle caseless mode */ if (caseless == NO) { caseless = YES; putmsg2("Caseless mode is now ON"); } else { caseless = NO; putmsg2("Caseless mode is now OFF"); } egrepcaseless(caseless); /* turn on/off -i flag */ return (NO); case ctrl('R'): /* rebuild the cross reference */ if (isuptodate == YES) { putmsg("The -d option prevents rebuilding the " "symbol database"); return (NO); } exitcurses(); freefilelist(); /* remake the source file list */ makefilelist(); rebuild(); if (errorsfound == YES) { errorsfound = NO; askforreturn(); } entercurses(); putmsg(""); /* clear any previous message */ totallines = 0; topline = nextline = 1; break; case ctrl('X'): /* mouse selection */ if ((p = getmouseevent()) == NULL) { return (NO); /* unknown control sequence */ } /* if the button number is a scrollbar tag */ if (p->button == '0') { scrollbar(p); break; } /* ignore a sweep */ if (p->x2 >= 0) { return (NO); } /* if this is a line selection */ if (p->y1 < FLDLINE) { /* find the selected line */ /* note: the selection is forced into range */ for (i = disprefs - 1; i > 0; --i) { if (p->y1 >= displine[i]) { break; } } /* display it in the file with the editor */ editref(i); } else { /* this is an input field selection */ field = mouseselection(p, FLDLINE, FIELDS); setfield(); resetcmd(); return (NO); } break; case '\t': /* go to next input field */ case '\n': case '\r': case ctrl('N'): case KEY_DOWN: case KEY_ENTER: case KEY_RIGHT: field = (field + 1) % FIELDS; setfield(); resetcmd(); return (NO); case ctrl('P'): /* go to previous input field */ case KEY_UP: case KEY_LEFT: field = (field + (FIELDS - 1)) % FIELDS; setfield(); resetcmd(); return (NO); case KEY_HOME: /* go to first input field */ field = 0; setfield(); resetcmd(); return (NO); case KEY_LL: /* go to last input field */ field = FIELDS - 1; setfield(); resetcmd(); return (NO); case ' ': /* display next page */ case '+': case ctrl('V'): case KEY_NPAGE: /* don't redisplay if there are no lines */ if (totallines == 0) { return (NO); } /* * note: seekline() is not used to move to the next * page because display() leaves the file pointer at * the next page to optimize paging forward */ break; case '-': /* display previous page */ case KEY_PPAGE: /* don't redisplay if there are no lines */ if (totallines == 0) { return (NO); } i = topline; /* save the current top line */ nextline = topline; /* go back to this page */ /* if on first page but not at beginning, go to beginning */ if (nextline > 1 && nextline <= mdisprefs) { nextline = 1; } else { /* go back the maximum displayable lines */ nextline -= mdisprefs; /* if this was the first page, go to the last page */ if (nextline < 1) { nextline = totallines - mdisprefs + 1; if (nextline < 1) { nextline = 1; } /* old top is past last line */ i = totallines + 1; } } /* * move down til the bottom line is just before the * previous top line */ c = nextline; for (;;) { seekline(nextline); display(); if (i - bottomline <= 0) { break; } nextline = ++c; } return (NO); /* display already up to date */ case '>': /* write or append the lines to a file */ if (totallines == 0) { putmsg("There are no lines to write to a file"); } else { /* get the file name */ (void) move(PRLINE, 0); (void) addstr("Write to file: "); s = "w"; if ((c = mygetch()) == '>') { (void) move(PRLINE, 0); (void) addstr(appendprompt); c = '\0'; s = "a"; } if (c != '\r' && c != '\n' && c != KEY_ENTER && c != KEY_BREAK && getaline(newpat, COLS - sizeof (appendprompt), c, NO) > 0) { shellpath(filename, sizeof (filename), newpat); if ((file = fopen(filename, s)) == NULL) { cannotopen(filename); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { (void) putc(c, file); } seekline(topline); (void) fclose(file); } } clearprompt(); } return (NO); /* return to the previous field */ case '<': /* read lines from a file */ (void) move(PRLINE, 0); (void) addstr(readprompt); if (getaline(newpat, COLS - sizeof (readprompt), '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof (filename), newpat); if (readrefs(filename) == NO) { putmsg2("Ignoring an empty file"); return (NO); } return (YES); } clearprompt(); return (NO); case '^': /* pipe the lines through a shell command */ case '|': /* pipe the lines to a shell command */ if (totallines == 0) { putmsg("There are no lines to pipe to a shell command"); return (NO); } /* get the shell command */ (void) move(PRLINE, 0); (void) addstr(pipeprompt); if (getaline(newpat, COLS - sizeof (pipeprompt), '\0', NO) == 0) { clearprompt(); return (NO); } /* if the ^ command, redirect output to a temp file */ if (commandc == '^') { (void) strcat(strcat(newpat, " >"), temp2); } exitcurses(); if ((file = mypopen(newpat, "w")) == NULL) { (void) fprintf(stderr, "cscope: cannot open pipe to shell command: %s\n", newpat); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { (void) putc(c, file); } seekline(topline); (void) mypclose(file); } if (commandc == '^') { if (readrefs(temp2) == NO) { putmsg("Ignoring empty output of ^ command"); } } askforreturn(); entercurses(); break; case ctrl('L'): /* redraw screen */ case KEY_CLEAR: (void) clearok(curscr, TRUE); (void) wrefresh(curscr); drawscrollbar(topline, bottomline, totallines); return (NO); case '!': /* shell escape */ (void) execute(shell, shell, (char *)NULL); seekline(topline); break; case '?': /* help */ (void) clear(); help(); (void) clear(); seekline(topline); break; case ctrl('E'): /* edit all lines */ editall(); break; case ctrl('A'): /* repeat last pattern */ case ctrl('Y'): /* (old command) */ if (*pattern != '\0') { (void) addstr(pattern); goto repeat; } break; case ctrl('B'): /* cmd history back */ case ctrl('F'): /* cmd history fwd */ curritem = currentcmd(); item = (commandc == ctrl('F')) ? nextcmd() : prevcmd(); clearmsg2(); if (curritem == item) { /* inform user that we're at history end */ putmsg2( "End of input field and search pattern history"); } if (item) { field = item->field; setfield(); atfield(); (void) addstr(item->text); (void) strcpy(pattern, item->text); switch (c = mygetch()) { case '\r': case '\n': case KEY_ENTER: goto repeat; default: ungetch(c); atfield(); (void) clrtoeol(); /* clear current field */ break; } } return (NO); case '\\': /* next character is not a command */ (void) addch('\\'); /* display the quote character */ /* get a character from the terminal */ if ((commandc = mygetch()) == EOF) { return (NO); /* quit */ } (void) addstr("\b \b"); /* erase the quote character */ goto ispat; case '.': atfield(); /* move back to the input field */ /* FALLTHROUGH */ default: /* edit a selected line */ if (isdigit(commandc) && commandc != '0' && !mouse) { if (returnrequired == NO) { editref(commandc - '1'); } else { (void) move(PRLINE, 0); (void) addstr(selectionprompt); if (getaline(newpat, COLS - sizeof (selectionprompt), commandc, NO) > 0 && (i = atoi(newpat)) > 0) { editref(i - 1); } clearprompt(); } } else if (isprint(commandc)) { /* this is the start of a pattern */ ispat: if (getaline(newpat, COLS - fldcolumn - 1, commandc, caseless) > 0) { (void) strcpy(pattern, newpat); resetcmd(); /* reset history */ repeat: addcmd(field, pattern); /* add to history */ if (field == CHANGE) { /* prompt for the new text */ (void) move(PRLINE, 0); (void) addstr(toprompt); (void) getaline(newpat, COLS - sizeof (toprompt), '\0', NO); } /* search for the pattern */ if (search() == YES) { switch (field) { case DEFINITION: case FILENAME: if (totallines > 1) { break; } topline = 1; editref(0); break; case CHANGE: return (changestring()); } } else if (field == FILENAME && access(newpat, READ) == 0) { /* try to edit the file anyway */ edit(newpat, "1"); } } else { /* no pattern--the input was erased */ return (NO); } } else { /* control character */ return (NO); } } return (YES); }
void SampleApp::Run() { sf::Event event; //m_window.SetFramerateLimit( 60 ); //m_window.EnableVerticalSync( true ); // Tune Renderer m_sfgui.TuneUseFBO( true ); m_sfgui.TuneAlphaThreshold( .2f ); m_sfgui.TuneCull( true ); // Create widgets. m_wndmain = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ); m_wndmain->SetTitle( L"Example application" ); sfg::Button::Ptr btnaddbuttonh( sfg::Button::Create( L"Add button horizontally" ) ); sfg::Button::Ptr btnaddbuttonv( sfg::Button::Create( L"Add button vertically" ) ); m_titlebar_toggle = sfg::ToggleButton::Create( "Toggle titlebar" ); m_titlebar_toggle->SetActive( true ); { sf::Image add_image; if( add_image.loadFromFile( "data/add.png" ) ) { sfg::Image::Ptr image( sfg::Image::Create( add_image ) ); btnaddbuttonh->SetImage( image ); image = sfg::Image::Create( add_image ); btnaddbuttonv->SetImage( image ); } } sfg::Button::Ptr btnhidewindow( sfg::Button::Create( L"Close window" ) ); btnhidewindow->SetId( "close" ); { sf::Image close_image; if( close_image.loadFromFile( "data/delete.png" ) ) { sfg::Image::Ptr image( sfg::Image::Create( close_image ) ); btnhidewindow->SetImage( image ); } } sfg::Button::Ptr btntogglespace( sfg::Button::Create( L"Box Spacing") ); sfg::Button::Ptr btnloadstyle( sfg::Button::Create( L"Load theme") ); m_entry = sfg::Entry::Create( L"Type" ); m_entry->SetRequisition( sf::Vector2f( 100.f, .0f ) ); m_entry->AppendText( L" something!" ); m_limit_check = sfg::CheckButton::Create( L"Limit to 4 chars" ); m_limit_check->SetId( "limit_check" ); sfg::Entry::Ptr password( sfg::Entry::Create() ); password->HideText( '*' ); // Layout. sfg::Box::Ptr boxtoolbar( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); boxtoolbar->SetSpacing( 5.f ); boxtoolbar->Pack( btnaddbuttonh, false ); boxtoolbar->Pack( btnaddbuttonv, false ); boxtoolbar->Pack( m_titlebar_toggle, false ); boxtoolbar->Pack( btnhidewindow, false ); boxtoolbar->Pack( m_entry, true ); boxtoolbar->Pack( m_limit_check, false ); sfg::Frame::Ptr frame1( sfg::Frame::Create( L"Toolbar 1" ) ); frame1->Add( boxtoolbar ); sfg::Box::Ptr boxtoolbar2( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); boxtoolbar2->SetSpacing( 5.f ); boxtoolbar2->Pack( btntogglespace, false ); boxtoolbar2->Pack( btnloadstyle, false ); m_boxbuttonsh = sfg::Box::Create( sfg::Box::HORIZONTAL ); m_boxbuttonsh->SetSpacing( 5.f ); m_boxbuttonsv = sfg::Box::Create( sfg::Box::VERTICAL ); m_boxbuttonsv->SetSpacing( 5.f ); sfg::Entry::Ptr username_entry( sfg::Entry::Create() ); username_entry->SetMaximumLength( 8 ); m_progress = sfg::ProgressBar::Create( sfg::ProgressBar::HORIZONTAL ); m_progress->SetRequisition( sf::Vector2f( 0.f, 20.f ) ); m_progress_vert = sfg::ProgressBar::Create( sfg::ProgressBar::VERTICAL ); m_progress_vert->SetRequisition( sf::Vector2f( 20.f, 0.f ) ); sfg::Separator::Ptr separatorv( sfg::Separator::Create( sfg::Separator::VERTICAL ) ); m_table = sfg::Table::Create(); m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect<sf::Uint32>( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND ); m_table->Attach( sfg::Label::Create( L"Username:"******"Password:"******"Login" ), sf::Rect<sf::Uint32>( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL ); m_table->Attach( separatorv, sf::Rect<sf::Uint32>( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL ); m_table->Attach( m_progress_vert, sf::Rect<sf::Uint32>( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL ); m_table->SetRowSpacings( 5.f ); m_table->SetColumnSpacings( 5.f ); m_scrolled_window_box = sfg::Box::Create( sfg::Box::VERTICAL ); for( int i = 0; i < 5; i++ ) { sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::HORIZONTAL ); for( int j = 0; j < 20; j++ ) { box->Pack( sfg::Button::Create( L"One button among many" ), true ); } m_scrolled_window_box->Pack( box, false ); } m_scrolled_window = sfg::ScrolledWindow::Create(); m_scrolled_window->SetRequisition( sf::Vector2f( .0f, 160.f ) ); m_scrolled_window->SetScrollbarPolicy( sfg::ScrolledWindow::HORIZONTAL_AUTOMATIC | sfg::ScrolledWindow::VERTICAL_AUTOMATIC ); m_scrolled_window->SetPlacement( sfg::ScrolledWindow::TOP_LEFT ); m_scrolled_window->AddWithViewport( m_scrolled_window_box ); sfg::Scrollbar::Ptr scrollbar( sfg::Scrollbar::Create() ); scrollbar->SetRange( .0f, 100.f ); m_scale = sfg::Scale::Create(); m_scale->SetAdjustment( scrollbar->GetAdjustment() ); m_scale->SetRequisition( sf::Vector2f( 100.f, .0f ) ); boxtoolbar2->Pack( m_scale, false ); m_combo_box = sfg::ComboBox::Create(); for( int index = 0; index < 30; ++index ) { std::stringstream sstr; sstr << "Item " << index; m_combo_box->AppendItem( sstr.str() ); } boxtoolbar2->Pack( m_combo_box, true ); sfg::Frame::Ptr frame2( sfg::Frame::Create( L"Toolbar 2" ) ); frame2->Add( boxtoolbar2 ); frame2->SetAlignment( sf::Vector2f( .8f, .0f ) ); sfg::Separator::Ptr separatorh( sfg::Separator::Create( sfg::Separator::HORIZONTAL ) ); sfg::Box::Ptr box_image( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); box_image->SetSpacing( 15.f ); sfg::Fixed::Ptr fixed_container( sfg::Fixed::Create() ); sfg::Button::Ptr fixed_button( sfg::Button::Create( L"I'm at (34,61)" ) ); fixed_container->Put( fixed_button, sf::Vector2f( 34.f, 61.f ) ); box_image->Pack( fixed_container, false ); sf::Image sfgui_logo; m_image = sfg::Image::Create(); if( sfgui_logo.loadFromFile( "data/sfgui.png" ) ) { m_image->SetImage( sfgui_logo ); box_image->Pack( m_image, false ); } sfg::Button::Ptr mirror_image( sfg::Button::Create( L"Mirror Image" ) ); box_image->Pack( mirror_image, false ); sfg::Box::Ptr spinner_box( sfg::Box::Create( sfg::Box::VERTICAL ) ); m_spinner = sfg::Spinner::Create(); m_spinner->SetRequisition( sf::Vector2f( 40.f, 40.f ) ); m_spinner->Start(); sfg::ToggleButton::Ptr spinner_toggle( sfg::ToggleButton::Create( L"Spin") ); spinner_toggle->SetActive( true ); spinner_box->SetSpacing( 5.f ); spinner_box->Pack( m_spinner, false ); spinner_box->Pack( spinner_toggle, false ); box_image->Pack( spinner_box, false ); sfg::Box::Ptr radio_box( sfg::Box::Create( sfg::Box::VERTICAL ) ); sfg::RadioButton::Ptr radio1( sfg::RadioButton::Create( "Radio 1" ) ); sfg::RadioButton::Ptr radio2( sfg::RadioButton::Create( "Radio 2", radio1->GetGroup() ) ); sfg::RadioButton::Ptr radio3( sfg::RadioButton::Create( "Radio 3", radio2->GetGroup() ) ); radio_box->Pack( radio1 ); radio_box->Pack( radio2 ); radio_box->Pack( radio3 ); box_image->Pack( radio_box, false ); sfg::SpinButton::Ptr spinbutton( sfg::SpinButton::Create( scrollbar->GetAdjustment() ) ); spinbutton->SetRequisition( sf::Vector2f( 80.f, 0.f ) ); spinbutton->SetDigits( 3 ); sfg::Box::Ptr spinbutton_box( sfg::Box::Create( sfg::Box::VERTICAL ) ); spinbutton_box->Pack( spinbutton, false, false ); box_image->Pack( spinbutton_box, false, false ); sfg::ComboBox::Ptr aligned_combo_box( sfg::ComboBox::Create() ); aligned_combo_box->AppendItem( L"I'm way over here" ); aligned_combo_box->AppendItem( L"Me too" ); aligned_combo_box->AppendItem( L"Me three" ); aligned_combo_box->SelectItem( 0 ); sfg::Alignment::Ptr alignment( sfg::Alignment::Create() ); alignment->Add( aligned_combo_box ); box_image->Pack( alignment, true ); alignment->SetAlignment( sf::Vector2f( 1.f, .5f ) ); alignment->SetScale( sf::Vector2f( 0.f, .01f ) ); sfg::Box::Ptr boxmain( sfg::Box::Create( sfg::Box::VERTICAL ) ); boxmain->SetSpacing( 5.f ); boxmain->Pack( scrollbar, false ); boxmain->Pack( m_progress, false ); boxmain->Pack( frame1, false ); boxmain->Pack( frame2, false ); boxmain->Pack( m_boxbuttonsh, false ); boxmain->Pack( m_boxbuttonsv, false ); boxmain->Pack( box_image, true ); boxmain->Pack( separatorh, false ); boxmain->Pack( m_table, true ); boxmain->Pack( m_scrolled_window ); sfg::Notebook::Ptr notebook1( sfg::Notebook::Create() ); sfg::Notebook::Ptr notebook2( sfg::Notebook::Create() ); sfg::Notebook::Ptr notebook3( sfg::Notebook::Create() ); sfg::Notebook::Ptr notebook4( sfg::Notebook::Create() ); notebook1->SetTabPosition( sfg::Notebook::TOP ); notebook2->SetTabPosition( sfg::Notebook::RIGHT ); notebook3->SetTabPosition( sfg::Notebook::BOTTOM ); notebook4->SetTabPosition( sfg::Notebook::LEFT ); sfg::Box::Ptr vertigo_box( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); sfg::Button::Ptr vertigo_button( sfg::Button::Create( L"Vertigo" ) ); vertigo_box->Pack( vertigo_button, true, true ); notebook1->AppendPage( boxmain, sfg::Label::Create( "Page Name Here" ) ); notebook1->AppendPage( notebook2, sfg::Label::Create( "Another Page" ) ); notebook2->AppendPage( notebook3, sfg::Label::Create( "Yet Another Page" ) ); notebook2->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) ); notebook3->AppendPage( notebook4, sfg::Label::Create( "And Another Page" ) ); notebook3->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) ); notebook4->AppendPage( vertigo_box, sfg::Label::Create( "And The Last Page" ) ); notebook4->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) ); m_wndmain->Add( notebook1 ); // Signals. btnaddbuttonh->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnAddButtonHClick, this ); btnaddbuttonv->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnAddButtonVClick, this ); m_titlebar_toggle->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnToggleTitlebarClick, this ); btnhidewindow->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnHideWindowClicked, this ); btntogglespace->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnToggleSpaceClick, this ); m_limit_check->GetSignal( sfg::ToggleButton::OnToggle ).Connect( &SampleApp::OnLimitCharsToggle, this ); btnloadstyle->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnLoadThemeClick, this ); m_scale->GetAdjustment()->GetSignal( sfg::Adjustment::OnChange ).Connect( &SampleApp::OnAdjustmentChange, this ); spinner_toggle->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnToggleSpinner, this ); mirror_image->GetSignal( sfg::Widget::OnLeftClick ).Connect( &SampleApp::OnMirrorImageClick, this ); spinbutton->SetValue( 20.f ); spinbutton->GetAdjustment()->SetMinorStep( .8f ); m_wndmain->SetPosition( sf::Vector2f( 100.f, 100.f ) ); // Another window sfg::Window::Ptr second_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ) ); second_window->SetId( "second_window" ); second_window->SetTitle( "Resize this window to see ad-hoc wrapping." ); sfg::Box::Ptr box( sfg::Box::Create( sfg::Box::VERTICAL, 5.f ) ); sfg::Label::Ptr lipsum = sfg::Label::Create( "Nullam ut ante leo. Quisque consequat condimentum pulvinar. " "Duis a enim sapien, ut vestibulum est. Vestibulum commodo, orci non gravida. " "Aliquam sed pretium lacus. " "Nullam placerat mauris vel nulla sagittis pellentesque. " "Suspendisse in justo dui.\n" "Ut dolor massa, gravida eu facilisis convallis, convallis sed odio.\n" "Nunc placerat consequat vehicula." ); lipsum->SetRequisition( sf::Vector2f( 400.f, 0.f ) ); lipsum->SetLineWrap( true ); box->Pack( lipsum ); second_window->Add( box ); second_window->SetPosition( sf::Vector2f( 10.f, 10.f ) ); second_window->SetId( "second_window" ); m_desktop.Add( second_window ); sfg::Window::Ptr third_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ) ); m_gl_canvas = sfg::Canvas::Create( true ); m_gl_canvas->SetRequisition( sf::Vector2f( 200.f, 150.f ) ); third_window->Add( m_gl_canvas ); third_window->SetId( "third_window" ); third_window->SetTitle( "Embedded OpenGL drawing" ); third_window->SetPosition( sf::Vector2f( 480.f, 20.f ) ); m_desktop.Add( third_window ); sf::Texture texture; texture.loadFromImage( sfgui_logo ); m_canvas_sprite.setTexture( texture ); sfg::Window::Ptr fourth_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ) ); m_sfml_canvas = sfg::Canvas::Create(); m_sfml_canvas->SetRequisition( sf::Vector2f( static_cast<float>( texture.getSize().x ), static_cast<float>( texture.getSize().y ) ) ); fourth_window->Add( m_sfml_canvas ); fourth_window->SetId( "fourth_window" ); fourth_window->SetTitle( "Embedded SFML drawing" ); fourth_window->SetPosition( sf::Vector2f( 760.f, 20.f ) ); m_desktop.Add( fourth_window ); // Add window to desktop m_desktop.Add( m_wndmain ); // Play around with resource manager. sf::Font my_font; my_font.loadFromFile( "data/linden_hill.otf" ); m_desktop.GetEngine().GetResourceManager().AddFont( "custom_font", my_font, false ); // false -> do not manage! // Set properties. m_desktop.SetProperty( "Button#close:Normal", "Color", sf::Color::Yellow ); // #close is sufficient since there is only 1 widget with this id m_desktop.SetProperty( "#close", "FontName", "data/linden_hill.otf" ); m_desktop.SetProperty( "#close", "FontSize", 15.f ); // Multiple properties can be set at once to save calls. m_desktop.SetProperties( "Window#second_window > Box > Label {" " FontName: custom_font;" " FontSize: 18;" "}" ); m_fps_counter = 0; m_fps_clock.restart(); sf::Clock clock; sf::Clock frame_time_clock; sf::Int64 frame_times[5000]; std::size_t frame_times_index = 0; while( m_window.isOpen() ) { while( m_window.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) { m_window.close(); } else if( event.type == sf::Event::Resized ) { m_desktop.UpdateViewRect( sf::FloatRect( 0.f, 0.f, static_cast<float>( event.size.width ), static_cast<float>( event.size.height ) ) ); } m_desktop.HandleEvent( event ); } m_window.draw( m_background_sprite ); sf::Uint64 microseconds = clock.getElapsedTime().asMicroseconds(); // Only update every 5ms if( microseconds > 5000 ) { m_desktop.Update( static_cast<float>( microseconds ) / 1000000.f ); clock.restart(); // Only refresh canvas contents every 5ms too m_gl_canvas->Bind(); m_gl_canvas->Clear( sf::Color( 0, 0, 0, 0 ), true ); RenderCustomGL(); m_gl_canvas->Display(); m_gl_canvas->Unbind(); m_sfml_canvas->Bind(); m_sfml_canvas->Clear( sf::Color( 0, 0, 0, 0 ) ); RenderCustomSFML(); m_sfml_canvas->Display(); m_sfml_canvas->Unbind(); m_window.setActive( true ); } m_sfgui.Display( m_window ); m_window.display(); sf::Int64 frame_time = frame_time_clock.getElapsedTime().asMicroseconds(); frame_time_clock.restart(); frame_times[ frame_times_index ] = frame_time; frame_times_index = ( frame_times_index + 1 ) % 5000; if( m_fps_clock.getElapsedTime().asMicroseconds() >= 1000000 ) { m_fps_clock.restart(); sf::Int64 total_time = 0; for( std::size_t index = 0; index < 5000; ++index ) { total_time += frame_times[index]; } std::stringstream sstr; sstr << "SFGUI test -- FPS: " << m_fps_counter << " -- Frame Time (microsecs): min: " << *std::min_element( frame_times, frame_times + 5000 ) << " max: " << *std::max_element( frame_times, frame_times + 5000 ) << " avg: " << static_cast<float>( total_time ) / 5000.f; m_window.setTitle( sstr.str() ); m_fps_counter = 0; } ++m_fps_counter; } glDeleteLists( m_custom_draw_display_list, 1 ); }
void SampleApp::Run() { sf::Event event; //m_window.SetFramerateLimit( 60 ); //m_window.EnableVerticalSync( true ); // Tune Renderer sfg::Renderer::Get().TuneDepthTest( sfg::Renderer::ALTERNATE_DEPTH ); sfg::Renderer::Get().TuneAlphaThreshold( .2f ); sfg::Renderer::Get().TunePrecomputeBlending( true ); sfg::Renderer::Get().TuneCull( true ); // Create widgets. m_wndmain = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ); m_wndmain->SetTitle( L"Example application" ); sfg::Button::Ptr btnaddbuttonh( sfg::Button::Create( L"Add button horizontally" ) ); sfg::Button::Ptr btnaddbuttonv( sfg::Button::Create( L"Add button vertically" ) ); m_titlebar_toggle = sfg::ToggleButton::Create( "Toggle titlebar" ); m_titlebar_toggle->SetActive( true ); { sf::Image add_image; if( add_image.loadFromFile( "data/add.png" ) ) { sfg::Image::Ptr image( sfg::Image::Create( add_image ) ); btnaddbuttonh->SetImage( image ); image = sfg::Image::Create( add_image ); btnaddbuttonv->SetImage( image ); } } sfg::Button::Ptr btnhidewindow( sfg::Button::Create( L"Close window" ) ); btnhidewindow->SetId( "close" ); { sf::Image close_image; if( close_image.loadFromFile( "data/delete.png" ) ) { sfg::Image::Ptr image( sfg::Image::Create( close_image ) ); btnhidewindow->SetImage( image ); } } sfg::Button::Ptr btntogglespace( sfg::Button::Create( L"Box Spacing") ); sfg::Button::Ptr btnloadstyle( sfg::Button::Create( L"Load theme") ); m_entry = sfg::Entry::Create( L"Type" ); m_entry->SetRequisition( sf::Vector2f( 100.f, .0f ) ); m_entry->AppendText( L" something!" ); m_limit_check = sfg::CheckButton::Create( L"Limit to 4 chars" ); m_limit_check->SetId( "limit_check" ); sfg::Entry::Ptr password( sfg::Entry::Create() ); password->HideText( '*' ); // Layout. sfg::Box::Ptr boxtoolbar( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); boxtoolbar->SetSpacing( 5.f ); boxtoolbar->Pack( btnaddbuttonh, false ); boxtoolbar->Pack( btnaddbuttonv, false ); boxtoolbar->Pack( m_titlebar_toggle, false ); boxtoolbar->Pack( btnhidewindow, false ); boxtoolbar->Pack( m_entry, true ); boxtoolbar->Pack( m_limit_check, false ); sfg::Frame::Ptr frame1( sfg::Frame::Create( L"Toolbar 1" ) ); frame1->Add( boxtoolbar ); sfg::Box::Ptr boxtoolbar2( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); boxtoolbar2->SetSpacing( 5.f ); boxtoolbar2->Pack( btntogglespace, false ); boxtoolbar2->Pack( btnloadstyle, false ); m_boxbuttonsh = sfg::Box::Create( sfg::Box::HORIZONTAL ); m_boxbuttonsh->SetSpacing( 5.f ); m_boxbuttonsv = sfg::Box::Create( sfg::Box::VERTICAL ); m_boxbuttonsv->SetSpacing( 5.f ); sfg::Entry::Ptr username_entry( sfg::Entry::Create() ); username_entry->SetMaximumLength( 8 ); m_progress = sfg::ProgressBar::Create( sfg::ProgressBar::HORIZONTAL ); m_progress->SetRequisition( sf::Vector2f( 0.f, 20.f ) ); m_progress_vert = sfg::ProgressBar::Create( sfg::ProgressBar::VERTICAL ); m_progress_vert->SetRequisition( sf::Vector2f( 20.f, 0.f ) ); sfg::Separator::Ptr separatorv( sfg::Separator::Create( sfg::Separator::VERTICAL ) ); m_table = sfg::Table::Create(); m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect<sf::Uint32>( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND ); m_table->Attach( sfg::Label::Create( L"Username:"******"Password:"******"Login" ), sf::Rect<sf::Uint32>( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL ); m_table->Attach( separatorv, sf::Rect<sf::Uint32>( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL ); m_table->Attach( m_progress_vert, sf::Rect<sf::Uint32>( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL ); m_table->SetRowSpacings( 5.f ); m_table->SetColumnSpacings( 5.f ); m_scrolled_window_box = sfg::Box::Create( sfg::Box::VERTICAL ); for( int i = 0; i < 5; i++ ) { sfg::Box::Ptr box = sfg::Box::Create( sfg::Box::HORIZONTAL ); for( int j = 0; j < 20; j++ ) { box->Pack( sfg::Button::Create( L"One button among many" ), true ); } m_scrolled_window_box->Pack( box, false ); } m_scrolled_window = sfg::ScrolledWindow::Create(); m_scrolled_window->SetRequisition( sf::Vector2f( .0f, 150.f ) ); m_scrolled_window->SetScrollbarPolicy( sfg::ScrolledWindow::HORIZONTAL_AUTOMATIC | sfg::ScrolledWindow::VERTICAL_AUTOMATIC ); m_scrolled_window->SetPlacement( sfg::ScrolledWindow::TOP_LEFT ); m_scrolled_window->AddWithViewport( m_scrolled_window_box ); sfg::Scrollbar::Ptr scrollbar( sfg::Scrollbar::Create() ); scrollbar->SetRange( .0f, 100.f ); m_scale = sfg::Scale::Create(); m_scale->SetAdjustment( scrollbar->GetAdjustment() ); m_scale->SetRequisition( sf::Vector2f( 100.f, .0f ) ); boxtoolbar2->Pack( m_scale, false ); m_combo_box = sfg::ComboBox::Create(); m_combo_box->AppendItem( "Item 0" ); m_combo_box->AppendItem( "Item 1" ); m_combo_box->AppendItem( "Item 2" ); m_combo_box->AppendItem( "Item 3" ); boxtoolbar2->Pack( m_combo_box, true ); sfg::Frame::Ptr frame2( sfg::Frame::Create( L"Toolbar 2" ) ); frame2->Add( boxtoolbar2 ); frame2->SetAlignment( sf::Vector2f( .8f, .0f ) ); sfg::Separator::Ptr separatorh( sfg::Separator::Create( sfg::Separator::HORIZONTAL ) ); sfg::Box::Ptr box_image( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); box_image->SetSpacing( 5.f ); sfg::Fixed::Ptr fixed_container( sfg::Fixed::Create() ); sfg::Button::Ptr fixed_button( sfg::Button::Create( L"I'm at (34,61)" ) ); fixed_container->Put( fixed_button, sf::Vector2f( 34.f, 61.f ) ); box_image->Pack( fixed_container, false ); sf::Image sfgui_logo; sfg::Image::Ptr image = sfg::Image::Create(); if( sfgui_logo.loadFromFile("sfgui.png") ) { image->SetImage( sfgui_logo ); box_image->Pack( image, false ); } sfg::Box::Ptr spinner_box( sfg::Box::Create( sfg::Box::VERTICAL ) ); m_spinner = sfg::Spinner::Create(); m_spinner->SetRequisition( sf::Vector2f( 40.f, 40.f ) ); m_spinner->Start(); sfg::ToggleButton::Ptr spinner_toggle( sfg::ToggleButton::Create( L"Spin") ); spinner_toggle->SetActive( true ); spinner_box->SetSpacing( 5.f ); spinner_box->Pack( m_spinner, false ); spinner_box->Pack( spinner_toggle, false ); box_image->Pack( spinner_box, false ); sfg::ComboBox::Ptr aligned_combo_box( sfg::ComboBox::Create() ); aligned_combo_box->AppendItem( L"I'm way over here" ); aligned_combo_box->AppendItem( L"Me too" ); aligned_combo_box->AppendItem( L"Me three" ); aligned_combo_box->SelectItem( 0 ); sfg::Alignment::Ptr alignment( sfg::Alignment::Create() ); alignment->Add( aligned_combo_box ); box_image->Pack( alignment, true ); alignment->SetAlignment( sf::Vector2f( 1.f, .5f ) ); alignment->SetScale( sf::Vector2f( 0.f, .01f ) ); sfg::Box::Ptr boxmain( sfg::Box::Create( sfg::Box::VERTICAL ) ); boxmain->SetSpacing( 5.f ); boxmain->Pack( scrollbar, false ); boxmain->Pack( m_progress, false ); boxmain->Pack( frame1, false ); boxmain->Pack( frame2, false ); boxmain->Pack( m_boxbuttonsh, false ); boxmain->Pack( m_boxbuttonsv, false ); boxmain->Pack( box_image, true ); boxmain->Pack( separatorh, false ); boxmain->Pack( m_table, true ); boxmain->Pack( m_scrolled_window ); sfg::Notebook::Ptr notebook1( sfg::Notebook::Create() ); sfg::Notebook::Ptr notebook2( sfg::Notebook::Create() ); sfg::Notebook::Ptr notebook3( sfg::Notebook::Create() ); sfg::Notebook::Ptr notebook4( sfg::Notebook::Create() ); notebook1->SetTabPosition( sfg::Notebook::TOP ); notebook2->SetTabPosition( sfg::Notebook::RIGHT ); notebook3->SetTabPosition( sfg::Notebook::BOTTOM ); notebook4->SetTabPosition( sfg::Notebook::LEFT ); sfg::Box::Ptr vertigo_box( sfg::Box::Create( sfg::Box::HORIZONTAL ) ); sfg::Button::Ptr vertigo_button( sfg::Button::Create( L"Vertigo" ) ); vertigo_box->Pack( vertigo_button, true, true ); notebook1->AppendPage( boxmain, sfg::Label::Create( "Page Name Here" ) ); notebook1->AppendPage( notebook2, sfg::Label::Create( "Another Page" ) ); notebook2->AppendPage( notebook3, sfg::Label::Create( "Yet Another Page" ) ); notebook2->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) ); notebook3->AppendPage( notebook4, sfg::Label::Create( "And Another Page" ) ); notebook3->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) ); notebook4->AppendPage( vertigo_box, sfg::Label::Create( "And The Last Page" ) ); notebook4->AppendPage( sfg::Label::Create( L"" ), sfg::Label::Create( "Dummy Page" ) ); m_wndmain->Add( notebook1 ); // Signals. btnaddbuttonh->OnClick.Connect( &SampleApp::OnAddButtonHClick, this ); btnaddbuttonv->OnClick.Connect( &SampleApp::OnAddButtonVClick, this ); m_titlebar_toggle->OnClick.Connect( &SampleApp::OnToggleTitlebarClick, this ); btnhidewindow->OnClick.Connect( &SampleApp::OnHideWindowClicked, this ); btntogglespace->OnClick.Connect( &SampleApp::OnToggleSpaceClick, this ); m_limit_check->OnToggle.Connect( &SampleApp::OnLimitCharsToggle, this ); btnloadstyle->OnClick.Connect( &SampleApp::OnLoadThemeClick, this ); m_scale->GetAdjustment()->OnChange.Connect( &SampleApp::OnAdjustmentChange, this ); spinner_toggle->OnClick.Connect( &SampleApp::OnToggleSpinner, this ); m_wndmain->SetPosition( sf::Vector2f( 100.f, 100.f ) ); // Another window sfg::Window::Ptr second_window( sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND ) ); second_window->SetId( "second_window" ); second_window->SetTitle( "Another window" ); sfg::Box::Ptr box( sfg::Box::Create( sfg::Box::VERTICAL, 5.f ) ); box->Pack( sfg::Label::Create( "Aliquam sed pretium lacus." ), false ); box->Pack( sfg::Label::Create( "Nullam placerat mauris vel nulla sagittis pellentesque." ), false ); box->Pack( sfg::Label::Create( "Suspendisse in justo dui." ), false ); box->Pack( sfg::Label::Create( "Ut dolor massa, gravida eu facilisis convallis, convallis sed odio." ), false ); box->Pack( sfg::Label::Create( "Nunc placerat consequat vehicula." ), false ); second_window->Add( box ); second_window->SetPosition( sf::Vector2f( 10.f, 10.f ) ); second_window->SetId( "second_window" ); m_desktop.Add( second_window ); // Add window to desktop m_desktop.Add( m_wndmain ); // Play around with resource manager. sf::Font my_font; my_font.loadFromFile( "data/linden_hill.otf" ); m_desktop.GetEngine().GetResourceManager().AddFont( "custom_font", my_font, false ); // false -> do not manage! // Set properties. m_desktop.SetProperty( "Button#close:Normal", "Color", sf::Color::Yellow ); m_desktop.SetProperty( "Button#close", "FontName", "data/linden_hill.otf" ); m_desktop.SetProperty( "Button#close", "FontSize", 15.f ); m_desktop.SetProperty( "Window#second_window > Box > Label", "FontName", "custom_font" ); m_desktop.SetProperty( "Window#second_window > Box > Label", "FontSize", 18.f ); m_fps_counter = 0; m_fps_clock.restart(); sf::Clock clock; while( m_window.isOpen() ) { while( m_window.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) { m_window.close(); } else if( event.type == sf::Event::Resized ) { m_desktop.UpdateViewRect( sf::FloatRect( 0.f, 0.f, static_cast<float>( event.size.width ), static_cast<float>( event.size.height ) ) ); } m_desktop.HandleEvent( event ); } m_window.draw( m_background_sprite ); sf::Uint64 microseconds = clock.getElapsedTime().asMicroseconds(); // Only update every 5ms if( microseconds > 5000 ) { m_desktop.Update( static_cast<float>( microseconds ) / 1000000.f ); clock.restart(); } sfg::Renderer::Get().Display( m_window ); m_window.display(); if( m_fps_clock.getElapsedTime().asMicroseconds() >= 1000000 ) { m_fps_clock.restart(); std::stringstream sstr; sstr << "SFGUI test -- FPS: " << m_fps_counter; m_window.setTitle( sstr.str() ); m_fps_counter = 0; } ++m_fps_counter; } }
int main(int argc, char *argv[]) { Q_UNUSED(argc) Q_UNUSED(argv) ////////////////////////////////////////////////////////////////// /// Init GraphicSystem singleton GraphicSystem::initialize("GraphicSystemTest", "data/fonts/DejaVuSans.ttf"); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Get pointers of GraphicSystem sf::RenderWindow *window; window = GraphicSystem::instance()->getWindow(); tgui::Gui *gui; gui = GraphicSystem::instance()->getGUI(); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Create widgets tgui::Picture::Ptr picture((*gui)); picture->load("data/others/Linux.jpg"); tgui::Button::Ptr button((*gui)); button->load(THEME_CONFIG_FILE); button->setPosition(40, 25); button->setText("Quit"); button->setCallbackId(1); button->bindCallback(tgui::Button::LeftMouseClicked); button->setSize(300, 40); tgui::ChatBox::Ptr chatbox((*gui)); chatbox->load(THEME_CONFIG_FILE); chatbox->setSize(200, 100); chatbox->setTextSize(20); chatbox->setPosition(400, 25); chatbox->addLine("Line 1", sf::Color::Red); chatbox->addLine("Line 2", sf::Color::Blue); chatbox->addLine("Line 3", sf::Color::Green); chatbox->addLine("Line 4", sf::Color::Yellow); chatbox->addLine("Line 5", sf::Color::Cyan); chatbox->addLine("Line 6", sf::Color::Magenta); tgui::Checkbox::Ptr checkbox((*gui)); checkbox->load(THEME_CONFIG_FILE); checkbox->setPosition(40, 80); checkbox->setText("Checkbox"); checkbox->setSize(32, 32); tgui::ChildWindow::Ptr child((*gui)); child->load(THEME_CONFIG_FILE); child->setSize(200, 100); child->setBackgroundColor(sf::Color(80, 80, 80)); child->setPosition(400, 460); child->setTitle("Child window"); child->setIcon("data/others/icon.jpg"); tgui::ComboBox::Ptr comboBox((*gui)); comboBox->load(THEME_CONFIG_FILE); comboBox->setSize(120, 21); comboBox->setPosition(210, 440); comboBox->addItem("Item 1"); comboBox->addItem("Item 2"); comboBox->addItem("Item 3"); comboBox->setSelectedItem("Item 2"); tgui::EditBox::Ptr editBox((*gui)); editBox->load(THEME_CONFIG_FILE); editBox->setPosition(40, 200); editBox->setSize(300, 30); tgui::Label::Ptr label((*gui)); label->load(THEME_CONFIG_FILE); label->setText("Label"); label->setPosition(40, 160); label->setTextColor(sf::Color(200, 200, 200)); label->setTextSize(24); tgui::ListBox::Ptr listBox((*gui)); listBox->load(THEME_CONFIG_FILE); listBox->setSize(150, 120); listBox->setItemHeight(20); listBox->setPosition(40, 440); listBox->addItem("Item 1"); listBox->addItem("Item 2"); listBox->addItem("Item 3"); tgui::LoadingBar::Ptr loadingbar((*gui)); loadingbar->load(THEME_CONFIG_FILE); loadingbar->setPosition(40, 330); loadingbar->setSize(300, 30); loadingbar->setValue(35); tgui::MenuBar::Ptr menu((*gui)); menu->load(THEME_CONFIG_FILE); menu->setSize(window->getSize().x, 20); menu->addMenu("File"); menu->addMenuItem("File", "Load"); menu->addMenuItem("File", "Save"); menu->addMenuItem("File", "Exit"); menu->bindCallback(tgui::MenuBar::MenuItemClicked); menu->setCallbackId(2); sf::Texture texture; texture.loadFromFile("data/others/ThinkLinux.jpg"); tgui::Panel::Ptr panel((*gui)); panel->setSize(200, 140); panel->setPosition(400, 150); panel->setBackgroundTexture(&texture); tgui::RadioButton::Ptr radioButton((*gui)); radioButton->load(THEME_CONFIG_FILE); radioButton->setPosition(40, 120); radioButton->setText("Radio Button"); radioButton->setSize(32, 32); tgui::Slider::Ptr slider((*gui)); slider->load(THEME_CONFIG_FILE); slider->setVerticalScroll(false); slider->setPosition(40, 250); slider->setSize(300, 25); slider->setValue(2); tgui::Scrollbar::Ptr scrollbar((*gui)); scrollbar->load(THEME_CONFIG_FILE); scrollbar->setVerticalScroll(false); scrollbar->setPosition(40, 290); scrollbar->setSize(300, 25); scrollbar->setMaximum(5); scrollbar->setLowValue(3); tgui::Slider2d::Ptr slider2d((*gui)); slider2d->load("data/widgets/Slider2d/Black.conf"); slider2d->setPosition(400, 300); slider2d->setSize(200, 150); tgui::SpinButton::Ptr spinButton((*gui)); spinButton->load(THEME_CONFIG_FILE); spinButton->setPosition(40, 410); spinButton->setVerticalScroll(false); spinButton->setSize(40, 20); tgui::SpriteSheet::Ptr spritesheet((*gui)); spritesheet->load("data/others/ThinkLinux.jpg"); spritesheet->setCells(4, 4); spritesheet->setVisibleCell(2, 3); spritesheet->setSize(160, 120); spritesheet->setPosition(620, 25); tgui::Tab::Ptr tab((*gui)); tab->load(THEME_CONFIG_FILE); tab->setPosition(40, 370); tab->add("Item 1"); tab->add("Item 2"); tab->add("Item 3"); tgui::TextBox::Ptr textBox((*gui)); textBox->load(THEME_CONFIG_FILE); textBox->setPosition(210, 470); textBox->setSize(180, 120); textBox->setTextSize(16); comboBox->moveToFront(); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Start main loop while(window->isOpen()) { GraphicSystem::instance()->injectPreUpdate(0); sf::Event event; while(GraphicSystem::instance()->pollWindowEvent(event)) { if(event.type == sf::Event::Closed) window->close(); GraphicSystem::instance()->handleGUIEvent(event); } tgui::Callback callback; while(GraphicSystem::instance()->pollGUICallback(callback)) { if(callback.id == 1) window->close(); else if(callback.id == 2) { if(callback.text == "Exit") window->close(); } } GraphicSystem::instance()->injectPostUpdate(0); } ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Destroy GraphicSystem GraphicSystem::shutdown(); ////////////////////////////////////////////////////////////////// return 0; }
/* execute the command */ BOOL command(int commandc) { char filename[PATHLEN + 1]; /* file path name */ MOUSE *p; /* mouse data */ int c, i; FILE *file; struct cmd *curritem, *item; /* command history */ char *s; switch (commandc) { case ctrl('C'): /* toggle caseless mode */ if (caseless == NO) { caseless = YES; postmsg2("Caseless mode is now ON"); } else { caseless = NO; postmsg2("Caseless mode is now OFF"); } egrepcaseless(caseless); /* turn on/off -i flag */ return(NO); case ctrl('R'): /* rebuild the cross reference */ if (isuptodate == YES) { postmsg("The -d option prevents rebuilding the symbol database"); return(NO); } exitcurses(); freefilelist(); /* remake the source file list */ makefilelist(); rebuild(); if (errorsfound == YES) { errorsfound = NO; askforreturn(); } entercurses(); clearmsg(); /* clear any previous message */ totallines = 0; disprefs = 0; topline = nextline = 1; selecting = 0; break; #if UNIXPC case ESC: /* possible unixpc mouse selection */ #endif case ctrl('X'): /* mouse selection */ if ((p = getmouseaction(DUMMYCHAR)) == NULL) { return(NO); /* unknown control sequence */ } /* if the button number is a scrollbar tag */ if (p->button == '0') { scrollbar(p); break; } /* ignore a sweep */ if (p->x2 >= 0) { return(NO); } /* if this is a line selection */ if (p->y1 < FLDLINE) { /* find the selected line */ /* note: the selection is forced into range */ for (i = disprefs - 1; i > 0; --i) { if (p->y1 >= displine[i]) { break; } } /* display it in the file with the editor */ editref(i); } else { /* this is an input field selection */ field = p->y1 - FLDLINE; /* force it into range */ if (field >= FIELDS) { field = FIELDS - 1; } setfield(); resetcmd(); return(NO); } break; case '\t': /* go to next input field */ if (disprefs) { selecting = !selecting; if (selecting) { move(displine[curdispline], 0); refresh(); } else { atfield(); resetcmd(); } } return(NO); #ifdef KEY_ENTER case KEY_ENTER: #endif case '\r': case '\n': /* go to reference */ if (selecting) { editref(curdispline); return(YES); } /* FALLTHROUGH */ case ctrl('N'): #ifdef KEY_DOWN case KEY_DOWN: #endif #ifdef KEY_RIGHT case KEY_RIGHT: #endif if (selecting) { if ((curdispline + 1) < disprefs) { move(displine[++curdispline], 0); refresh(); } } else { field = (field + 1) % FIELDS; setfield(); atfield(); resetcmd(); } return(NO); case ctrl('P'): /* go to previous input field */ #ifdef KEY_UP case KEY_UP: #endif #ifdef KEY_LEFT case KEY_LEFT: #endif if (selecting) { if (curdispline) { move(displine[--curdispline], 0); refresh(); } } else { field = (field + (FIELDS - 1)) % FIELDS; setfield(); atfield(); resetcmd(); } return(NO); #ifdef KEY_HOME case KEY_HOME: /* go to first input field */ if (selecting) { curdispline = 0; move(REFLINE, 0); refresh(); } else { field = 0; setfield(); atfield(); resetcmd(); } return(NO); #endif #ifdef KEY_LL case KEY_LL: /* go to last input field */ if (selecting) { move(displine[disprefs - 1], 0); refresh(); } else { field = FIELDS - 1; setfield(); atfield(); resetcmd(); } return(NO); #endif /* def(KEY_LL) */ case ' ': /* display next page */ case '+': case ctrl('V'): #ifdef KEY_NPAGE case KEY_NPAGE: #endif /* don't redisplay if there are no lines */ if (totallines == 0) { return(NO); } /* note: seekline() is not used to move to the next * page because display() leaves the file pointer at * the next page to optimize paging forward */ curdispline = 0; break; case ctrl('H'): case '-': /* display previous page */ #ifdef KEY_PPAGE case KEY_PPAGE: #endif /* don't redisplay if there are no lines */ if (totallines == 0) { return(NO); } curdispline = 0; /* if there are only two pages, just go to the other one */ if (totallines <= 2 * mdisprefs) { break; } /* if on first page but not at beginning, go to beginning */ nextline -= mdisprefs; /* already at next page */ if (nextline > 1 && nextline <= mdisprefs) { nextline = 1; } else { nextline -= mdisprefs; if (nextline < 1) { nextline = totallines - mdisprefs + 1; if (nextline < 1) { nextline = 1; } } } seekline(nextline); break; case '>': /* write or append the lines to a file */ if (totallines == 0) { postmsg("There are no lines to write to a file"); } else { /* get the file name */ move(PRLINE, 0); addstr("Write to file: "); s = "w"; if ((c = mygetch()) == '>') { move(PRLINE, 0); addstr(appendprompt); c = '\0'; s = "a"; } if (c != '\r' && mygetline("", newpat, COLS - sizeof(appendprompt), c, NO) > 0 ) { shellpath(filename, sizeof(filename), newpat); if ((file = myfopen(filename, s)) == NULL) { cannotopen(filename); } else { seekline(1); while ((c = getc(refsfound)) != EOF) { putc(c, file); } seekline(topline); fclose(file); } } clearprompt(); } return(NO); /* return to the previous field */ case '<': /* read lines from a file */ move(PRLINE, 0); addstr(readprompt); if (mygetline("", newpat, COLS - sizeof(readprompt), '\0', NO) > 0) { clearprompt(); shellpath(filename, sizeof(filename), newpat); if (readrefs(filename) == NO) { postmsg2("Ignoring an empty file"); return(NO); } return(YES); } clearprompt(); return(NO); case '^': /* pipe the lines through a shell command */ case '|': /* pipe the lines to a shell command */ if (totallines == 0) { postmsg("There are no lines to pipe to a shell command"); return(NO); } /* get the shell command */ move(PRLINE, 0); addstr(pipeprompt); if (mygetline("", newpat, COLS - sizeof(pipeprompt), '\0', NO) == 0) { clearprompt(); return(NO); } /* if the ^ command, redirect output to a temp file */ if (commandc == '^') { strcat(strcat(newpat, " >"), temp2); /* HBB 20020708: somebody might have even * their non-interactive default shells * complain about clobbering * redirections... --> delete before * overwriting */ remove(temp2); } exitcurses(); if ((file = mypopen(newpat, "w")) == NULL) { fprintf(stderr, "\ cscope: cannot open pipe to shell command: %s\n", newpat); } else {
void Messages::dialog::show() { werase( w ); draw_border( w, border_color ); scrollbar() .offset_x( 0 ) .offset_y( border_width ) .content_size( folded_filtered.size() ) .viewport_pos( offset ) .viewport_size( max_lines ) .apply( w ); // Range of window lines to print size_t line_from = 0, line_to; if( offset < folded_filtered.size() ) { line_to = std::min( max_lines, folded_filtered.size() - offset ); } else { line_to = 0; } if( !log_from_top ) { // Always print from new to old std::swap( line_from, line_to ); } std::string prev_time_str; bool printing_range = false; for( size_t line = line_from; line != line_to; ) { // Decrement here if printing from bottom to get the correct line number if( !log_from_top ) { --line; } const size_t folded_ind = offset + line; const size_t msg_ind = folded_all[folded_filtered[folded_ind]].first; const game_message &msg = player_messages.history( msg_ind ); nc_color col = msgtype_to_color( msg.type, false ); // Print current line print_colored_text( w, border_width + line, border_width + time_width + padding_width, col, col, folded_all[folded_filtered[folded_ind]].second ); // Generate aligned time string const time_point msg_time = msg.timestamp_in_turns; const std::string time_str = to_string_clipped( calendar::turn - msg_time, clipped_align::right ); if( time_str != prev_time_str ) { // Time changed, print time string prev_time_str = time_str; right_print( w, border_width + line, border_width + msg_width + padding_width, time_color, time_str ); printing_range = false; } else { // Print line brackets to mark ranges of time if( printing_range ) { const size_t last_line = log_from_top ? line - 1 : line + 1; wattron( w, bracket_color ); mvwaddch( w, border_width + last_line, border_width + time_width - 1, LINE_XOXO ); wattroff( w, bracket_color ); } wattron( w, bracket_color ); mvwaddch( w, border_width + line, border_width + time_width - 1, log_from_top ? LINE_XXOO : LINE_OXXO ); wattroff( w, bracket_color ); printing_range = true; } // Decrement for !log_from_top is done at the beginning if( log_from_top ) { ++line; } } if( filtering ) { wrefresh( w ); // Print the help text werase( w_filter_help ); draw_border( w_filter_help, border_color ); for( size_t line = 0; line < help_text.size(); ++line ) { nc_color col = filter_help_color; print_colored_text( w_filter_help, border_width + line, border_width, col, col, help_text[line] ); } mvwprintz( w_filter_help, w_fh_height - 1, border_width, border_color, "< " ); mvwprintz( w_filter_help, w_fh_height - 1, w_fh_width - border_width - 2, border_color, " >" ); wrefresh( w_filter_help ); // This line is preventing this method from being const filter.query( false, true ); // Draw only } else { if( filter_str.empty() ) { mvwprintz( w, w_height - 1, border_width, border_color, _( "< Press %s to filter, %s to reset >" ), ctxt.get_desc( "FILTER" ), ctxt.get_desc( "RESET_FILTER" ) ); } else { mvwprintz( w, w_height - 1, border_width, border_color, "< %s >", filter_str ); mvwprintz( w, w_height - 1, border_width + 2, filter_color, "%s", filter_str ); } wrefresh( w ); } }
void menu_draw(int m) { int i = 0; #ifdef HAVE_LCD_BITMAP int fw, fh; int menu_lines; int height = LCD_HEIGHT; lcd_setfont(FONT_UI); lcd_getstringsize("A", &fw, &fh); if (global_settings.statusbar) height -= STATUSBAR_HEIGHT; #if CONFIG_KEYPAD == RECORDER_PAD if(global_settings.buttonbar && menus[m].use_buttonbar) { buttonbar_set(menus[m].buttonbar[0], menus[m].buttonbar[1], menus[m].buttonbar[2]); height -= BUTTONBAR_HEIGHT; } #endif menu_lines = height / fh; #else int menu_lines = MENU_LINES; #endif lcd_clear_display(); #ifdef HAVE_LCD_BITMAP lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */ #endif /* Adjust cursor pos if it's below the screen */ if (menus[m].cursor - menus[m].top >= menu_lines) menus[m].top = menus[m].cursor - (menu_lines - 1); /* Adjust cursor pos if it's above the screen */ if(menus[m].cursor < menus[m].top) menus[m].top = menus[m].cursor; for (i = menus[m].top; (i < menus[m].itemcount) && (i<menus[m].top+menu_lines); i++) { /* We want to scroll the line where the cursor is */ if((menus[m].cursor - menus[m].top)==(i-menus[m].top)) #ifdef HAVE_LCD_BITMAP if (global_settings.invert_cursor) lcd_puts_scroll_style(LINE_X, i-menus[m].top, P2STR(menus[m].items[i].desc), STYLE_INVERT); else #endif lcd_puts_scroll(LINE_X, i-menus[m].top, P2STR(menus[m].items[i].desc)); else lcd_puts(LINE_X, i-menus[m].top, P2STR(menus[m].items[i].desc)); } /* place the cursor */ put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true); #ifdef HAVE_LCD_BITMAP if (global_settings.scrollbar && menus[m].itemcount > menu_lines) scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1, height, menus[m].itemcount, menus[m].top, menus[m].top + menu_lines, VERTICAL); #if CONFIG_KEYPAD == RECORDER_PAD if(global_settings.buttonbar && menus[m].use_buttonbar) buttonbar_draw(); #endif /* CONFIG_KEYPAD == RECORDER_PAD */ #endif /* HAVE_LCD_BITMAP */ status_draw(true); lcd_update(); }
BOOL changestring(void) { char buf[PATLEN + 1]; /* input buffer */ char newfile[PATHLEN + 1]; /* new file name */ char oldfile[PATHLEN + 1]; /* old file name */ char linenum[NUMLEN + 1]; /* file line number */ char msg[MSGLEN + 1]; /* message */ FILE *script; /* shell script file */ BOOL anymarked = NO; /* any line marked */ MOUSEEVENT *p; /* mouse data */ int c, i; char *s; /* open the temporary file */ if ((script = fopen(temp2, "w")) == NULL) { cannotopen(temp2); return (NO); } /* create the line change indicators */ change = (BOOL *)mycalloc((unsigned)totallines, sizeof (BOOL)); changing = YES; initmenu(); /* until the quit command is entered */ for (;;) { /* display the current page of lines */ display(); same: /* get a character from the terminal */ (void) move(PRLINE, 0); (void) addstr( "Select lines to change (press the ? key for help): "); if ((c = mygetch()) == EOF || c == ctrl('D') || c == ctrl('Z')) { break; /* change lines */ } /* see if the input character is a command */ switch (c) { case ' ': /* display next page */ case '+': case ctrl('V'): case KEY_NPAGE: case '-': /* display previous page */ case KEY_PPAGE: case '!': /* shell escape */ case '?': /* help */ (void) command(c); break; case ctrl('L'): /* redraw screen */ case KEY_CLEAR: (void) command(c); goto same; case ESC: /* kept for backwards compatibility */ /* FALLTHROUGH */ case '\r': /* don't change lines */ case '\n': case KEY_ENTER: case KEY_BREAK: case ctrl('G'): clearprompt(); goto nochange; case '*': /* mark/unmark all displayed lines */ for (i = 0; topline + i < nextline; ++i) { mark(i); } goto same; case 'a': /* mark/unmark all lines */ for (i = 0; i < totallines; ++i) { if (change[i] == NO) { change[i] = YES; } else { change[i] = NO; } } /* show that all have been marked */ seekline(totallines); break; case ctrl('X'): /* mouse selection */ if ((p = getmouseevent()) == NULL) { goto same; /* unknown control sequence */ } /* if the button number is a scrollbar tag */ if (p->button == '0') { scrollbar(p); break; } /* find the selected line */ /* note: the selection is forced into range */ for (i = disprefs - 1; i > 0; --i) { if (p->y1 >= displine[i]) { break; } } mark(i); goto same; default: /* if a line was selected */ if (isdigit(c) && c != '0' && !mouse) { if (returnrequired == NO) { mark(c - '1'); } else { clearprompt(); (void) move(PRLINE, 0); (void) addstr(selectionprompt); if (getaline(buf, COLS - sizeof (selectionprompt), c, NO) > 0 && (i = atoi(buf)) > 0) { mark(i - 1); } } } goto same; } } /* for each line containing the old text */ (void) fprintf(script, "ed - <<\\!\nH\n"); *oldfile = '\0'; seekline(1); for (i = 0; fscanf(refsfound, "%s%*s%s%*[^\n]", newfile, linenum) == 2; ++i) { /* see if the line is to be changed */ if (change[i] == YES) { anymarked = YES; /* if this is a new file */ if (strcmp(newfile, oldfile) != 0) { /* make sure it can be changed */ if (access(newfile, WRITE) != 0) { (void) sprintf(msg, "Cannot write to file %s", newfile); putmsg(msg); anymarked = NO; break; } /* if there was an old file */ if (*oldfile != '\0') { (void) fprintf(script, "w\n"); /* save it */ } /* edit the new file */ (void) strcpy(oldfile, newfile); (void) fprintf(script, "e %s\n", oldfile); } /* output substitute command */ (void) fprintf(script, "%ss/", linenum); /* change */ for (s = pattern; *s != '\0'; ++s) { /* old text */ if (*s == '/') { (void) putc('\\', script); } (void) putc(*s, script); } (void) putc('/', script); /* to */ for (s = newpat; *s != '\0'; ++s) { /* new text */ if (strchr("/\\&", *s) != NULL) { (void) putc('\\', script); } (void) putc(*s, script); } (void) fprintf(script, "/gp\n"); /* and print */ } } (void) fprintf(script, "w\nq\n!\n"); /* write and quit */ (void) fclose(script); clearprompt(); /* if any line was marked */ if (anymarked == YES) { /* edit the files */ (void) refresh(); (void) fprintf(stderr, "Changed lines:\n\r"); (void) execute(shell, shell, temp2, (char *)NULL); askforreturn(); } nochange: changing = NO; initmenu(); free(change); seekline(topline); return (YES); /* clear any marks on exit without change */ }
void view(void) { static byte mod; static unsigned k; static unsigned long delta; static byte i; load_headers(); in_buf=0; ateof=0; atstart=1; scrollbar_pos=0xa000+29; if(last==0) last=header_length; goto_pos(last); mod=1; ozcls(); while(1) { if(mod) { if(!backandforth)position_save(); show(); unbar(); scrollbar(); backandforth=mod=0; } switch(k=ozgetchblank()) { case KEY_LEFT: case KEY_BACKSPACE: #ifdef DEBUG putformatted(0,0,"positionptr=| numpositions=| ", positionptr,numpositions); ozgetch(); #endif if(positionptr<=1) break; goto_pos(positions[(--positionptr)-1]); if(!positionptr) positionptr=1; backandforth=mod=1; #ifdef DEBUG putformatted(0,0,"positionptr=| numpositions=| ", positionptr,numpositions); ozgetch(); #endif break; case KEY_RIGHT: #ifdef DEBUG putformatted(0,0,"positionptr=| numpositions=| ", positionptr,numpositions); ozgetch(); #endif if(positionptr>=numpositions) break; goto_pos(positions[positionptr]); positionptr++; backandforth=mod=1; #ifdef DEBUG putformatted(0,0,"positionptr=| numpositions=| ", positionptr,numpositions); ozgetch(); #endif break; case 'm': /* mark position */ if(numbookmarks>=MAX_BOOKMARKS) { for(i=0;i<MAX_BOOKMARKS-1;i++) { bookmarks[i]=bookmarks[i+1]; } numbookmarks--; } bookmarkptr=numbookmarks; bookmarks[numbookmarks++]=screen_offset+buffer_offset; bookmarksmod=1; break; case 'b': if(numbookmarks) { goto_pos(bookmarks[bookmarkptr]); if(bookmarkptr) bookmarkptr--; else bookmarkptr=numbookmarks-1; mod=1; } break; case 'r': show_bar=!show_bar; bookmarksmod=1; unbar(); scrollbar(); break; case 'h': case KEY_UPPER_MENU: case KEY_LOWER_MENU: dohelp(); ozcls(); mod=1; break; case 'i': _ozfilledbox(0,0,WIDTH,line_height,0); delta=screen_offset+buffer_offset-header_length; putformatted(0,0,"$ : ^/^=|%",filename, delta,length-header_length, (unsigned int)(delta*100/(length-header_length)) ); _ozfilledbox(0,0,WIDTH,line_height,XOR); ozgetchblank(); mod=1; ozcls(); break; case 'c': if(numbookmarks && ozwarn("Delete all bookmarks?",yn)==KEY_LOWER_ENTER ) { bookmarksmod=1; numbookmarks=0; } mod=1; ozcls(); break; case '-': case KEY_PAGEUP: for(i=0;i<num_lines-1;i++) { checkshiftup(); backline(); } mod=1; break; case 's': if(myfont) break; line_height++; if(line_height==11) line_height=8; if(line_height!=9) num_lines=80/line_height; else num_lines=9; bookmarksmod=1; mod=1; ozcls(); break; case KEY_PAGEDOWN: case KEY_LOWER_ENTER: case KEY_UPPER_ENTER: case KEY_RETURN: case ' ': for(i=0;i<num_lines-1;i++) { checkshiftdown(); forwardline(); } mod=1; break; case KEY_UP: checkshiftup(); if(!backline()) break; unbar(); ozscrolldown(line_height*30); dcompline(filebuf+screen_offset); puttextline(0); position_save(); scrollbar(); break; case KEY_DOWN: checkshiftdown(); if(forwardline()) { mod=1; showbot=1; unbar(); ozscroll(line_height*30); } break; case KEY_LEFT_SHIFT | MASKSHIFT: case KEY_RIGHT_SHIFT | MASKSHIFT: switch(ozgetch() & 0xF0FF) { case '-': ozclick(!ozgetclick()); ozsavekeysettings(); break; case KEY_PAGEUP: case KEY_UP: tenpercent(-1); mod=1; break; case KEY_PAGEDOWN: case KEY_DOWN: tenpercent(1); mod=1; break; } break; case KEY_UP | MASKSHIFT: case KEY_PAGEUP | MASKSHIFT: tenpercent(-1); mod=1; break; case KEY_PAGEDOWN | MASKSHIFT: case KEY_DOWN | MASKSHIFT: tenpercent(1); mod=1; break; case KEY_2ND: switch(ozgetch() & 0xF0FF ) { case '-': ozclick(!ozgetclick()); ozsavekeysettings(); break; case KEY_PAGEUP: case KEY_UP: goto_pos(header_length); mod=1; break; case KEY_PAGEDOWN: case KEY_DOWN: goto_pos(length); mod=1; break; } break; case KEY_LOWER_ESC: case KEY_UPPER_ESC: case KEY_MYPROGRAMS: exit(0); case KEY_MAIN: case KEY_CALENDAR: case KEY_TELEPHONE: case KEY_MEMO: ozexitto(k); case KEY_BACKLIGHT: oztogglelight(); break; } } }
void iDraw() { int m,n; iClear(); iSetcolor(1,1,1); iFilledRectangle(1,1,width-19,height-18); //draw text box iSetcolor(0,0,0); iRectangle(1,1,width-19,height-19); //draw text boundary if (selflag) { for (int l=selSI; l<=selEI; l++) { int sx = (l==selSI)?( (selSJ==0)?3:selSJ*charSpace) : 3; int sy = height - 17 - (l+1-s)*lineSpace - 5; int w; if (l==selSI) w = (selSI == selEI) ? selEJ-selSJ : strlen(str+l*charMax*sizeof(char))-selSJ; else if (l==selEI) w = selEJ; else w = (strlen(str+l*charMax*sizeof(char))==0)?1:strlen(str+l*charMax*sizeof(char)); iSetcolor(.8,.8,.9); iFilledRectangle(sx,sy,w*charSpace,lineSpace); } } iSetcolor(0,0,0); for (m=height-17-lineSpace, n=s; n<=imax; m-=lineSpace, n++) { iText(3, m, str+n*charMax*sizeof(char),font); //print text } if (fOpen) { fileopen(); iSetcolor(0,0,0); iText((width-15)/2-135,(height-19)/2+62,subTemp+r); //print file open text } else if (fsave) { filesave(); iSetcolor(0,0,0); iText((width-15)/2-135,(height-19)/2+62,subTemp+r); //print file save as text } else if (aboutR) { aboutRword(); } cursor(); //draw cursor iSetcolor(.9,.9,.9); iFilledRectangle(3,height-17,width-19,17); iSetcolor(0,0,0); iLine(2,height-18,width-19,height-18); iSetcolor(0,0,0); iText(5,height-12,"File",GLUT_BITMAP_HELVETICA_12); iSetcolor(0,0,0); iText(45,height-12,"Edit",GLUT_BITMAP_HELVETICA_12); iSetcolor(0,0,0); iText(85,height-12,"Format",GLUT_BITMAP_HELVETICA_12); iSetcolor(0,0,0); iText(141,height-12,"Help",GLUT_BITMAP_HELVETICA_12); //draw menus if (menuflag == 1) { fileMenu(); //draw file drop down menu } else if (menuflag == 2) { editMenu(); //draw edit drop down menu } else if (menuflag == 3) { formatMenu(); //draw format drop down menu } else if (menuflag == 4) { helpMenu(); //draw help drop down menu } if (fontflag) { fontlist(); //draw font list } else if (saveM) { saveMessage(); //message box while exitting } scrollbar(); // draw scrollbar if (load) loading(); //load window }