////////////////////// // PortAudio callback int PortAudioPlayer::paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData) { // Get provider PortAudioPlayer *player = (PortAudioPlayer *) userData; AudioProvider *provider = player->GetProvider(); int end = 0; // Calculate how much left __int64 lenAvailable = player->endPos - player->playPos; uint64_t avail = 0; if (lenAvailable > 0) { avail = lenAvailable; if (avail > framesPerBuffer) { lenAvailable = framesPerBuffer; avail = lenAvailable; } } else { lenAvailable = 0; avail = 0; } // Play something if (lenAvailable > 0) { provider->GetAudio(outputBuffer,player->playPos,lenAvailable); } // Pad end with blank if (avail < (uint64_t) framesPerBuffer) { //provider->softStop = true; } // Set volume short *output = (short*) outputBuffer; for (unsigned int i=0;i<avail;i++) output[i] = MID(-(1<<15),int(output[i] * player->GetVolume()),(1<<15)-1); // Fill rest with blank for (unsigned int i=avail;i<framesPerBuffer;i++) output[i]=0; // Set play position (and real one) player->playPos += framesPerBuffer; player->realPlayPos = (__int64)(Pa_StreamTime(player->stream) - player->paStart) + player->startPos; // Cap to start if lower return end; }
void Tabs::setScrollX(int scroll_x) { int max_x = getMaxScrollX(); scroll_x = MID(0, scroll_x, max_x); if (m_scrollX != scroll_x) { m_scrollX = scroll_x; calculateHot(); invalidate(); } // We need scroll buttons? if (max_x > 0) { // Add childs if (!HAS_ARROWS(this)) { addChild(m_button_left); addChild(m_button_right); invalidate(); } /* disable/enable buttons */ m_button_left->setEnabled(m_scrollX > 0); m_button_right->setEnabled(m_scrollX < max_x); /* setup the position of each button */ { JRect rect = jwidget_get_rect(this); JRect box = jrect_new(rect->x2-ARROW_W*2, rect->y1, rect->x2-ARROW_W, rect->y2-2); jwidget_set_rect(m_button_left, box); jrect_moveto(box, box->x1+ARROW_W, box->y1); jwidget_set_rect(m_button_right, box); jrect_free(box); jrect_free(rect); } } // Remove buttons else if (HAS_ARROWS(this)) { removeChild(m_button_left); removeChild(m_button_right); invalidate(); } }
void Update(int u, int l, int r, int change) { if(f[u].label == change) return ; if(l == f[u].l && r == f[u].r) { f[u].label = change; return ; } if(f[u].label) { put_down(u); } int mid = MID(f[u].l, f[u].r); if(r <= mid) Update(L(u), l, r, change); else if(mid < l) Update(R(u), l, r, change); else { Update(L(u), l, mid, change); Update(R(u), mid+1, r, change); } }
int Query(Tnode* T,int u,int l,int r) { int delta = T[u].delta; if(T[u].l == l && T[u].r == r) return T[u].sum + delta*(r-l); T[L(u)].delta += delta; T[R(u)].delta += delta; T[u].sum += delta*(T[u].r-T[u].l); T[u].delta = 0; int mid = MID(T[u].l,T[u].r); if(l >= mid) return Query(T,R(u),l,r); else if(r <= mid) return Query(T,L(u),l,r); else return Query(T,L(u),l,mid) + Query(T,R(u),mid,r); }
void PasteTextCommand::onExecute(Context* ctx) { Editor* editor = current_editor; if (editor == NULL) return; Preferences& pref = Preferences::instance(); PasteTextWindow window(pref.textTool.fontFace(), pref.textTool.fontSize(), pref.colorBar.fgColor()); window.userText()->setText(last_text_used); window.openWindowInForeground(); if (window.getKiller() != window.ok()) return; last_text_used = window.userText()->getText(); std::string faceName = window.faceValue(); int size = window.sizeValue(); size = MID(1, size, 999); pref.textTool.fontFace(faceName); pref.textTool.fontSize(size); try { std::string text = window.userText()->getText(); app::Color appColor = window.fontColor()->getColor(); doc::color_t color = doc::rgba(appColor.getRed(), appColor.getGreen(), appColor.getBlue(), appColor.getAlpha()); doc::ImageRef image(render_text(faceName, size, text, color)); if (image) { editor->pasteImage(image.get()); } } catch (const std::exception& ex) { ui::Alert::show(PACKAGE "<<%s" "||&OK", ex.what()); } }
Sprite::Sprite(PixelFormat format, int width, int height, int ncolors) : Object(ObjectType::Sprite) , m_document(NULL) , m_format(format) , m_width(width) , m_height(height) , m_frames(1) , m_frameTags(this) { ASSERT(width > 0 && height > 0); m_frlens.push_back(100); // First frame with 100 msecs of duration m_folder = new LayerFolder(this); // Generate palette switch (format) { case IMAGE_GRAYSCALE: ncolors = 256; break; case IMAGE_BITMAP: ncolors = 2; break; } Palette pal(frame_t(0), ncolors); switch (format) { // For black and white images case IMAGE_GRAYSCALE: case IMAGE_BITMAP: for (int c=0; c<ncolors; c++) { int g = 255 * c / (ncolors-1); g = MID(0, g, 255); pal.setEntry(c, rgba(g, g, g, 255)); } break; } // Initial RGB map m_rgbMap = NULL; // The transparent color for indexed images is 0 by default m_transparentColor = 0; setPalette(&pal, true); }
void flash25spi::clearSector(unsigned int addr) { if (_sectorSize == 0) { clearBlock(addr); return; } addr &= ~(_sectorSize-1); enableWrite(); _enable->write(0); wait_us(1); _spi->write(0x20); _spi->write(HIGH(addr)); _spi->write(MID(addr)); _spi->write(LOW(addr)); wait_us(1); _enable->write(1); waitForWrite(); }
/* _xwin_mousedrv_init: * Initializes the mickey-mode driver. */ static int _xwin_mousedrv_init(void) { int num_buttons; unsigned char map[8]; num_buttons = _xwin_get_pointer_mapping(map, sizeof(map)); num_buttons = MID(2, num_buttons, 3); last_xspeed = -1; last_yspeed = -1; XLOCK(); _xwin_mouse_interrupt = _xwin_mousedrv_handler; XUNLOCK(); return num_buttons; }
Sprite::Sprite(PixelFormat format, int width, int height, int ncolors) : Object(OBJECT_SPRITE) , m_format(format) , m_width(width) , m_height(height) , m_frames(1) { ASSERT(width > 0 && height > 0); m_frlens.push_back(100); // First frame with 100 msecs of duration m_stock = new Stock(format); m_folder = new LayerFolder(this); // Generate palette Palette pal(FrameNumber(0), ncolors); switch (format) { // For colored images case IMAGE_RGB: case IMAGE_INDEXED: pal.resize(ncolors); break; // For black and white images case IMAGE_GRAYSCALE: case IMAGE_BITMAP: for (int c=0; c<ncolors; c++) { int g = 255 * c / (ncolors-1); g = MID(0, g, 255); pal.setEntry(c, rgba(g, g, g, 255)); } break; } // Initial RGB map m_rgbMap = NULL; // The transparent color for indexed images is 0 by default m_transparentColor = 0; setPalette(&pal, true); }
/* Dithering with noise shaping filter. Set shape = 0 for no shaping. */ static void sample_dither_filter(float *src, long size, float shape) { float r1 = 0, r2 = 0; float s1 = 0, s2 = 0; /* Feedback buffer */ float o = 0.5f / 255; float tmp; int i; for (i = 0; i < size; i++) { r2 = r1; r1 = rand() / (float)RAND_MAX; tmp = src[i] + shape * (s1 + s1 - s2); src[i] = tmp + o * (r1 - r2); src[i] = MID(-1.0f, src[i], 1.0f); s2 = s1; s1 = tmp - src[i]; } return; }
void layer_render(const Layer* layer, Image* image, int x, int y, FrameNumber frame) { if (!layer->isVisible()) return; switch (layer->type()) { case ObjectType::LayerImage: { const Cel* cel = static_cast<const LayerImage*>(layer)->getCel(frame); Image* src_image; if (cel) { ASSERT((cel->imageIndex() >= 0) && (cel->imageIndex() < layer->sprite()->stock()->size())); src_image = cel->image(); ASSERT(src_image != NULL); ASSERT(src_image->maskColor() == layer->sprite()->transparentColor()); composite_image(image, src_image, cel->x() + x, cel->y() + y, MID(0, cel->opacity(), 255), static_cast<const LayerImage*>(layer)->getBlendMode()); } break; } case ObjectType::LayerFolder: { LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin(); LayerConstIterator end = static_cast<const LayerFolder*>(layer)->getLayerEnd(); for (; it != end; ++it) layer_render(*it, image, x, y, frame); break; } } }
void layer_render(const Layer* layer, Image* image, int x, int y, FrameNumber frame) { if (!layer->isReadable()) return; switch (layer->getType()) { case GFXOBJ_LAYER_IMAGE: { const Cel* cel = static_cast<const LayerImage*>(layer)->getCel(frame); Image* src_image; if (cel) { ASSERT((cel->getImage() >= 0) && (cel->getImage() < layer->getSprite()->getStock()->size())); src_image = layer->getSprite()->getStock()->getImage(cel->getImage()); ASSERT(src_image != NULL); src_image->mask_color = layer->getSprite()->getTransparentColor(); image_merge(image, src_image, cel->getX() + x, cel->getY() + y, MID (0, cel->getOpacity(), 255), static_cast<const LayerImage*>(layer)->getBlendMode()); } break; } case GFXOBJ_LAYER_FOLDER: { LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin(); LayerConstIterator end = static_cast<const LayerFolder*>(layer)->getLayerEnd(); for (; it != end; ++it) layer_render(*it, image, x, y, frame); break; } } }
static void delayed_free(void *uptr, const char* file, int line) { void *mptr; void *olduptr = free_delay[free_delay_pos]; size_t nbytes; if ( uptr==NULL ) return; mptr = user2malloc_(uptr); memory_check(uptr, MID(mptr), MFILE(mptr), MLINE(mptr), file, line); if ( olduptr!=NULL ) { actual_free(olduptr, file, line); } free_delay[free_delay_pos] = uptr; free_delay_pos++; free_delay_pos = free_delay_pos % MAX_FREE_DELAY_COUNT; nbytes = -user_nsize1_(uptr); #ifdef FREED_CHAR (void)memset(uptr, FREED_CHAR, (size_t)nbytes); #endif }
void debug_malloc_verify(const char *file, int line) { void *mptr; #ifdef MAX_FREE_DELAY_COUNT delayed_free_all(file,line); #endif if (!malloc_watch) { return; } mptr = first_warrant_mptr; if (mptr != NULL) { /* Check all this memory first */ do { memory_check(malloc2user_(mptr), MID(mptr), MFILE(mptr), MLINE(mptr), file, line); mptr = warrant_link_(mptr); } while (mptr != NULL); } }
void Updata(Tnode* T,int u,int l,int r,int up) { if(T[u].l == l && T[u].r == r) { T[u].delta += up; return ; } else T[u].sum += up*(r-l); int mid = MID(T[u].l,T[u].r); if(l >= mid) Updata(T,R(u),l,r,up); else if(r <= mid) Updata(T,L(u),l,r,up); else { Updata(T,L(u),l,mid,up); Updata(T,R(u),mid,r,up); } }
int traffic_load(struct request *rq) { int bytes, bw; int gload = 0, iload = 0 ; struct group *group = NULL; ip_hash_entry_t *he = NULL; if ( !rq ) return(0); if ( TEST(rq->flags, RQ_HAS_BANDWIDTH) ) group = rq_to_group(rq); if ( group && (bw = group->bandwidth) ) { bytes = MID(bytes); gload = (bytes*100)/bw; } if ( TEST(rq->flags, RQ_HAVE_PER_IP_BW) ) he = rq->ip_hash_ptr; if ( he && (bw = rq->per_ip_bw) ) { bytes = MID_IP(he); iload = (bytes*100)/bw; } return(MAX(gload,iload)); }
static void actual_free(void *uptr, const char *file, int line) { void *mptr; const char *mfile; int mline; int mid; if ( uptr == NULL ) return; mptr = user2malloc_(uptr); memory_check(uptr, (mid=MID(mptr)), (mfile=MFILE(mptr)), (mline=MLINE(mptr)), file, line); if (malloc_watch && remove_warrant(mptr)==0 ) memory_check(uptr, mid, mfile, mline, file, line); #ifdef FREED_CHAR if ( mptr!=NULL ) { size_t nbytes = -nsize1_(mptr); /* LINTED */ (void)memset(mptr, FREED_CHAR, rbytes_(nbytes)); } #endif free(mptr); }
int Entry::getCaretFromMouse(MouseMessage* mousemsg) { base::utf8_const_iterator utf8_begin = base::utf8_const_iterator(getText().begin()); base::utf8_const_iterator utf8_end = base::utf8_const_iterator(getText().end()); int c, x, w, mx, caret = m_caret; int textlen = base::utf8_length(getText()); mx = mousemsg->position().x; mx = MID(getBounds().x+this->border_width.l, mx, getBounds().x2()-this->border_width.r-1); x = getBounds().x + this->border_width.l; base::utf8_const_iterator utf8_it = (m_scroll < textlen ? utf8_begin + m_scroll: utf8_end); for (c=m_scroll; utf8_it != utf8_end; ++c, ++utf8_it) { w = getFont()->charWidth(*utf8_it); if (x+w >= getBounds().x2()-this->border_width.r) break; if ((mx >= x) && (mx < x+w)) { caret = c; break; } x += w; } if (utf8_it == utf8_end) { if ((mx >= x) && (mx <= getBounds().x2()-this->border_width.r-1)) { caret = c; } } return caret; }
bool flash25spi::writePage(unsigned int startAdr, unsigned int len, const char* data) { enableWrite(); _enable->write(0); wait_us(1); _spi->write(0x02); _spi->write(HIGH(startAdr)); _spi->write(MID(startAdr)); _spi->write(LOW(startAdr)); // do real write for (unsigned int i=0;i<len;i++) { _spi->write(data[i]); } wait_us(1); // disable to start physical write _enable->write(1); waitForWrite(); return true; }
void Kickertest_Add( signed short val) { dbgu_GoToCursor( PARAM_COL, Kickertest_Row); switch( Kickertest_Row) { case BALL_X_ROW: Kickertest_element[KICKERTEST_BALL].x += val; dbgu_printf("%4d ", Kickertest_element[KICKERTEST_BALL].x); break; case BALL_Y_ROW: Kickertest_element[KICKERTEST_BALL].y += val; dbgu_printf("%4d ", Kickertest_element[KICKERTEST_BALL].y); break; case BALL_Z_ROW: Kickertest_element[KICKERTEST_BALL].z += val; dbgu_printf("%4d ", Kickertest_element[KICKERTEST_BALL].z); break; case TARGET_X_ROW: Kickertest_element[KICKERTEST_TARGET].x += val; dbgu_printf("%4d ", Kickertest_element[KICKERTEST_TARGET].x); break; case TARGET_Y_ROW: Kickertest_element[KICKERTEST_TARGET].y += val; dbgu_printf("%4d ", Kickertest_element[KICKERTEST_TARGET].y); break; case TARGET_Z_ROW: Kickertest_element[KICKERTEST_TARGET].z += val; dbgu_printf("%4d ", Kickertest_element[KICKERTEST_TARGET].z); break; case KICKTYPE_ROW: kickertest_type = MID(KICKER_TYPE_MINIMAL, kickertest_type + val, KICKER_TYPE_MAXIMAL); Kickertest_PrintKicktype(); break; case FADE_ENABLE_ROW: kicker_fadeEnable = !kicker_fadeEnable; dbgu_printf("%d ", kicker_fadeEnable); break; } }
void StatusBar::updateFromLayer() { try { const ContextReader reader(UIContext::instance()); const Cel* cel; // Opacity layer if (reader.layer() && reader.layer()->isImage() && !reader.layer()->isBackground() && (cel = reader.cel())) { m_slider->setValue(MID(0, cel->getOpacity(), 255)); m_slider->setEnabled(true); } else { m_slider->setValue(255); m_slider->setEnabled(false); } } catch (LockedDocumentException&) { // Disable all m_slider->setEnabled(false); } }
//////////////////// // Adjust scrollbar void BaseGrid::AdjustScrollbar() { // Variables int w,h,sw,sh; GetClientSize(&w,&h); int drawPerScreen = h/lineHeight; int rows = GetRows(); bool barToEnable = drawPerScreen < rows+2; bool barEnabled = scrollBar->IsEnabled(); // Set yPos yPos = MID(0,yPos,rows - drawPerScreen); // Set size scrollBar->Freeze(); scrollBar->GetSize(&sw,&sh); scrollBar->SetSize(w-sw,0,sw,h); // Set parameters if (barEnabled) { scrollBar->SetScrollbar(yPos,drawPerScreen,rows+2,drawPerScreen-2,true); } if (barToEnable != barEnabled) scrollBar->Enable(barToEnable); scrollBar->Thaw(); }
void ColorButton::openSelectorDialog() { int x, y; if (m_frame == NULL) { m_frame = new ColorSelector(); m_frame->user_data[0] = this; m_frame->ColorChange.connect(&ColorButton::onFrameColorChange, this); } m_frame->setColor(m_color, ColorSelector::ChangeType); m_frame->open_window(); x = MID(0, this->rc->x1, JI_SCREEN_W-jrect_w(m_frame->rc)); if (this->rc->y2 <= JI_SCREEN_H-jrect_h(m_frame->rc)) y = MAX(0, this->rc->y2); else y = MAX(0, this->rc->y1-jrect_h(m_frame->rc)); m_frame->position_window(x, y); jmanager_dispatch_messages(m_frame->getManager()); m_frame->layout(); /* setup the hot-region */ { JRect rc = jrect_new(MIN(this->rc->x1, m_frame->rc->x1)-8, MIN(this->rc->y1, m_frame->rc->y1)-8, MAX(this->rc->x2, m_frame->rc->x2)+8, MAX(this->rc->y2, m_frame->rc->y2)+8); JRegion rgn = jregion_new(rc, 1); jrect_free(rc); static_cast<PopupFrame*>(m_frame)->setHotRegion(rgn); } }
bool flash25spi::read(unsigned int startAdr, unsigned int len, char *data) { // assertion if (startAdr+len>_size) return false; // char* ret=(char*)malloc(len); if (!len) return false; _enable->write(0); wait_us(1); // send address _spi->write(0x03); _spi->write(HIGH(startAdr)); _spi->write(MID(startAdr)); _spi->write(LOW(startAdr)); // read data into buffer for (unsigned int i=0;i<len;i++) { data[i]=_spi->write(0); } wait_us(1); _enable->write(1); return true; }
MID Memory::alloc_dynamic(size_t p_bytes, const char *p_descr) { MemoryPoolDynamic::ID id = MemoryPoolDynamic::get_singleton()->alloc(p_bytes,p_descr); return MID(id); }
void LayerOpacityCommand::onLoadParams(const Params& params) { m_opacity = params.get_as<int>("opacity"); m_opacity = MID(0, m_opacity, 255); }
size_t DfpnSolver::MID(const DfpnBounds& maxBounds, DfpnHistory& history) { maxBounds.CheckConsistency(); SG_ASSERT(maxBounds.phi > 1); SG_ASSERT(maxBounds.delta > 1); ++m_numMIDcalls; size_t prevWork = 0; SgEmptyBlackWhite colorToMove = GetColorToMove(); DfpnData data; if (TTRead(data)) { prevWork = data.m_work; if (! maxBounds.GreaterThan(data.m_bounds)) // Estimated bounds are larger than we had // anticipated. The calling state must have computed // the max bounds with out of date information, so just // return here without doing anything: the caller will // now update to this new info and carry on. return 0; } else { SgEmptyBlackWhite winner = SG_EMPTY; if (TerminalState(colorToMove, winner)) { ++m_numTerminal; DfpnBounds terminal; if (colorToMove == winner) DfpnBounds::SetToWinning(terminal); else { SG_ASSERT(SgOppBW(colorToMove) == winner); DfpnBounds::SetToLosing(terminal); } TTWrite(DfpnData(terminal, SG_NULLMOVE, 1)); return 1; } } ++m_generateMoves; DfpnChildren children; GenerateChildren(children.Children()); // Not thread safe: perhaps move into while loop below later... std::vector<DfpnData> childrenData(children.Size()); for (size_t i = 0; i < children.Size(); ++i) LookupData(childrenData[i], children, i); // Index used for progressive widening size_t maxChildIndex = ComputeMaxChildIndex(childrenData); SgHashCode currentHash = Hash(); SgMove bestMove = SG_NULLMOVE; DfpnBounds currentBounds; size_t localWork = 1; do { UpdateBounds(currentBounds, childrenData, maxChildIndex); if (! maxBounds.GreaterThan(currentBounds)) break; // Select most proving child std::size_t bestIndex = 999999; DfpnBoundType delta2 = DfpnBounds::INFTY; SelectChild(bestIndex, delta2, childrenData, maxChildIndex); bestMove = children.MoveAt(bestIndex); // Compute maximum bound for child const DfpnBounds childBounds(childrenData[bestIndex].m_bounds); DfpnBounds childMaxBounds; childMaxBounds.phi = maxBounds.delta - (currentBounds.delta - childBounds.phi); childMaxBounds.delta = delta2 == DfpnBounds::INFTY ? maxBounds.phi : std::min(maxBounds.phi, std::max(delta2 + 1, DfpnBoundType(delta2 * (1.0 + m_epsilon)))); SG_ASSERT(childMaxBounds.GreaterThan(childBounds)); if (delta2 != DfpnBounds::INFTY) m_deltaIncrease.Add(float(childMaxBounds.delta-childBounds.delta)); // Recurse on best child PlayMove(bestMove); history.Push(bestMove, currentHash); localWork += MID(childMaxBounds, history); history.Pop(); UndoMove(); // Update bounds for best child LookupData(childrenData[bestIndex], children, bestIndex); // Compute some stats when find winning move if (childrenData[bestIndex].m_bounds.IsLosing()) { m_moveOrderingIndex.Add(float(bestIndex)); m_moveOrderingPercent.Add(float(bestIndex) / (float)childrenData.size()); m_totalWastedWork += prevWork + localWork - childrenData[bestIndex].m_work; } else if (childrenData[bestIndex].m_bounds.IsWinning()) maxChildIndex = ComputeMaxChildIndex(childrenData); } while (! CheckAbort()); // Find the most delaying move for losing states, and the smallest // winning move for winning states. if (currentBounds.IsSolved()) { if (currentBounds.IsLosing()) { std::size_t maxWork = 0; for (std::size_t i = 0; i < children.Size(); ++i) { if (childrenData[i].m_work > maxWork) { maxWork = childrenData[i].m_work; bestMove = children.MoveAt(i); } } } else { std::size_t minWork = DfpnBounds::INFTY; for (std::size_t i = 0; i < children.Size(); ++i) { if (childrenData[i].m_bounds.IsLosing() && childrenData[i].m_work < minWork) { minWork = childrenData[i].m_work; bestMove = children.MoveAt(i); } } } } // Store search results TTWrite(DfpnData(currentBounds, bestMove, localWork + prevWork)); return localWork; }
FBCALL void fb_GfxEllipse(void *target, float fx, float fy, float radius, unsigned int color, float aspect, float start, float end, int fill, int flags) { FB_GFXCTX *context; int x, y, x1, y1, top, bottom; unsigned int orig_color; float a, b, orig_x, orig_y, increment; FB_GRAPHICS_LOCK( ); if (!__fb_gfx || radius <= 0.0) { FB_GRAPHICS_UNLOCK( ); return; } context = fb_hGetContext(); orig_x = fx; orig_y = fy; fb_hPrepareTarget(context, target); orig_color = color; if (flags & DEFAULT_COLOR_1) color = context->fg_color; else color = fb_hFixColor(context->target_bpp, color); fb_hSetPixelTransfer(context, color); fb_hFixRelative(context, flags, &fx, &fy, NULL, NULL); fb_hTranslateCoord(context, fx, fy, &x, &y); if (context->flags & CTX_WINDOW_ACTIVE) { /* radius gets multiplied by the VIEW/WINDOW width ratio (aspect is unchanged) */ radius *= (context->view_w / context->win_w); } if (aspect == 0.0) aspect = __fb_gfx->aspect; if (aspect > 1.0) { a = (radius / aspect); b = radius; } else { a = radius; b = (radius * aspect); } if ((start != 0.0) || (end != 3.141593f * 2.0)) { if (start < 0) { start = -start; get_arc_point(start, a, b, &x1, &y1); x1 = orig_x + x1; y1 = orig_y - y1; fb_GfxLine(target, orig_x, orig_y, x1, y1, orig_color, LINE_TYPE_LINE, 0xFFFF, COORD_TYPE_AA | (flags & ~COORD_TYPE_MASK)); } if (end < 0) { end = -end; get_arc_point(end, a, b, &x1, &y1); x1 = orig_x + x1; y1 = orig_y - y1; fb_GfxLine(target, orig_x, orig_y, x1, y1, orig_color, LINE_TYPE_LINE, 0xFFFF, COORD_TYPE_AA | (flags & ~COORD_TYPE_MASK)); } while (end < start) end += 2 * PI; while (end - start > 2 * PI) start += 2 * PI; increment = 1 / (sqrt(a) * sqrt(b) * 1.5); DRIVER_LOCK(); top = bottom = y; for (; start < end + (increment / 2); start += increment) { get_arc_point(start, a, b, &x1, &y1); x1 = x + x1; y1 = y - y1; if ((x1 < context->view_x) || (x1 >= context->view_x + context->view_w) || (y1 < context->view_y) || (y1 >= context->view_y + context->view_h)) continue; context->put_pixel(context, x1, y1, color); if (y1 > bottom) bottom = y1; if (y1 < top) top = y1; } } else { DRIVER_LOCK(); draw_ellipse(context, x, y, a, b, color, fill, &top, &bottom); } top = MID(context->view_y, top, context->view_y + context->view_h - 1); bottom = MID(context->view_y, bottom, context->view_y + context->view_h - 1); if( top > bottom ) SWAP( top, bottom ); SET_DIRTY(context, top, bottom - top + 1); DRIVER_UNLOCK(); FB_GRAPHICS_UNLOCK( ); }
bool Tabs::onProcessMessage(Message* msg) { SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); switch (msg->type) { case JM_REQSIZE: msg->reqsize.w = 0; // msg->reqsize.h = 4 + jwidget_get_text_height(widget) + 5; msg->reqsize.h = theme->get_part(PART_TAB_FILLER)->h + theme->get_part(PART_TAB_BOTTOM_NORMAL)->h; return true; case JM_SETPOS: jrect_copy(this->rc, &msg->setpos.rect); setScrollX(m_scrollX); return true; case JM_DRAW: { BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect), jrect_h(&msg->draw.rect)); JRect rect = jwidget_get_rect(this); jrect_displace(rect, -msg->draw.rect.x1, -msg->draw.rect.y1); JRect box = jrect_new(rect->x1-m_scrollX, rect->y1, rect->x1-m_scrollX+2*jguiscale(), rect->y1+theme->get_part(PART_TAB_FILLER)->h); clear_to_color(doublebuffer, theme->get_window_face_color()); theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, box->x2-1, box->y2-1, PART_TAB_FILLER); theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); box->x1 = box->x2; // For each tab... TabsListIterator it, end = m_list_of_tabs.end(); for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; box->x2 = box->x1 + tab->width; int x_delta = 0; int y_delta = 0; // Y-delta for animating tabs (intros and outros) if (m_ani == ANI_ADDING_TAB && m_selected == tab) { y_delta = (box->y2 - box->y1) * (ANI_ADDING_TAB_TICKS - m_ani_t) / ANI_ADDING_TAB_TICKS; } else if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == tab) { x_delta += m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS)); x_delta = MID(0, x_delta, m_removedTab->width); // Draw deleted tab if (m_removedTab) { JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2); drawTab(doublebuffer, box2, m_removedTab, 0, false); jrect_free(box2); } } box->x1 += x_delta; box->x2 += x_delta; drawTab(doublebuffer, box, tab, y_delta, (tab == m_selected)); box->x1 = box->x2; } if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == NULL) { // Draw deleted tab if (m_removedTab) { int x_delta = m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS)); x_delta = MID(0, x_delta, m_removedTab->width); JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2); drawTab(doublebuffer, box2, m_removedTab, 0, false); jrect_free(box2); box->x1 += x_delta; box->x2 = box->x1; } } /* fill the gap to the right-side */ if (box->x1 < rect->x2) { theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, rect->x2-1, box->y2-1, PART_TAB_FILLER); theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, rect->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); } jrect_free(rect); jrect_free(box); blit(doublebuffer, ji_screen, 0, 0, msg->draw.rect.x1, msg->draw.rect.y1, doublebuffer->w, doublebuffer->h); destroy_bitmap(doublebuffer); return true; } case JM_MOUSEENTER: case JM_MOTION: calculateHot(); return true; case JM_MOUSELEAVE: if (m_hot != NULL) { m_hot = NULL; invalidate(); } return true; case JM_BUTTONPRESSED: if (m_hot != NULL) { if (m_selected != m_hot) { m_selected = m_hot; invalidate(); } if (m_selected && m_delegate) m_delegate->clickTab(this, m_selected->data, msg->mouse.flags); } return true; case JM_WHEEL: { int dx = (jmouse_z(1) - jmouse_z(0)) * jrect_w(this->rc)/6; // setScrollX(m_scrollX+dx); m_begScrollX = m_scrollX; if (m_ani != ANI_SMOOTH_SCROLL) m_endScrollX = m_scrollX + dx; else m_endScrollX += dx; // Limit endScrollX position (to improve animation ending to the correct position) { int max_x = getMaxScrollX(); m_endScrollX = MID(0, m_endScrollX, max_x); } startAni(ANI_SMOOTH_SCROLL); return true; } case JM_TIMER: { switch (m_ani) { case ANI_NONE: // Do nothing break; case ANI_SCROLL: { int dir = (getManager()->getCapture() == m_button_left ? -1: 1); setScrollX(m_scrollX + dir*8*msg->timer.count); break; } case ANI_SMOOTH_SCROLL: { if (m_ani_t == ANI_SMOOTH_SCROLL_TICKS) { stopAni(); setScrollX(m_endScrollX); } else { // Lineal //setScrollX(m_begScrollX + m_endScrollX - m_begScrollX) * m_ani_t / 10); // Exponential setScrollX(m_begScrollX + (m_endScrollX - m_begScrollX) * (1.0-std::exp(-10.0 * m_ani_t / (double)ANI_SMOOTH_SCROLL_TICKS))); } break; } case ANI_ADDING_TAB: { if (m_ani_t == ANI_ADDING_TAB_TICKS) stopAni(); invalidate(); break; } case ANI_REMOVING_TAB: { if (m_ani_t == ANI_REMOVING_TAB_TICKS) stopAni(); invalidate(); break; } } ++m_ani_t; break; } case JM_SIGNAL: if (msg->signal.num == JI_SIGNAL_INIT_THEME) { m_button_left->setBgColor(theme->get_tab_selected_face_color()); m_button_right->setBgColor(theme->get_tab_selected_face_color()); } else if (msg->signal.num == JI_SIGNAL_SET_FONT) { TabsListIterator it, end = m_list_of_tabs.end(); for (it = m_list_of_tabs.begin(); it != end; ++it) { Tab* tab = *it; tab->width = calcTabWidth(tab); } } else if (msg->signal.num == JI_SIGNAL_INIT_THEME) { /* setup the background color */ jwidget_set_bg_color(this, ji_color_face()); } break; } return Widget::onProcessMessage(msg); }
void RenderEngine::renderLayer( const Layer* layer, Image *image, int source_x, int source_y, FrameNumber frame, Zoom zoom, void (*zoomed_func)(Image*, const Image*, const Palette*, int, int, int, int, Zoom), bool render_background, bool render_transparent, int blend_mode) { // we can't read from this layer if (!layer->isVisible()) return; switch (layer->type()) { case ObjectType::LayerImage: { if ((!render_background && layer->isBackground()) || (!render_transparent && !layer->isBackground())) break; const Cel* cel = static_cast<const LayerImage*>(layer)->getCel(frame); if (cel != NULL) { Image* src_image; // Is the 'preview_image' set to be used with this layer? if ((selected_layer == layer) && (selected_frame == frame) && (preview_image != NULL)) { src_image = preview_image; } // If not, we use the original cel-image from the images' stock else { src_image = cel->image(); } if (src_image) { int t, output_opacity; output_opacity = MID(0, cel->opacity(), 255); output_opacity = INT_MULT(output_opacity, global_opacity, t); ASSERT(src_image->maskColor() == m_sprite->transparentColor()); (*zoomed_func)(image, src_image, m_sprite->getPalette(frame), zoom.apply(cel->x()) - source_x, zoom.apply(cel->y()) - source_y, output_opacity, (blend_mode < 0 ? static_cast<const LayerImage*>(layer)->getBlendMode(): blend_mode), zoom); } } break; } case ObjectType::LayerFolder: { LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin(); LayerConstIterator end = static_cast<const LayerFolder*>(layer)->getLayerEnd(); for (; it != end; ++it) { renderLayer(*it, image, source_x, source_y, frame, zoom, zoomed_func, render_background, render_transparent, blend_mode); } break; } } // Draw extras if (m_document->getExtraCel() && layer == m_currentLayer && frame == m_currentFrame) { Cel* extraCel = m_document->getExtraCel(); if (extraCel->opacity() > 0) { Image* extraImage = m_document->getExtraCelImage(); (*zoomed_func)(image, extraImage, m_sprite->getPalette(frame), zoom.apply(extraCel->x()) - source_x, zoom.apply(extraCel->y()) - source_y, extraCel->opacity(), m_document->getExtraCelBlendMode(), zoom); } } }