tags:

views:

177

answers:

1

I wrote the following, but I'm not understanding it after modifying it some to fit with single pixels (graphic displays) instead of single characters (character displays).

XRES x YRES is the pixel resolution of each character. LCDGraphic draws its own characters based on these values. The idea in this transition algorithm is that you can go right, left, or (both) right one line, left the next line, then right, etc... The text version works like it's supposed to, but when I translated it for graphic displays, it's acting weird.

LCOLS is 256 (the sentinal), and transition_tick_ increments till this sentinel each time LCDGraphic::Transition() is executed. col can thus be in the range between 0-255. Well, when pixels are going left and right, they're supposed to be moving together. However, for some reason the lines going right move till they're finished, then the lines moving left move till they're finished. It appears that where col is < 128 the left moving lines are adjusting, then when col is >= 128 the right moving lines adjust. I'm pretty well confused by this.

void LCDGraphic::Transition() {
    int direction = visitor_->GetDirection();
    int col;
    transitioning_ = true;
    for(unsigned int row = 0; row < LROWS / YRES; row++) {
        if( direction == TRANSITION_LEFT ||
            (direction == TRANSITION_BOTH && row % 2 == 0))
            col = LCOLS - transition_tick_;
        else if( direction == TRANSITION_RIGHT || direction == TRANSITION_BOTH)
            col = transition_tick_;
        else
            col = 0;

        if(col < 0)
            col = 0;

        for(unsigned int i = 0; i < YRES; i++) {
            int n = row * YRES * LCOLS + i * LCOLS;
            for(unsigned int l = 0; l < 1; l++) {// LAYERS; l++) {
                RGBA tmp[LCOLS];
                memcpy(tmp + XRES, GraphicFB[l] + n + col + XRES, (LCOLS - col) * sizeof(RGBA));
                for(unsigned j = 0; j < XRES; j++)
                        tmp[j] = NO_COL;
                memcpy(GraphicFB[l] + n + col, tmp, sizeof(RGBA) * (LCOLS - col));
            }
        }    
    }

    transition_tick_+=XRES;
    if( transition_tick_ >= (int)LCOLS ) {
        transitioning_ = false;
        transition_tick_ = 0;
        emit static_cast<LCDEvents *>(
            visitor_->GetWrapper())->_TransitionFinished();
    }

    GraphicBlit(0, 0, LROWS, LCOLS);
}
+1  A: 

I figured it out. Just half LCOLS. Odd problem though. I'm still a bit confused.

void LCDGraphic::Transition() {
    int direction = visitor_->GetDirection();
    int col;
    transitioning_ = true;
    for(unsigned int row = 0; row < LROWS / YRES; row++) {
        if( direction == TRANSITION_LEFT ||
            (direction == TRANSITION_BOTH && row % 2 == 0))
            col = LCOLS / 2 - transition_tick_; // changed this line
        else if( direction == TRANSITION_RIGHT || direction == TRANSITION_BOTH)
            col = transition_tick_;
        else
            col = 0;

        if(col < 0)
            col = 0;

        for(unsigned int i = 0; i < YRES; i++) {
            int n = row * YRES * LCOLS + i * LCOLS;
            for(unsigned int l = 0; l < 1; l++) {// LAYERS; l++) {
                RGBA tmp[LCOLS];
                LCDError("Transition: LROWS: %u, LCOLS: %u, n: %d, row: %d, col: %d, calc1: %d, calc2: %d, fb: %p, tmp: %p",
                    LROWS, LCOLS, n, row, col, n + col + XRES, (LCOLS - col) * sizeof(RGBA), GraphicFB, tmp);
                memcpy(tmp + XRES, GraphicFB[l] + n + col + XRES, (LCOLS - col) * sizeof(RGBA));
                for(unsigned j = 0; j < XRES; j++)
                        tmp[j] = NO_COL;
                memcpy(GraphicFB[l] + n + col, tmp, sizeof(RGBA) * (LCOLS - col));
            }
        }
    }

    transition_tick_+=XRES;
    if( transition_tick_ >= (int)LCOLS / 2) { //changed this line
        transitioning_ = false;
        transition_tick_ = 0;
        emit static_cast<LCDEvents *>(
            visitor_->GetWrapper())->_TransitionFinished();
    }

    GraphicBlit(0, 0, LROWS, LCOLS);
}
Scott