bool TouchApplication::sendMouseEvent(QObject* receiver, QEvent::Type mevtype, QPoint globalpos, Qt::KeyboardModifiers modifiers) { QPoint localpos = globalpos; if(receiver->isWidgetType()) localpos = static_cast<QWidget*>(receiver)->mapFromGlobal(globalpos); else if(receiver->isWindowType()) localpos = static_cast<QWindow*>(receiver)->mapFromGlobal(globalpos); QMouseEvent* mouseevent = new QMouseEvent(mevtype, localpos, globalpos, mevtype == QEvent::MouseMove ? Qt::NoButton : Qt::LeftButton, mevtype == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton, modifiers); if(mevtype == QEvent::MouseButtonRelease) { // set low priority to ensure release event is processed after any potential events generated by press // another option might be to call processEvents() before postEvent() or notify() for release event postEvent(receiver, mouseevent, Qt::LowEventPriority); // send an offscreen move event with no buttons (i.e., hover) to workaround problems with press-drag-release on menus QPoint offscreen(-10000, -10000); QMouseEvent* ev2 = new QMouseEvent(QEvent::MouseMove, offscreen, offscreen, Qt::NoButton, Qt::NoButton, modifiers); postEvent(receiver, ev2, Qt::LowEventPriority); } else postEvent(receiver, mouseevent); //return QApplication::notify(receiver, &mouseevent); return true; }
void omshowcursor(int x, int y) { if (! offscreen(x,y)) { wmove(Levelw,screenmody(y),screenmodx(x)); wrefresh(Levelw); } }
/* regardless of line of sight, etc, draw a monster */ void plotmon(pmt m) { if (! offscreen(m->x,m->y)) { wmove(Levelw,screenmody(m->y),screenmodx(m->x)); if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(m->monchar)); waddch(Levelw,(m->monchar&0xff)); } }
/* Puts c at x,y on screen. No fuss, no bother. */ void putspot(int x, int y, Symbol c) { if (! offscreen(x,y)) { wmove(Levelw,screenmody(y),screenmodx(x)); if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(c)); waddch(Levelw,(0xff&c)); } }
void plotchar(Symbol pyx, int x, int y) { if (! offscreen(x,y)) { wmove(Levelw,screenmody(y),screenmodx(x)); if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(pyx)); waddch(Levelw,(pyx&0xff)); wrefresh(Levelw); } }
void Clock::Draw(BView *view, int32) { BScreen screen; BBitmap buffer(view->Bounds(), screen.ColorSpace(), true); BView offscreen(view->Bounds(), NULL, 0, 0); buffer.AddChild(&offscreen); buffer.Lock(); int n; float a,R; float width = view->Bounds().Width(); float height = view->Bounds().Height(); float zoom = (height/1024) * 0.85; time(&tmptodaytime); TodayTime = localtime(&tmptodaytime); todaysecond = TodayTime->tm_sec; todayminute = TodayTime->tm_min + (todaysecond/60.0); todayhour = TodayTime->tm_hour + (todayminute/60.0); rgb_color bg_color = {0,0,0}; offscreen.SetHighColor(bg_color); offscreen.SetLowColor(bg_color); offscreen.FillRect(offscreen.Bounds()); offscreen.SetHighColor(200,200,200); for(n=0,a=0,R=510*zoom;n<60;n++,a+=(2*M_PI)/60) { float x = width/2 + R * cos(a); float y = height/2 + R * sin(a); DrawBlock(&offscreen,x,y,a,14*zoom); } offscreen.SetHighColor(255,255,255); for(n=0,a=0,R=500*zoom;n<12;n++,a+=(2*M_PI)/12) { float x = width/2 + R * cos(a); float y = height/2 + R * sin(a); DrawBlock(&offscreen,x,y,a,32*zoom); } offscreen.SetHighColor(255,255,255); DrawArrow(&offscreen, width/2,height/2, ( ((2*M_PI)/60) * todayminute) - (M_PI/2), 220*zoom, 1, 8*zoom); DrawArrow(&offscreen, width/2,height/2, ( ((2*M_PI)/12) * todayhour) - (M_PI/2), 140*zoom, 1, 14*zoom); offscreen.FillEllipse(BPoint(width/2,height/2),24*zoom,24*zoom); offscreen.SetHighColor(250,20,20); DrawArrow(&offscreen, width/2,height/2, ( ((2*M_PI)/60) * todaysecond) - (M_PI/2), 240*zoom, 1, 4*zoom); offscreen.FillEllipse(BPoint(width/2,height/2),20*zoom,20*zoom); offscreen.Sync(); buffer.Unlock(); view->DrawBitmap(&buffer); buffer.RemoveChild(&offscreen); }
void screencheck(int x, int y) { int change = 0; #ifdef CENTER_ON_PLAYER change = 1; ScreenOffset = y - (ScreenLength/2); ScreenXOffset = x - (ScreenWidth/2); #else #if 0 int width = 0; #endif if (((y-ScreenOffset) < (ScreenLength/8)) || ((y-ScreenOffset) > (7*ScreenLength/8))) { change = 1; ScreenOffset = y - (ScreenLength/2); } if (((x-ScreenXOffset) < (ScreenWidth/8)) || ((x-ScreenXOffset) > (7*ScreenWidth/8))) { #if 0 if ( Current_Environment == E_COUNTRYSIDE ) width = COUNTRY_WIDTH; else width = Level->level_width; /* PGM: this code prevents scrolling when near the right edge of the level, but this unfortunately results in a badly placed view when, for examples, restoring a save near the edge of a level. Ideas on fixing this, or moving it, appreciated. PGM July 1999. */ if ( ( (x-ScreenXOffset) + (7*ScreenWidth/8) ) < width +( ScreenWidth/8 ) ) #endif { change = 1; ScreenXOffset = x - (ScreenWidth/2); if (ScreenXOffset < 0) ScreenXOffset = 0; } } #endif if ( change == 1 ) { show_screen(); if (Current_Environment != E_COUNTRYSIDE) drawmonsters(TRUE); if (!offscreen(Player.x,Player.y)) drawplayer(); } }
/* blank out a spot regardless */ void blotspot(int i, int j) { if (inbounds(i,j)) { lreset(i,j,SEEN); Level->site[i][j].showchar = SPACE; if (! offscreen(i,j)) { wmove(Levelw,screenmody(j),screenmodx(i)); wattrset(Levelw, CHARATTR(SPACE)); waddch(Levelw, SPACE&0xff); } } }
void screencheck(int y) { if (((y-ScreenOffset) < (ScreenLength/8)) || ((y-ScreenOffset) > (7*ScreenLength/8))) { ScreenOffset = y - (ScreenLength/2); show_screen(); if (Current_Environment != E_COUNTRYSIDE) drawmonsters(TRUE); if (!offscreen(Player.x,Player.y)) drawplayer(); } }
//Update function for a projectile. void proj_update(SPP sp, int i) { if (((PROJP)sp->pool[i])->dead || offscreen(sp->pool[i])) { ((PROJP)sp->pool[i])->dead = 0; kill_item(sp, i); } PROJP tmp = sp->pool[i]; update_proj_position(tmp); tmp->animFrame++; tmp->animFrame %= 60; }
void drawplayer(void) { int c; if (E_COUNTRYSIDE == Current_Environment) { if (inbounds(lastx, lasty) && !offscreen(lastx, lasty)) { wmove(Levelw, screenmody(lasty), screenmodx(lastx)); c = Country[lastx][lasty].current_terrain_type; if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(c)); waddch(Levelw, c & 0xff); } wmove(Levelw, screenmody(Player.y), screenmodx(Player.x)); if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(PLAYER)); waddch(Levelw, PLAYER & 0xff); } else { if (inbounds(lastx, lasty) && !offscreen(lastx, lasty)) plotspot(lastx, lasty, (Player.status[BLINDED] > 0 ? FALSE : TRUE)); wmove(Levelw, screenmody(Player.y), screenmodx(Player.x)); if ((!Player.status[INVISIBLE]) || Player.status[TRUESIGHT]) { if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(PLAYER)); waddch(Levelw, PLAYER & 0xff); } } lastx = Player.x; lasty = Player.y; }
void drawvision(int x, int y) { static int oldx = -1,oldy = -1; int i,j,c; if (Current_Environment != E_COUNTRYSIDE) { if (Player.status[BLINDED]) { drawspot(oldx,oldy); drawspot(x,y); drawplayer(); } else { if (Player.status[ILLUMINATION] > 0) { for (i= -2;i<3;i++) for (j= -2;j<3;j++) if (inbounds(x+i,y+j)) if (view_los_p(x+i,y+j,Player.x,Player.y)) dodrawspot(x+i,y+j); } else { for (i= -1;i<2;i++) for (j= -1;j<2;j++) if (inbounds(x+i,y+j)) dodrawspot(x+i,y+j); } drawplayer(); drawmonsters(FALSE); /* erase all monsters */ drawmonsters(TRUE); /* draw those now visible */ } if ((! gamestatusp(FAST_MOVE)) || (! optionp(JUMPMOVE))) omshowcursor(Player.x,Player.y); oldx = x; oldy = y; } else { for (i= -1;i<2;i++) for (j= -1;j<2;j++) if (inbounds(x+i,y+j)) { c_set(x+i, y+j, SEEN); if (!offscreen(x+i,y+j)) { wmove(Levelw,screenmody(y+j),screenmodx(x+i)); c = Country[x+i][y+j].current_terrain_type; if (optionp(SHOW_COLOUR)) wattrset(Levelw, CHARATTR(c)); waddch(Levelw,(c&0xff)); } } drawplayer(); omshowcursor(Player.x,Player.y); } }
void draw(SkCanvas* canvas) { SkBitmap bitmap; bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); { SkCanvas offscreen(bitmap); SkPaint paint; SkFont font(nullptr, 100); offscreen.drawString("ABC", 20, 160, font, paint); SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); offscreen.saveLayerAlpha(&layerBounds, 128); offscreen.clear(SK_ColorWHITE); offscreen.drawString("DEF", 20, 160, font, paint); } canvas->drawBitmap(bitmap, 0, 0, nullptr); }
void DesktopWidget::paintEvent( QPaintEvent * ) { QColor c1 = backgroundColor(); QColor c2 = c1.light(104); QColor c3 = c1.dark(106); if ( !pm ) { pm = new QPixmap( 64, 64 ); generateStone( pm, c1, c2, c3 ); setBackgroundPixmap( *pm ); update(); } QRect br = fontMetrics().boundingRect( text ); QPixmap offscreen( br.width(), br.height() ); int x = width()/2 - br.width()/2; int y = height()/2 - br.height()/2; offscreen.fill( this, x, y ); QPainter p; p.begin( &offscreen ); drawShadeText( &p, -br.x(), -br.y(), text, c2, c3, 3 ); p.end(); bitBlt( this, x, y, &offscreen ); }
void FormGadget::drawProxy() { if (!visible()) return; if (form()->application().runningOnTreo600() && hasFocus()) drawFocusRing(); Graphics graphics(WinGetDrawWindow()); // form()->windowHandle() Rect rect; bounds(rect); bool db=doubleBuffer_; if (db) { Rect formBounds; form()->bounds(formBounds); Err error; WinHandle wh = WinCreateOffscreenWindow(formBounds.width(), formBounds.height(), nativeFormat, &error); if (errNone == error) { { Graphics offscreen(wh); ActivateGraphics active(offscreen); handleDraw(graphics); offscreen.copyArea(rect, graphics, rect.topLeft()); } WinDeleteWindow(wh, false); } else db=false; } if (!db) { Graphics::ClipRectangleSetter setClip(graphics, rect); handleDraw(graphics); } fireDrawCompleted(); }
void draw(SkCanvas* canvas) { canvas->scale(16, 16); SkBitmap bitmap; SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType); bitmap.allocPixels(imageInfo); SkCanvas offscreen(bitmap); offscreen.clear(SK_ColorGREEN); canvas->drawBitmap(bitmap, 0, 0); auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t { return (b << 0) | (g << 5) | (r << 11); }; uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00), pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) }; uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17), pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) }; SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes()); if (bitmap.writePixels(redPixmap, 0, 0)) { canvas->drawBitmap(bitmap, 2, 2); } SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes()); if (bitmap.writePixels(bluePixmap, 0, 0)) { canvas->drawBitmap(bitmap, 4, 4); } }
void FliPlayer::copyCurrentFrameToScreen() { g_Screen.scale2x(0, 0, fli_info_.width, fli_info_.height, offscreen(), 0, false); }
void Message::Draw(BView *view, int32 frame) { if (view == NULL || view->Window() == NULL || !view->Window()->IsLocked()) return; BScreen screen(view->Window()); if (!screen.IsValid()) return; // Double-buffered drawing BBitmap buffer(view->Bounds(), screen.ColorSpace(), true); if (buffer.InitCheck() != B_OK) return; BView offscreen(view->Bounds(), NULL, 0, 0); buffer.AddChild(&offscreen); buffer.Lock(); // Set up the colors rgb_color base_color = {(uint8)(rand() % 25), (uint8)(rand() % 25), (uint8)(rand() % 25)}; offscreen.SetHighColor(base_color); offscreen.SetLowColor(tint_color(base_color, 0.815F)); offscreen.FillRect(offscreen.Bounds(), kCheckered); rgb_color colors[8] = { tint_color(base_color, B_LIGHTEN_1_TINT), tint_color(base_color, 0.795F), tint_color(base_color, 0.851F), tint_color(base_color, 0.926F), tint_color(base_color, 1.05F), tint_color(base_color, B_DARKEN_1_TINT), tint_color(base_color, B_DARKEN_2_TINT), tint_color(base_color, B_DARKEN_3_TINT), }; offscreen.SetDrawingMode(B_OP_OVER); // Set the basic font parameters, including random font family BFont font; offscreen.GetFont(&font); font.SetFace(B_BOLD_FACE); font.SetFamilyAndStyle(*(fFontFamilies.ItemAt(rand() % fFontFamilies.CountItems())), NULL); offscreen.SetFont(&font); // Get the message BString *message = get_message(); BString *origMessage = new BString(); message->CopyInto(*origMessage, 0, message->Length()); // Replace newlines and tabs with spaces message->ReplaceSet("\n\t", ' '); int height = (int) offscreen.Bounds().Height(); int width = (int) offscreen.Bounds().Width(); // From 14 to 22 iterations int32 iterations = (rand() % 8) + 14; for (int32 i = 0; i < iterations; i++) { // Randomly set font size and shear BFont font; offscreen.GetFont(&font); float fontSize = ((rand() % 320) + 42) * fScaleFactor; font.SetSize(fontSize); // Set the shear off 90 about 1/2 of the time if (rand() % 2 == 1) font.SetShear((float) ((rand() % 135) + (rand() % 45))); else font.SetShear(90.0); offscreen.SetFont(&font); // Randomly set drawing location int x = (rand() % width) - (rand() % width/((rand() % 8)+1)); int y = rand() % height; // Draw new text offscreen.SetHighColor(colors[rand() % 8]); int strLength = message->Length(); // See how wide this string is with the current font float strWidth = offscreen.StringWidth(message->String()); int drawingLength = (int) (strLength * (width / strWidth)); int start = 0; if (drawingLength >= strLength) drawingLength = strLength; else start = rand() % (strLength - drawingLength); char *toDraw = new char[drawingLength+1]; strncpy(toDraw, message->String()+start, drawingLength); toDraw[drawingLength] = 0; offscreen.DrawString(toDraw, BPoint(x, y)); delete[] toDraw; } // Now draw the full message in a nice translucent box, but only // if this isn't preview mode if (!fPreview) { BFont font(be_fixed_font); font.SetSize(14.0); offscreen.SetFont(&font); font_height fontHeight; font.GetHeight(&fontHeight); float lineHeight = fontHeight.ascent + fontHeight.descent + fontHeight.leading; BStringList lines; int longestLine = 0; int32 count = get_lines(origMessage, lines, &longestLine); float stringWidth = font.StringWidth(lines.StringAt(longestLine).String()); BRect box(0, 0, stringWidth + 20, (lineHeight * count) + 20); box.OffsetTo((width - box.Width()) / 2, height - box.Height() - 40); offscreen.SetDrawingMode(B_OP_ALPHA); base_color.alpha = 128; offscreen.SetHighColor(base_color); offscreen.FillRoundRect(box, 8, 8); offscreen.SetHighColor(205, 205, 205); BPoint start = box.LeftTop(); start.x += 10; start.y += 10 + fontHeight.ascent + fontHeight.leading; for (int i = 0; i < count; i++) { offscreen.DrawString(lines.StringAt(i).String(), start); start.y += lineHeight; } } delete origMessage; delete message; offscreen.Sync(); buffer.Unlock(); view->DrawBitmap(&buffer); buffer.RemoveChild(&offscreen); }