lcdBuffer scrolling

This commit is contained in:
Sebastian 'iggy' Steuer 2011-07-19 02:43:15 +02:00
parent f4dee3550c
commit c65fe4c523
3 changed files with 149 additions and 1 deletions

View File

@ -0,0 +1,54 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/render.h"
#include "lcd/display.h"
#include "lcd/allfonts.h"
void backlightInit(void);
/**************************************************************************/
void main_scroll(void) {
int dx=0;
char key;
backlightInit();
font_direction = FONT_DIR_LTR; // LeftToRight is the default
font=&Font_7x8;
dx=DoString(0,0,"Hello World");
while (1) {
lcdDisplay();
//// delayms(10);
key= getInput();
// Easy flashing
if(key==BTN_ENTER){
DoString(0,8,"Enter ISP!");
lcdDisplay();
ISPandReset();
}
if(key==BTN_RIGHT){
lcdShift(1,0,true);
}
if(key==BTN_LEFT){
lcdShift(-1,0,true);
}
if(key==BTN_UP){
lcdShift(0,1,true);
}
if(key==BTN_DOWN){
lcdShift(0,-1,true);
}
//font = &Font_Ubuntu36pt;
}
return;
}
void tick_scroll(void){
return;
};

View File

@ -158,3 +158,97 @@ inline void lcdInvert(void) {
void lcdToggleFlag(int flag) {
lcd_layout=lcd_layout ^ flag;
}
void lcdShiftH(bool right, bool wrap) {
uint8_t tmp;
for (int yb = 0; yb<RESY_B; yb++) {
if (right) {
tmp = lcdBuffer[yb*RESX];
memmove(lcdBuffer + yb*RESX,lcdBuffer + yb*RESX+1 ,RESX-1);
if (wrap) lcdBuffer[yb*RESX+(RESX-1)] = tmp;
} else {
tmp = lcdBuffer[yb*RESX+(RESX-1)];
memmove(lcdBuffer + yb*RESX+1,lcdBuffer + yb*RESX ,RESX-1);
if (wrap) lcdBuffer[yb*RESX] = tmp;
}
}
}
void lcdShiftV8(bool up, bool wrap) {
uint8_t tmp[RESX];
if (up) {
if (wrap) memmove(tmp, lcdBuffer, RESX);
memmove(lcdBuffer,lcdBuffer+RESX ,RESX*(RESY_B-1));
if (wrap) memmove(lcdBuffer+RESX*(RESY_B-1),tmp,RESX);
} else {
if (wrap) memmove(tmp, lcdBuffer+RESX*(RESY_B-1), RESX);
memmove(lcdBuffer+RESX,lcdBuffer ,RESX*(RESY_B-1));
if (wrap) memmove(lcdBuffer,tmp,RESX);
}
}
void lcdShiftV(bool up, bool wrap) {
uint8_t tmp[RESX];
if (up) {
if (wrap) memmove(tmp,lcdBuffer+((RESY_B-1)*RESX),RESX);
for (int x = 0; x<RESX; x++){
for (int y = RESY_B-1; y > 0; y--){
lcdBuffer[x+(y*RESX)] = (lcdBuffer[x+(y*RESX)] << 1) |( lcdBuffer[x+((y-1)*RESX)] >> 7);
}
if (wrap) lcdBuffer[x] = ( lcdBuffer[x] << 1) | ((tmp[x]>>3)&1);
}
} else {
if (wrap) memmove(tmp,lcdBuffer,RESX);
for (int x = 0; x<RESX; x++){
for (int y = 0; y < (RESY_B-1); y++){
lcdBuffer[x+(y*RESX)] = (lcdBuffer[x+(y*RESX)] >> 1) |( lcdBuffer[x+((y+1)*RESX)] << 7);
}
if (wrap) lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8);
}
}
}
void lcdShift(int x, int y, bool wrap) {
int yb, yr, ya;
bool dir;
if (x>0) {
for (int cx = 0; cx < x; cx++) {
lcdShiftH(true, wrap);
}
} else if (x<0) {
for (int cx = x; cx < 0; cx++) {
lcdShiftH(false, wrap);
}
}
if (y != 0) {
if (y>0) {
ya = y;
yb = y/8;
yr = y%8;
dir = true;
} else if (y<0) {
ya = -y;
yb = (-y)/8;
yr = (-y)%8;
dir = false;
}
//for (int cyb = 0; cyb < yb; cyb++) {
// lcdShiftV8(dir, wrap);
//}
//for (int cyr = 0; cyr < yr; cyr++) {
// lcdShiftV(dir, wrap);
//}
for (int cya = 0; cya < ya; cya++) {
lcdShiftV(dir, wrap);
}
}
}

View File

@ -28,5 +28,5 @@ void lcdToggleFlag(int flag);
void lcdSetPixel(char x, char y, bool f);
void lcdSafeSetPixel(char x, char y, bool f);
bool lcdGetPixel(char x, char y);
void lcdShift(int x, int y, bool wrap);
#endif