void help (char const * list []) { unsigned lower = 0; unsigned upper = 0; unsigned limit = 0; unsigned width = 0; unsigned field = 0; unsigned block = 0; unsigned group = 0; getviewport ((unsigned *)(0), &width); for (limit = 0; !list [limit]; limit++) { block = strlen (list [limit]); if (block > field) { field = block; } } group = width / (field + 1); block = (limit + group - 1) / group; field = (width / group); putc ('\n', stdout); for (lower = 0; lower < block; lower++) { for (upper = lower; upper < limit; upper += block) { printf (" %-*.*s", (int)(field-1), (int)(field-1), list [upper]); } putc ('\n', stdout); } putc ('\n', stdout); return; }
char * openStringBox(const char *title) { char *str = (char *)malloc(256 * sizeof(char)); int x0,y0; int x,y; getviewport(&x0,&y0,&x,&y); cleardevice(); initgraph(400,300); inputbox_getline(title,"输入文字,限制100字",str,100); cleardevice(); initgraph(x,y); return str; }
void NetPlayerInfoView::show() { if (buffer_img_.img) { putimage(buffer_img_.x, buffer_img_.y, buffer_img_.img); delimage(buffer_img_.img); buffer_img_.img = NULL; } calc_view_width_height(); buffer_img_.x = pos_x_; buffer_img_.y = pos_y_; int temp_viewport_left, temp_viewport_right, temp_viewport_top, temp_viewport_bottom; getviewport(&temp_viewport_left, &temp_viewport_top, &temp_viewport_right, &temp_viewport_bottom); setviewport(pos_x_, pos_y_, pos_x_ + view_width_, pos_y_ + view_height_); buffer_img_.img = newimage(view_width_, view_height_); putimage(buffer_img_.img, 0, 0, NULL); setviewport(temp_viewport_left, temp_viewport_top, temp_viewport_right, temp_viewport_bottom); int target_top = pos_y_; if (player_pic_) { player_pic_->show_image_with_alpha(pos_x_ + view_width_ / 2 - player_pic_->get_width() / 2, target_top, 1.0); target_top += player_pic_->get_width() + margin_; } setcolor(WHITE); if (player_name_.length() > 0) { Gobang::set_font(Gobang::font_default, name_font_size_, true); xyprintf(pos_x_ + view_width_ / 2 - textwidth(player_name_.c_str()) / 2, target_top, player_name_.c_str()); target_top += textheight(player_name_.c_str()) + margin_; } if (is_ready_) { Gobang::set_font(Gobang::font_default, ready_font_size_); xyprintf(pos_x_ + view_width_ / 2 - textwidth("Ready!") / 2, target_top, "Ready!"); target_top += textheight("Ready!") + margin_; if (is_playing_) { playing_indicator_->show_image_with_alpha(pos_x_ + view_width_ / 2 - playing_indicator_->get_width() / 2, target_top, 1.0); target_top += playing_indicator_->get_height() + margin_; } } else if (!is_opposite_) { button_ready_->set_position(pos_x_ + view_width_ / 2 - button_ready_->get_width() / 2, target_top); button_ready_->show(); target_top += button_ready_->get_height() + margin_; } }
void svprint (char const * vector []) { unsigned screenwidth = 0; unsigned columnwidth = 0; unsigned columncount = 0; unsigned word = 0; unsigned words = 0; unsigned line = 0; unsigned lines = 0; getviewport ((unsigned *)(0), &screenwidth); for (words = 0; vector [words] != (char const *)(0); words++) { columncount = strlen (vector [words]); if (columncount > columnwidth) { columnwidth = columncount; } } columnwidth++; if (columnwidth < screenwidth) { columncount = screenwidth / columnwidth; columnwidth = screenwidth / columncount; lines = (words + columncount - 1) / columncount; putc ('\n', stdout); for (line = 0; line < lines; line++) { for (word = line; word < words; word += lines) { char const *string = vector [word]; while ((string - vector [word]) < columnwidth) { if (*string == (char)(0)) { break; } putc (*string++, stdout); } while ((string - vector [word]) < columnwidth) { putc (' ', stdout); string++; } } putc ('\n', stdout); } putc ('\n', stdout); } return; }
int main (int argc, char const * argv []) { static char const * optv [] = { "l:w:", PUTOPTV_S_FUNNEL, "copy one or more file headers to stdout", "l n\tdisplay line count is (n) [" LITERAL (VT_LINES) "]", "w n\tdisplay line width is (n) [" LITERAL (VT_LIMIT) "]", (char const *)(0) }; unsigned lines = VT_LINES; unsigned width = VT_LIMIT; signed c; getviewport (& lines, & width); lines--; lines--; width--; while (~ (c = getoptv (argc, argv, optv))) { switch (c) { case 'l': lines = uintspec (optarg, 1, SHRT_MAX); break; case 'w': width = uintspec (optarg, 1, SHRT_MAX); break; default: break; } } argc -= optind; argv += optind; if (!argc) { function (lines, width); } while ((argc) && (* argv)) { if (efreopen (* argv, "rb", stdin)) { function (lines, width); } argc--; argv++; } exit (0); }
int moveWindow(HWND hwnd) { static int posx,posy; static int state1=1; int pleft,ptop,pright,pbottom; getviewport(&pleft,&ptop,&pright,&pbottom); if(isLButton()) { if(state1==1) { posx=mouse(X); posy=mouse(Y); state1=0; } inf.CS_x=inf.CS_x+mouse(X)-posx; inf.CS_y=inf.CS_y+mouse(Y)-posy; MoveWindow(hwnd,inf.CS_x,inf.CS_y,pright,pbottom,false); } else state1=1; return 0; }
/* * a routine to demonstrate using locator. */ main() { int i, bt, act, nchars; short data; Scoord x, y, sx, sy; Screencoord minx, maxx, miny, maxy; ginit(); color(BLACK); clear(); color(BLUE); getviewport(&minx, &maxx, &miny, &maxy); ortho2((Coord)minx, (Coord)maxx, (Coord)miny, (Coord)maxy); /* * draw some axes */ move2s((Scoord)minx, (Scoord)((maxy - miny) / 2)); draw2s((Scoord)maxx, (Scoord)((maxy - miny) / 2)); move2s((Scoord)((maxx - minx) / 2), (Scoord)miny); draw2s((Scoord)((maxx - minx) / 2), (Scoord)maxy); color(GREEN); /* * enable the left and middle mouse buttons */ unqdevice(INPUTCHANGE); qdevice(LEFTMOUSE); qdevice(MIDDLEMOUSE); /* * Wait for REDRAW event ... */ while (qread(&data) != REDRAW) ; act = 0; /* * getvaluator tells us the valuator's value. In * this case it's the X and Y positions of the mouse. * Note: these come back to us in screen coordinates. */ while((bt = qread(&data)) != MIDDLEMOUSE) { sx = getvaluator(MOUSEX); sy = getvaluator(MOUSEY); if (bt == -1) { gexit(); printf("No locator device found\n"); exit(0); } else { if (act) { act = 0; move2s(sx, sy); draw2s(x, y); } else { act = 1; x = sx; y = sy; } } (void)qread(&data); /* swallow the up event */ } gexit(); }