~RB_Tree() { for(iterator iter=begin(); iter !=end();) { eraser(iter++); } _root=_nil; }
void PreviewWidget::paintEvent( QPaintEvent * ) { int i_total = 0, i_offset = 0, i; QPainter painter( this ); QPixmap pixmaps[3]; for( int i=0; i<3; i++ ) { pixmaps[i] = QPixmap::grabWidget( bars[i], bars[i]->contentsRect() ); for( int j=0; j < bars[i]->layout()->count(); j++ ) { QLayoutItem *item = bars[i]->layout()->itemAt( j ); if ( !strcmp( item->widget()->metaObject()->className(), "QLabel" ) ) { QPainter eraser( &pixmaps[i] ); eraser.fillRect( item->geometry(), palette().background() ); eraser.end(); } } pixmaps[i] = pixmaps[i].scaled( size(), Qt::KeepAspectRatio ); } for( i=0; i<3; i++ ) i_total += pixmaps[i].size().height(); /* Draw top bars */ i = ( b_top ) ? 1 : 3; for( ; i<3; i++ ) { painter.drawPixmap( pixmaps[i].rect().translated( 0, i_offset ), pixmaps[i] ); i_offset += pixmaps[i].rect().height(); } /* Draw central area */ QRect conearea( 0, i_offset, size().width(), size().height() - i_total ); painter.fillRect( conearea, Qt::black ); QPixmap cone = QPixmap( ":/logo/vlc128.png" ); if ( ( conearea.size() - QSize(10, 10) - cone.size() ).isEmpty() ) cone = cone.scaled( conearea.size() - QSize(10, 10), Qt::KeepAspectRatio ); if ( cone.size().isValid() ) { painter.drawPixmap( ((conearea.size() - cone.size()) / 2).width(), i_offset + ((conearea.size() - cone.size()) / 2).height(), cone ); } /* Draw bottom bars */ i_offset += conearea.height(); for( i = 0 ; i< ((b_top) ? 1 : 3); i++ ) { painter.drawPixmap( pixmaps[i].rect().translated( 0, i_offset ), pixmaps[i] ); i_offset += pixmaps[i].rect().height(); } /* Draw overlay */ painter.fillRect( rect(), QColor( 255, 255, 255, 128 ) ); painter.end(); }
gint button_release_event(GtkWidget *widget,GdkEventButton *event ) { if (event->state & GDK_BUTTON1_MASK && pixmap != NULL) switch(tool) { case RECT_SEL: select_rectangular_region(widget,event->x,event->y,0); selected++; break; case ERASER: eraser(widget,event->x,event->y); break; case LINE:draw_line(widget,event->x,event->y,0); break; case BRUSH: paintbrush(widget,event->x,event->y); break; case SPRAYCAN: spraycan(widget,event->x,event->y); break; case PENCIL:draw_using_pencil(widget,event->x,event->y); break; case BUCKET: break; case POLYLINE: draw_line(widget,event->x,event->y,0); pre_x=last_x=event->x; pre_y=last_y=event->y; break; case ELLIPSE: draw_arc(widget,event->x,event->y,0); break; case POLYGON: draw_polygon(widget,event->x,event->y,0); last_x=event->x; last_y=event->y; lineflag++; break; case RECTANGLE:draw_rectangle(widget,event->x,event->y,0); break; } return TRUE; }
program() { var filename=COMMAND.a(2); var itemids=erase(COMMAND,1,0,0); eraser(itemids,1,0,0); var silent=index(ucase(OPTIONS),"S"); if (not filename or not itemids) abort("Syntax is 'delete filename itemid ... (S=Silent)'"); var file; if (not open(filename,file)) abort(filename^" file does not exist."); var sep=0; var posn=1; var ndeleted=0; do { var itemid=remove(itemids,posn,sep); if (itemid=="*") { clearfile(file); if (not silent) printl("All records deleted"); stop(); } if (deleterecord(file,itemid)) ++ndeleted; else if (not silent) printl(quote(itemid)^" does not exist."); } while (sep); if (not silent) printl(ndeleted^" record(s) deleted."); }
static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) { unsigned long flags; int parmrk; if (tty->raw) { put_tty_queue(c, tty); return; } if (I_ISTRIP(tty)) c &= 0x7f; if (I_IUCLC(tty) && L_IEXTEN(tty)) c = tolower(c); if (L_EXTPROC(tty)) { put_tty_queue(c, tty); return; } if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) && c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && c != SUSP_CHAR(tty)) { start_tty(tty); process_echoes(tty); } if (tty->closing) { if (I_IXON(tty)) { if (c == START_CHAR(tty)) { start_tty(tty); process_echoes(tty); } else if (c == STOP_CHAR(tty)) stop_tty(tty); } return; } if (!test_bit(c, tty->process_char_map) || tty->lnext) { tty->lnext = 0; parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { if (L_ECHO(tty)) process_output('\a', tty); return; } if (L_ECHO(tty)) { finish_erasing(tty); if (tty->canon_head == tty->read_head) echo_set_canon_col(tty); echo_char(c, tty); process_echoes(tty); } if (parmrk) put_tty_queue(c, tty); put_tty_queue(c, tty); return; } if (I_IXON(tty)) { if (c == START_CHAR(tty)) { start_tty(tty); process_echoes(tty); return; } if (c == STOP_CHAR(tty)) { stop_tty(tty); return; } } if (L_ISIG(tty)) { int signal; signal = SIGINT; if (c == INTR_CHAR(tty)) goto send_signal; signal = SIGQUIT; if (c == QUIT_CHAR(tty)) goto send_signal; signal = SIGTSTP; if (c == SUSP_CHAR(tty)) { send_signal: if (!L_NOFLSH(tty)) { n_tty_flush_buffer(tty); tty_driver_flush_buffer(tty); } if (I_IXON(tty)) start_tty(tty); if (L_ECHO(tty)) { echo_char(c, tty); process_echoes(tty); } if (tty->pgrp) kill_pgrp(tty->pgrp, signal, 1); return; } } if (c == '\r') { if (I_IGNCR(tty)) return; if (I_ICRNL(tty)) c = '\n'; } else if (c == '\n' && I_INLCR(tty)) c = '\r'; if (tty->icanon) { if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { eraser(c, tty); process_echoes(tty); return; } if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { tty->lnext = 1; if (L_ECHO(tty)) { finish_erasing(tty); if (L_ECHOCTL(tty)) { echo_char_raw('^', tty); echo_char_raw('\b', tty); process_echoes(tty); } } return; } if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { unsigned long tail = tty->canon_head; finish_erasing(tty); echo_char(c, tty); echo_char_raw('\n', tty); while (tail != tty->read_head) { echo_char(tty->read_buf[tail], tty); tail = (tail+1) & (N_TTY_BUF_SIZE-1); } process_echoes(tty); return; } if (c == '\n') { if (tty->read_cnt >= N_TTY_BUF_SIZE) { if (L_ECHO(tty)) process_output('\a', tty); return; } if (L_ECHO(tty) || L_ECHONL(tty)) { echo_char_raw('\n', tty); process_echoes(tty); } goto handle_newline; } if (c == EOF_CHAR(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE) return; if (tty->canon_head != tty->read_head) set_bit(TTY_PUSH, &tty->flags); c = __DISABLED_CHAR; goto handle_newline; } if ((c == EOL_CHAR(tty)) || (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) { if (L_ECHO(tty)) process_output('\a', tty); return; } if (L_ECHO(tty)) { if (tty->canon_head == tty->read_head) echo_set_canon_col(tty); echo_char(c, tty); process_echoes(tty); } if (parmrk) put_tty_queue(c, tty); handle_newline: spin_lock_irqsave(&tty->read_lock, flags); set_bit(tty->read_head, tty->read_flags); put_tty_queue_nolock(c, tty); tty->canon_head = tty->read_head; tty->canon_data++; spin_unlock_irqrestore(&tty->read_lock, flags); kill_fasync(&tty->fasync, SIGIO, POLL_IN); if (waitqueue_active(&tty->read_wait)) wake_up_interruptible(&tty->read_wait); return; } } parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { if (L_ECHO(tty)) process_output('\a', tty); return; } if (L_ECHO(tty)) { finish_erasing(tty); if (c == '\n') echo_char_raw('\n', tty); else { if (tty->canon_head == tty->read_head) echo_set_canon_col(tty); echo_char(c, tty); } process_echoes(tty); } if (parmrk) put_tty_queue(c, tty); put_tty_queue(c, tty); }
static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) { if (tty->raw) { put_tty_queue(c, tty); return; } if (tty->stopped && I_IXON(tty) && I_IXANY(tty)) { start_tty(tty); return; } if (I_ISTRIP(tty)) c &= 0x7f; if (I_IUCLC(tty) && L_IEXTEN(tty)) c=tolower(c); if (tty->closing) { if (I_IXON(tty)) { if (c == START_CHAR(tty)) start_tty(tty); else if (c == STOP_CHAR(tty)) stop_tty(tty); } return; } /* * If the previous character was LNEXT, or we know that this * character is not one of the characters that we'll have to * handle specially, do shortcut processing to speed things * up. */ if (!test_bit(c, &tty->process_char_map) || tty->lnext) { finish_erasing(tty); tty->lnext = 0; if (L_ECHO(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { put_char('\a', tty); /* beep if no space */ return; } /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) tty->canon_column = tty->column; echo_char(c, tty); } if (I_PARMRK(tty) && c == (unsigned char) '\377') put_tty_queue(c, tty); put_tty_queue(c, tty); return; } if (c == '\r') { if (I_IGNCR(tty)) return; if (I_ICRNL(tty)) c = '\n'; } else if (c == '\n' && I_INLCR(tty)) c = '\r'; if (I_IXON(tty)) { if (c == START_CHAR(tty)) { start_tty(tty); return; } if (c == STOP_CHAR(tty)) { stop_tty(tty); return; } } if (L_ISIG(tty)) { int signal; signal = SIGINT; if (c == INTR_CHAR(tty)) goto send_signal; signal = SIGQUIT; if (c == QUIT_CHAR(tty)) goto send_signal; signal = SIGTSTP; if (c == SUSP_CHAR(tty)) { send_signal: isig(signal, tty, 0); return; } } if (L_ICANON(tty)) { if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { eraser(c, tty); return; } if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { tty->lnext = 1; if (L_ECHO(tty)) { finish_erasing(tty); if (L_ECHOCTL(tty)) { put_char('^', tty); put_char('\b', tty); } } return; } if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { unsigned long tail = tty->canon_head; finish_erasing(tty); echo_char(c, tty); opost('\n', tty); while (tail != tty->read_head) { echo_char(tty->read_buf[tail], tty); tail = (tail+1) & (N_TTY_BUF_SIZE-1); } return; } if (c == '\n') { if (L_ECHO(tty) || L_ECHONL(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { put_char('\a', tty); return; } opost('\n', tty); } goto handle_newline; } if (c == EOF_CHAR(tty)) { if (tty->canon_head != tty->read_head) set_bit(TTY_PUSH, &tty->flags); c = __DISABLED_CHAR; goto handle_newline; } if ((c == EOL_CHAR(tty)) || (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { /* * XXX are EOL_CHAR and EOL2_CHAR echoed?!? */ if (L_ECHO(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { put_char('\a', tty); return; } /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) tty->canon_column = tty->column; echo_char(c, tty); } /* * XXX does PARMRK doubling happen for * EOL_CHAR and EOL2_CHAR? */ if (I_PARMRK(tty) && c == (unsigned char) '\377') put_tty_queue(c, tty); handle_newline: set_bit(tty->read_head, &tty->read_flags); put_tty_queue(c, tty); tty->canon_head = tty->read_head; tty->canon_data++; if (tty->fasync) kill_fasync(tty->fasync, SIGIO); if (tty->read_wait) wake_up_interruptible(&tty->read_wait); return; } } finish_erasing(tty); if (L_ECHO(tty)) { if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { put_char('\a', tty); /* beep if no space */ return; } if (c == '\n') opost('\n', tty); else { /* Record the column of first canon char. */ if (tty->canon_head == tty->read_head) tty->canon_column = tty->column; echo_char(c, tty); } } if (I_PARMRK(tty) && c == (unsigned char) '\377') put_tty_queue(c, tty); put_tty_queue(c, tty); }
void maskImageWidget::init(const QImage& image) { setWindowTitle(tr("Mask Editor")); QPixmap load("coral_open32x32.png"); QPixmap save("coral_save32x32.png"); QPixmap undo("coral_undo32x32.png"); QPixmap redo("coral_redo32x32.png"); QPixmap pen("coral_pencil32x32.png"); QPixmap eraser("coral_eraser32x32.png"); QAction *canvasloadmask = new QAction(this); canvasloadmask->setIcon(load); canvasloadmask->setText(tr("&Load Mask")); QAction *canvassavemask = new QAction(this); canvassavemask->setIcon(QIcon(save)); canvassavemask->setText(tr("&Save Mask")); QAction *canvasundo = new QAction(this); canvasundo->setIcon(QIcon(undo)); canvasundo->setText(tr("&Undo")); canvasundo->setShortcut(QKeySequence("Ctrl+Z")); QAction *canvasredo = new QAction(this); canvasredo->setIcon(QIcon(redo)); canvasredo->setText(tr("&Redo")); canvasredo->setShortcut(QKeySequence("Ctrl+Shift+Z")); QAction *canvasclear = new QAction(tr("&Clear"), this); canvasclear->setShortcut(QKeySequence("Ctrl+C")); QAction *canvaspen = new QAction(this); canvaspen->setIcon(QIcon(pen)); canvaspen->setText(tr("&Pen")); QAction *canvaseraser = new QAction(this); canvaseraser->setIcon(QIcon(eraser)); canvaseraser->setText(tr("&Eraser")); QActionGroup *actions(new QActionGroup(this)); actions->addAction(canvaspen); actions->addAction(canvaseraser); canvaspen->setCheckable(true); canvaseraser->setCheckable(true); canvaspen->setChecked(true); actions->setExclusive(true); QAction *canvasOK = new QAction(this); canvasOK->setText("OK"); QAction *canvasCancel = new QAction(this); canvasCancel->setText("Cancel"); QBoxLayout *layout(new QVBoxLayout(this)); // We don't want a real-size image. We will downscale it! QImage image_to_use = image; pimpl_->realwidth_ = image.width(); pimpl_->realheight_ = image.height(); qDebug("maskImageWidget::Init real wxh %i x%i",pimpl_->realwidth_,pimpl_->realheight_); QDesktopWidget *desktop(QApplication::desktop()); if (image.width() > (desktop->width() * .8) || image.height() > (desktop->height() * .8)) { int width(desktop->width()), height(desktop->height()); image_to_use = image.scaled((int)std::floor(width * .75), (int)std::floor(height * .75), Qt::KeepAspectRatio); } pimpl_->render_area_ = new maskRenderWidget(image_to_use, this); QToolBar *canvas_toolbar(new QToolBar(this)); canvas_toolbar->addSeparator(); canvas_toolbar->addAction(canvasloadmask); canvas_toolbar->addAction(canvassavemask); canvas_toolbar->addSeparator(); canvas_toolbar->addAction(canvasundo); canvas_toolbar->addAction(canvasredo); canvas_toolbar->addSeparator(); QSpinBox *pen_width(new QSpinBox(canvas_toolbar)); pen_width->setToolTip(tr("Pen Width")); pen_width->setRange(0, 80); pen_width->setSingleStep(2); pen_width->setValue(16); connect(pen_width, SIGNAL(valueChanged(int)), SLOT(setCanvasPenWidth(int))); canvas_toolbar->addWidget(pen_width); canvas_toolbar->addAction(canvaspen); canvas_toolbar->addAction(canvaseraser); canvas_toolbar->addSeparator(); QSpinBox *gradient(new QSpinBox(canvas_toolbar)); gradient->setToolTip("Gradient Threshold"); gradient->setRange(0, 255); gradient->setValue(pimpl_->threshold_gradient_); connect(gradient, SIGNAL(valueChanged(int)), SLOT(setGradientThreshold(int))); QSpinBox *fixed(new QSpinBox(canvas_toolbar)); fixed->setToolTip("Fixed Threshold"); fixed->setRange(0, 255); fixed->setValue(pimpl_->threshold_fixed_); connect(fixed, SIGNAL(valueChanged(int)), SLOT(setFixedThreshold(int))); canvas_toolbar->addWidget(gradient); canvas_toolbar->addWidget(fixed); canvas_toolbar->addSeparator(); canvas_toolbar->addAction(canvasOK); canvas_toolbar->addAction(canvasCancel); layout->addWidget(canvas_toolbar); layout->addWidget(pimpl_->render_area_); layout->setSizeConstraint(QLayout::SetFixedSize); connect(canvasloadmask, SIGNAL(activated()), SLOT(loadMask())); connect(canvassavemask, SIGNAL(activated()), SLOT(saveMask())); connect(canvasundo, SIGNAL(activated()), pimpl_->render_area_, SLOT(undo())); connect(canvasredo, SIGNAL(activated()), pimpl_->render_area_, SLOT(redo())); connect(canvasclear, SIGNAL(activated()), pimpl_->render_area_, SLOT(clear())); connect(canvaspen, SIGNAL(activated()), SLOT(setCanvasPen())); connect(canvaseraser, SIGNAL(activated()), SLOT(setCanvasEraser())); connect(pimpl_->render_area_, SIGNAL(pointSelected(const QPoint &)), SLOT(automaticMask(const QPoint &))); connect(canvasOK, SIGNAL(activated()), SLOT(accept())); connect(canvasCancel, SIGNAL(activated()), SLOT(reject())); }
static void copy_to_cooked(struct tty_struct * tty) { int c, special_flag; unsigned long flags; if (!tty) { printk("copy_to_cooked: called with NULL tty\n"); return; } if (!tty->write) { printk("copy_to_cooked: tty %d has null write routine\n", tty->line); } while (1) { /* * Check to see how much room we have left in the * secondary queue. Send a throttle command or abort * if necessary. */ c = LEFT(&tty->secondary); if (tty->throttle && (c < SQ_THRESHOLD_LW) && !set_bit(TTY_SQ_THROTTLED, &tty->flags)) tty->throttle(tty, TTY_THROTTLE_SQ_FULL); if (c == 0) break; save_flags(flags); cli(); if (!EMPTY(&tty->read_q)) { c = tty->read_q.buf[tty->read_q.tail]; special_flag = clear_bit(tty->read_q.tail, &tty->readq_flags); INC(tty->read_q.tail); restore_flags(flags); } else { restore_flags(flags); break; } if (special_flag) { tty->char_error = c; continue; } if (tty->char_error) { if (tty->char_error == TTY_BREAK) { tty->char_error = 0; if (I_IGNBRK(tty)) continue; /* A break is handled by the lower levels. */ if (I_BRKINT(tty)) continue; if (I_PARMRK(tty)) { put_tty_queue('\377', &tty->secondary); put_tty_queue('\0', &tty->secondary); } put_tty_queue('\0', &tty->secondary); continue; } if (tty->char_error == TTY_OVERRUN) { tty->char_error = 0; printk("tty%d: input overrun\n", tty->line); continue; } /* Must be a parity or frame error */ tty->char_error = 0; if (I_IGNPAR(tty)) { continue; } if (I_PARMRK(tty)) { put_tty_queue('\377', &tty->secondary); put_tty_queue('\0', &tty->secondary); put_tty_queue(c, &tty->secondary); } else put_tty_queue('\0', &tty->secondary); continue; } if (I_ISTRIP(tty)) c &= 0x7f; if (!tty->lnext) { if (c == '\r') { if (I_IGNCR(tty)) continue; if (I_ICRNL(tty)) c = '\n'; } else if (c == '\n' && I_INLCR(tty)) c = '\r'; } if (I_IUCLC(tty) && L_IEXTEN(tty)) c=tolower(c); if (c == __DISABLED_CHAR) tty->lnext = 1; if (L_ICANON(tty) && !tty->lnext) { if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { eraser(c, tty); continue; } if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { tty->lnext = 1; if (L_ECHO(tty)) { if (tty->erasing) { opost('/', tty); tty->erasing = 0; } if (L_ECHOCTL(tty)) { opost('^', tty); opost('\b', tty); } } continue; } if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { unsigned long tail = tty->canon_head; if (tty->erasing) { opost('/', tty); tty->erasing = 0; } echo_char(c, tty); opost('\n', tty); while (tail != tty->secondary.head) { echo_char(tty->secondary.buf[tail], tty); INC(tail); } continue; } } if (I_IXON(tty) && !tty->lnext) { if ((tty->stopped && I_IXANY(tty) && L_IEXTEN(tty)) || c == START_CHAR(tty)) { start_tty(tty); continue; } if (c == STOP_CHAR(tty)) { stop_tty(tty); continue; } } if (L_ISIG(tty) && !tty->lnext) { if (c == INTR_CHAR(tty)) { isig(SIGINT, tty); continue; } if (c == QUIT_CHAR(tty)) { isig(SIGQUIT, tty); continue; } if (c == SUSP_CHAR(tty)) { if (!is_orphaned_pgrp(tty->pgrp)) isig(SIGTSTP, tty); continue; } } if (tty->erasing) { opost('/', tty); tty->erasing = 0; } if (c == '\n' && !tty->lnext) { if (L_ECHO(tty) || (L_ICANON(tty) && L_ECHONL(tty))) opost('\n', tty); } else if (L_ECHO(tty)) { /* Don't echo the EOF char in canonical mode. Sun handles this differently by echoing the char and then backspacing, but that's a hack. */ if (c != EOF_CHAR(tty) || !L_ICANON(tty) || tty->lnext) { /* Record the column of first canon char. */ if (tty->canon_head == tty->secondary.head) tty->canon_column = tty->column; echo_char(c, tty); } } if (I_PARMRK(tty) && c == (unsigned char) '\377' && (c != EOF_CHAR(tty) || !L_ICANON(tty) || tty->lnext)) put_tty_queue(c, &tty->secondary); if (L_ICANON(tty) && !tty->lnext && (c == '\n' || c == EOF_CHAR(tty) || c == EOL_CHAR(tty) || (c == EOL2_CHAR(tty) && L_IEXTEN(tty)))) { if (c == EOF_CHAR(tty)) c = __DISABLED_CHAR; set_bit(tty->secondary.head, &tty->secondary_flags); put_tty_queue(c, &tty->secondary); tty->canon_head = tty->secondary.head; tty->canon_data++; } else put_tty_queue(c, &tty->secondary); tty->lnext = 0; } if (!EMPTY(&tty->write_q)) TTY_WRITE_FLUSH(tty); if (L_ICANON(tty) ? tty->canon_data : !EMPTY(&tty->secondary)) wake_up_interruptible(&tty->secondary.proc_list); if (tty->throttle && (LEFT(&tty->read_q) >= RQ_THRESHOLD_HW) && clear_bit(TTY_RQ_THROTTLED, &tty->flags)) tty->throttle(tty, TTY_THROTTLE_RQ_AVAIL); }
//=============================================== DiskAccessor::DiskAccessor( GsTLInt size, const std::string& filename, const float* prop, const bool* flags ) : buffer_size_( std::min( size, 10000 ) ) { cache_filename_ = DiskAccessor::cache_filename( filename ); // if the file already exists, erase its content by opening it in write mode // (I don't know any other easy way to do that...) std::ofstream eraser( cache_filename_.c_str() ); eraser.close(); // Open a stream to the cache file in read/write mode cache_stream_.open( cache_filename_.c_str(), std::ios::in | std::ios::out | std::ios::binary ); if( !cache_stream_ ) { GsTLcerr << "Can't write temporary file. Check that the directory is writable\n" << "and that there is enough disk space left" << gstlIO::end; } flags_position_begin_ = static_cast<long int>( sizeof( float ) ) * static_cast<long int>( size ); val_bound_indexes_.first = -9; val_bound_indexes_.second = -9; flags_bound_indexes_.first = -9; flags_bound_indexes_.second = -9; val_buffer_modified_ = false; size_ = size; val_buffer_ = new float[buffer_size_]; flags_buffer_ = new bool[buffer_size_]; // If property values or flags were supplied, write them to file if( prop ) { long int remaining = static_cast<long int>( size_ ) * static_cast<long int>( sizeof(float) ); cache_stream_.write( (char*) prop, remaining ); } else { // write arbitrary values float arbitrary = Grid_continuous_property::no_data_value; for(GsTLInt i=0; i< size; i++ ) cache_stream_.write( (char*) &arbitrary, 1 ); } if( flags ) { long int remaining = static_cast<long int>( size_ ) * static_cast<long int>( sizeof(bool) ); cache_stream_.write( (char*) flags, remaining ); } else { // write default flag value (false) bool default_value = false; for(GsTLInt i=0; i< size; i++ ) cache_stream_.write( (char*) &default_value, 1 ); } close_cache_stream(); }
gint button_press_event( GtkWidget *widget, GdkEventButton *event ) { modified=1; if (event->button == 1 && pixmap != NULL) switch(tool) { case RECT_SEL: gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); pre_x=event->x; pre_y=event->y; select_rectangular_region(widget,event->x,event->y,1); last_x=event->x; last_y=event->y; break; case ERASER: gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); last_x=event->x; last_y=event->y; eraser(widget,event->x,event->y); break; case LINE: gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); pre_x=event->x; pre_y=event->y; draw_line(widget,event->x,event->y,0); last_x=event->x; last_y=event->y; break; case TEXT: gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); draw_text(widget,event->x,event->y); break; case BRUSH:gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); last_x=event->x; last_y=event->y; paintbrush(widget,event->x,event->y); break; case SPRAYCAN:gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); last_x=event->x; last_y=event->y; spraycan(widget,event->x,event->y); break; case PENCIL:gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); last_x=event->x; last_y=event->y; draw_using_pencil(widget,event->x,event->y); break; case BUCKET: bucketfill(widget,event->x,event->y); break; case COLORPICK: gdk_gc_copy(undo_gc,fg_gc); undoflag=1; colorpicker(widget,event->x,event->y); break; case POLYLINE:if(!poly) {pre_x=event->x; pre_y=event->y; poly++;} draw_polyline(widget,event->x,event->y,1); break; case ELLIPSE:gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); pre_x=event->x; pre_y=event->y; draw_arc(widget,event->x,event->y,0); last_x=event->x; last_y=event->y; break; case POLYGON:if(!poly) { pre_x=event->x; pre_y=event->y; last_x=event->x; last_y=event->y; poly++; } draw_polygon(widget,event->x,event->y,1); break; case RECTANGLE:gdk_draw_drawable(undomap,fg_gc,pixmap,0,0,0,0,-1,-1); pre_x=event->x; pre_y=event->y; draw_rectangle(widget,event->x,event->y,0); last_x=event->x; last_y=event->y; break; } return TRUE; }
gint motion_notify_event( GtkWidget *widget, GdkEventMotion *event ) { int x, y; GdkModifierType state; if (event->is_hint) gdk_window_get_pointer (event->window, &x, &y, &state); else /*To start drawing when mouse is just clicked without hint*/ { x = event->x; y = event->y; state = event->state; } if (state & GDK_BUTTON1_MASK && pixmap != NULL) switch(tool) { case RECT_SEL:select_rectangular_region(widget,x,y,1); last_x=x; last_y=y; break; case ERASER: eraser(widget,x,y); last_x=x; last_y=y; break; case LINE:draw_line(widget,x,y,1); last_x=x; last_y=y; break; case BRUSH: paintbrush(widget,x,y); last_x=x; last_y=y; break; case SPRAYCAN: spraycan(widget,x,y); last_x=x; last_y=y; break; case PENCIL:draw_using_pencil(widget,x,y); last_x=x; last_y=y; break; case BUCKET: break; case POLYLINE:draw_line(widget,x,y,1); last_x=x; last_y=y; break; case ELLIPSE: draw_arc(widget,x,y,1); last_x=event->x; last_y=event->y; break; case POLYGON: draw_polygon(widget,event->x,event->y,1); break; case RECTANGLE:draw_rectangle(widget,x,y,1); last_x=x; last_y=y; break; ; } return TRUE; }
void Mouse(char ch) { if(ch=='o') bar(0); else if(ch=='n') { setfillstyle(SOLID_FILL,15); hidemouse(); bar(42,62,598,458); mousecall(); setcolor(c); bar(c); } int cl,x5,y5,tool; int x1=604,y1=70,z=616,w=84; setfillstyle(cc,c); bar(12,290,27,310); //fillp show bar do { if(ch=='n') { ch='k'; if(tool==4) fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; else if(tool==1) fout<<"setfillstyle(SOLID_FILL,15);\n"; else if(tool==6) fout<<"setfillstyle("<<cc<<','<<c<<");\n"; fout<<"setcolor("<<c<<");\n"; fout<<"rectangle(42,62,598,458);\n"; } mousecall(); x1=604,y1=70,z=616,w=84; for(int i=0;i<8;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=1; if(v!=c) { fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; fout<<"setcolor("<<c<<");\n"; fout<<"rectangle(42,62,598,458);\n"; v=c; } c=i; setfillstyle(cc,c); bar(12,290,27,310); setfillstyle(SOLID_FILL,c); } } x1=621,y1=70,z=633,w=84; for( i=8;i<16;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=0; c=i; setfillstyle(cc,c); bar(12,290,27,310); setfillstyle(SOLID_FILL,c); if(v!=c) { fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; fout<<"setcolor("<<c<<");\n"; fout<<"rectangle(42,62,598,458);\n"; v=c; } } } x1=605,y1=320,z=637,w=457; for(i=7;i<11;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=0; cc=i; setfillstyle(cc,c); bar(12,290,27,310); if(v!=cc) { fout<<"setfillstyle("<<cc<<','<<c<<");\n"; v=cc; } } } x1=5,y1=320,z=37,w=457; for(i=2;i<7;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=0; cc=i; setfillstyle(cc,c); bar(12,290,27,310); if(v!=cc) { fout<<"setfillstyle("<<cc<<','<<c<<");\n"; v=cc; } } } bar(c); delay(100); mousepos(cl,x5,y5); if(x5>=621&&x5<=635&&y5>=3&&y5<=16) //changes made !!! { if(cl==1) { hidemouse(); break; } } mousepos(cl,x5,y5); int gg=0; gg=help_bar(gg); while(x5>=24&&x5<=36&&y5>=70&&y5<=84) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"RECTANGLE "); gg=1; if(cl==1) { tool=0; } } gg=help_bar(gg); static int er=1; mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=145&&y5<=159) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"ERASER "); gg=1; if(cl==1 && er==1) { tool=1; bar(15); fout<<"setfillstyle(SOLID_FILL,15);\n"; fout<<"setcolor(15);\n"; er=2; } } if(tool!=1) { bar(c); er=1; } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=70&&y5<=84) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"LINE"); gg=1; if(cl==1) { tool=2; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=90&&y5<=109) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"CIRCLE"); gg=1; if(cl==1) { tool=3; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=24&&x5<=36&&y5>=120&&y5<=134) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"BUCKET"); gg=1; if(cl==1) { if(cc!=1) { fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; cc=1; } tool=4; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=24&&x5<=36&&y5>=90&&y5<=109) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"BRUSH "); gg=1; if(cl==1) { tool=5; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=120&&y5<=134) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); gg=1; outtextxy(45,464,"FILLER"); if(cl==1) { tool=6; } } gg=help_bar(gg); mousepos(cl,x5,y5); static int v=0; if(x5>39 && x5<78 && y5>=42 && y5<=55) //save { if(cl==1) { char f[20]; hidemouse(); SBMP("temp.bmp"); if(op('b')) { strcpy(f,s); if(!strchr(f,'.')) strcat(f,".bmp"); int check; check=rename("temp.bmp",f); if(check==-1) { remove(f); rename("temp.bmp",f); } } if(v==0) { if(op('c')) { v=1; if(!strchr(s,'.')) strcat(s,".cpp"); strcpy(::f,s); } else if(bmp("temp.bmp",0,0)) {} else bmp(f,0,0); } if(bmp(f,0,0)); else bmp("temp.bmp",0,0); mousecall(); } } mousepos(cl,x5,y5); if(x5>=10 && x5<39 && y5>=42 && y5<=55) //open { if(cl==1) { hidemouse(); SBMP("temp.bmp"); if(op('o')) { if(!strchr(s,'.')) strcat(s,".bmp"); if(bmp(s,0,0)) { settextstyle(2,0,7); cleardevice(); setcolor(RED); outtextxy(200,220," SUCH FILE DOES NOT EXIST"); outtextxy(200,280,"PRESS ENTER TO CONTINUE:"); getch(); bmp("temp.bmp",0,0); } } else bmp("temp.bmp",0,0); mousecall(); } } mousepos(cl,x5,y5); if(x5>78 && x5<111 && y5>=42 && y5<=55) //new { if(cl==1) { v=0; main('n'); } } mousepos(cl,x5,y5); if(x5>111 && x5<174 && y5>=42 && y5<=55) //password change { if(cl==1) { hidemouse(); SBMP("temp.bmp"); if(op('p')) { ofstream fout("pass.txt"); char t[20]; for(int m=0;s[m]!='\0';m++) { t[m]=s[m]-27; } t[m]='\0'; fout<<t; fout.close(); } bmp("temp.bmp",0,0); mousecall(); } } mousepos(cl,x5,y5); if(x5>174 && x5<217 && y5>=42 && y5<=55) //help { if(cl==1) { hidemouse(); SBMP("temp.bmp"); help(); bmp("temp.bmp",0,0); mousecall(); } } while(x5>43 && x5<597 && y5>63 && y5<457) { mousepos(cl,x5,y5); mousecall(); if(cl==1 && x5>43 && x5<597 && y5>63 && y5<457 ) { double a,b,p,x1,y1,x2,y2; static int v1=0,v2=0,v3=0,v4=0; double r; switch(tool) { case 0://rectangle mousecall(); x1=x5; y1=y5; delay(500); restrict(43,597,63,457); mousepos(cl,x5,y5); x2=x5,y2=y5; setcolor(c); hidemouse(); rectangle(x1,y1,x2,y2); if(v1!=x1 || v2!=x2 || v3!=y1 || v4!=y2) { fout<<"rectangle("<<x1<<','<<y1<<','<<x2<<','<<y2<<");\n"; v1=x1,v2=x2,v3=y1,v4=y2; } mousecall(); restrict(0,640,0,480); break; case 1:eraser(); break; case 2://line(); mousecall(); x1=x5; y1=y5; delay(500); restrict(43,597,63,457); mousepos(cl,x5,y5); x2=x5,y2=y5; setcolor(c); hidemouse(); line(x1,y1,x2,y2); if(v1!=x1 || v2!=x2 || v3!=y1 || v4!=y2) { fout<<"line("<<x1<<','<<y1<<','<<x2<<','<<y2<<");\n"; v1=x1,v2=x2,v3=y1,v4=y2; } mousecall(); restrict(0,640,0,480); break; case 3://circle(); mousecall(); x1=x5; y1=y5; delay(500); restrict(43,597,63,457); mousepos(cl,x5,y5); x2=x5,y2=y5; a=(x1-x2)*(x1-x2),b=(y1-y2)*(y1-y2); p=a+b; r=SQRT(p); setcolor(c); int c1=x1+r,c2=x1-r,c3=y1+r,c4=y1-r; hidemouse(); circle(x1,y1,r); if(v1!=x1 || v2!=y1) { fout<<"circle("<<x1<<','<<y1<<','<<r<<");\n"; v1=x1,v2=y1; } if(c1>597 || c2<43 || c3>457 || c4<63) SCREEN(); mousecall(); restrict(0,640,0,480); break; case 4:bucket(); break; case 5:brush(x5,y5); break; case 6:fillp(); break; default:brush(x5,y5); } } } }while(1); }
void EraseableStroke::erase(double x, double y, double halfEraserSize, EraseableStrokePart * part, PartList * list) { XOJ_CHECK_TYPE(EraseableStroke); if (part->points->next == NULL) { return; } Point eraser(x, y); Point * a = (Point *) g_list_first(part->points)->data; Point * b = (Point *) g_list_last(part->points)->data; if (eraser.lineLengthTo(*a) < halfEraserSize * 1.2 && eraser.lineLengthTo(*b) < halfEraserSize * 1.2) { list->data = g_list_remove(list->data, part); addRepaintRect(part->getX(), part->getY(), part->getElementWidth(), part->getElementHeight()); delete part; return; } double x1 = x - halfEraserSize; double x2 = x + halfEraserSize; double y1 = y - halfEraserSize; double y2 = y + halfEraserSize; double aX = a->x; double aY = a->y; double bX = b->x; double bY = b->y; // check first point if (aX >= x1 && aY >= y1 && aX <= x2 && aY <= y2) { bool deleteAfter = false; if (erasePart(x, y, halfEraserSize, part, list, &deleteAfter)) { addRepaintRect(part->getX(), part->getY(), part->getElementWidth(), part->getElementHeight()); part->calcSize(); } if(deleteAfter) { delete part; } return; } // check last point if (bX >= x1 && bY >= y1 && bX <= x2 && bY <= y2) { bool deleteAfter = false; if (erasePart(x, y, halfEraserSize, part, list, &deleteAfter)) { addRepaintRect(part->getX(), part->getY(), part->getElementWidth(), part->getElementHeight()); part->calcSize(); } if(deleteAfter) { delete part; } return; } double len = hypot(bX - aX, bY - aY); /** * The normale to a vector, the padding to a point */ double p = ABS((x - aX) * (aY - bY) + (y - aY) * (bX - aX)) / hypot(aX - x, aY - y); // The space to the line is in the range, but it can also be parallel // and not enough close, so calculate a "circle" with the center on the // center of the line if (p <= halfEraserSize) { double centerX = (aX + x) / 2; double centerY = (aY + y) / 2; double distance = hypot(x - centerX, y - centerY); // we should calculate the length of the line within the rectangle, to find out // the distance from the border to the point, but the stroke are not rectangular // so we can do it simpler distance -= hypot((x2 - x1) / 2, (y2 - y1) / 2); if (distance <= (len / 2) + 0.1) { bool deleteAfter = false; if (erasePart(x, y, halfEraserSize, part, list, &deleteAfter)) { addRepaintRect(part->getX(), part->getY(), part->getElementWidth(), part->getElementHeight()); part->calcSize(); } if(deleteAfter) { delete part; } return; } } }