/* dx = in columns, dy = in lines */ void scroll_window(int dx, int dy) { Graphics *g; Rect r; Point p; /* a negative value scrolls up */ assert(lines != NULL); if (dy < 0) { assert(-dy < NUM_LINES); memmove(lines,lines-dy*NUM_COLUMNS,(NUM_LINES+dy)*NUM_COLUMNS*sizeof(TCHAR)); memset(lines+(NUM_LINES+dy)*NUM_COLUMNS*sizeof(TCHAR), __T(' '), -dy*NUM_COLUMNS); } else if (dy > 0) { assert(dy < NUM_LINES); memmove(lines+dy*NUM_COLUMNS,lines,(NUM_LINES-dy)*NUM_COLUMNS*sizeof(TCHAR)); memset(lines, __T(' '), dy*NUM_COLUMNS); } /* if */ csry += dy; if (csry < 0) csry = 0; if (csry >= NUM_LINES) csry=NUM_LINES - 1; assert(font != NULL); dx *= font_width(font, "x", 1); dy *= font_height(font); g = get_window_graphics(win); r = get_window_area(win); p = pt(r.x + dx, r.y + dy); copy_rect(g, p, g, r); if (dy > 0) { /* moving window contents downwards */ redraw_rect(win, rect(0,0,r.width,dy)); } else if (dy < 0) { /* moving window contents upwards */ redraw_rect(win, rect(0,r.height+dy,r.width,0-dy)); } /* if */ if (dx > 0) { /* moving window contents to the right */ redraw_rect(win, rect(0,0,dx,r.height)); } else if (dx < 0) { /* moving window contents to the left */ redraw_rect(win, rect(r.width+dx,0,0-dx,r.height)); } /* if */ del_graphics(g); }
static void refresh_screen(int top, int bottom) { Rect r; int h; if (top != bottom) { assert(win != NULL); r = get_window_area(win); assert(font != NULL); h = font_height(font); redraw_rect(win, rect(0, top * h, r.width, (bottom - top) * h)); } /* if */ //??? set to draw a caret }
void t_pgrid::run() { bool quit= false; setvbuf(stdout, 0, _IONBF, 0); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_WM_SetCaption("pgrid", "pgrid"); lastmillis= curmillis= SDL_GetTicks(); SDL_ShowCursor(0); SDL_EnableUNICODE(true); gui= new flux_gui(); bool guimouse= false; while(!quit) { lastframephystime= physicstime; lastmillis= curmillis; curmillis= SDL_GetTicks(); SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: case SDL_KEYUP: { if(event.key.keysym.sym==SDLK_ESCAPE) quit= true; if(wnd_getkbdfocus()!=NOWND) { flux_keyboard_event(event.type==SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.unicode&0x7F); } else { current_workspace()->keyboard_event(event.key); editor->keyboard_event(event.key); for(t_dyninputhandler_list::iterator i= dyninputhandlers.begin(); i!=dyninputhandlers.end(); i++) (*i)->keyboard_event(event.key); } keystate[event.key.keysym.sym]= (event.key.state==SDL_PRESSED? 1: 0); break; } case SDL_MOUSEMOTION: flux_mouse_move_event(event.motion.xrel, event.motion.yrel); if( find_prim_pos(event.motion.x, event.motion.y, true) || find_mouse_handler(event.motion.x, event.motion.y) ) guimouse= true; else { guimouse= false; mouse.x= event.motion.x; mouse.y= event.motion.y; mouse.buttons= event.motion.state; current_workspace()->mouse_motion_event(event.motion); editor->mouse_motion_event(event.motion); for(t_dyninputhandler_list::iterator i= dyninputhandlers.begin(); i!=dyninputhandlers.end(); i++) (*i)->mouse_motion_event(event.motion); } break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: { int b= event.button.button; int fluxbutton= (b==SDL_BUTTON_RIGHT? 2: b==SDL_BUTTON_MIDDLE? 3: b)-1; flux_mouse_button_event(fluxbutton, event.type==SDL_MOUSEBUTTONDOWN); if( find_prim_pos(event.button.x, event.button.y, true) || find_mouse_handler(event.button.x, event.button.y) ) { guimouse= true; } else { guimouse= false; wnd_setkbdfocus(NOWND); if(event.type==SDL_MOUSEBUTTONUP) mouse.buttons&= ~(SDL_BUTTON(event.button.button)); else mouse.buttons|= SDL_BUTTON(event.button.button); mouse.x= event.button.x; mouse.y= event.button.y; current_workspace()->mouse_button_event(event.button); editor->mouse_button_event(event.button); for(t_dyninputhandler_list::iterator i= dyninputhandlers.begin(); i!=dyninputhandlers.end(); i++) (*i)->mouse_button_event(event.button); } break; } case SDL_QUIT: quit= true; break; case SDL_VIDEORESIZE: { SDL_Surface *surf= SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_OPENGL|SDL_RESIZABLE); if(!surf) break; screen.sdl_surface= surf; screen.gl_init(event.resize.w, event.resize.h); current_workspace()->centerimage(); break; } case SDL_ACTIVEEVENT: { if(event.active.state&SDL_APPINPUTFOCUS) { hasinputfocus= event.active.gain; SDL_ShowCursor(!hasinputfocus); } if(event.active.state&SDL_APPMOUSEFOCUS) hasmousefocus= event.active.gain; break; } case SDL_VIDEOEXPOSE: { if(!hasinputfocus) { glClear(GL_DEPTH_BUFFER_BIT); current_workspace()->render(); SDL_GL_SwapBuffers(); checkglerror(); } break; } } } int x, y; SDL_GetMouseState(&x, &y); mousepos.x= x; mousepos.y= y; SDL_GetRelativeMouseState(&x, &y); mousevel.x= x; mousevel.y= y; mousevel.mul( 1000.0/(curmillis-lastmillis) ); current_workspace()->image->frame_tick((curmillis-lastmillis)*0.001); runphysics(); if(hasinputfocus) { glClear(GL_DEPTH_BUFFER_BIT); //~ screen.setperspective(); current_workspace()->render(); if(hasmousefocus && !guimouse) editor->render(); #if 1 next_event(); //~ aq_exec(); run_timers(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, screen.width,screen.height, 0, -1000, 1000); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //~ glEnable(GL_POINT_SMOOTH); //~ glPointSize(1.0); //~ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //~ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glColor3f(1,1,1); glDisable(GL_TEXTURE_2D); redraw_rect(&viewport); //~ cliptext(0,0,0,0); update_rect(&viewport); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); #endif gui->tick( (curmillis-lastmillis)*0.001 ); if(guimouse) { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glDisable(GL_DEPTH_TEST); redraw_cursor(); } SDL_GL_SwapBuffers(); checkglerror(); } int delay= 10 - (curmillis-lastmillis); if(!hasinputfocus) SDL_Delay(100); if(delay>0) SDL_Delay(delay); } SDL_WM_GrabInput(SDL_GRAB_OFF); delete gui; gui= 0; }
int main(void) { touchPosition touch; videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text vramSetBankC(VRAM_C_SUB_BG); SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31); //by default font will be rendered with color 255 //consoleInit() is a lot more fluxible but this gets you up and running quick consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); ///////////// powerON(POWER_ALL); // set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); vramSetBankA(VRAM_A_TEXTURE); // irqs are nice irqInit(); irqEnable(IRQ_VBLANK); // initialize gl glInit(); // setup the rear plane glClearColor(2, 4, 3, 16); glClearDepth(GL_MAX_DEPTH); // this should work the same as the normal gl call glViewPort(0,0, 255,191); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //~ glOrtho(0, 1, 192.0/256.0, 0, -10, 10); glOrthof32(0, 1<<12, (192<<12)/256, 0, -10<<12, 10<<12); REG_POWERCNT^= POWER_SWAP_LCDS; ///////////// flux_init(); create_frame_groups(); create_button_groups(); create_titleframe(); dmaCopy(fluxcolors, syscol_table, sizeof(fluxcolors)); dword rc1= create_rect(NOPARENT, 20,20, 128,96, 0x808080); dword rc= create_rect(NOPARENT, 10,10, 128,96, 0x404040|TRANSL_3); dword frm= clone_frame("titleframe", rc); clone_frame("titleframe", rc1); //~ clone_group("button", rc, 10,30, 30,14, ALIGN_LEFT|ALIGN_TOP); create_rect(rc, 10,10, 10,10, 0xFFFFFF|TRANSL_1); create_rect(rc, 20,10, 10,10, 0xFFFFFF|TRANSL_2); create_rect(rc, 30,10, 10,10, 0xFFFFFF|TRANSL_3); create_rect(rc, 10,15, 30,10, 0xFFFFFF|TRANSL_1); create_text(rc, 10,30, 40,40, "Text! Space!\nNewline!", 0xFFFFFF, FONT_DEFAULT); bool redraw_all= true; bool touch_wasdown= false; int lasttouch_x, lasttouch_y; while(1) { scanKeys(); u32 keysheld= keysHeld(); u32 keysdown= keysDown(); touch= touchReadXY(); if(keysdown&KEY_A) { redraw_all^= 1; iprintf("redraw each frame: %s\n", redraw_all? "on": "off"); } if(keysdown&KEY_B) { do_texalpha^= 1; iprintf("texture alpha: %s\n", do_texalpha? "on": "off"); } if(touch.x || touch.y) { flux_mouse_event(touch.px, touch.py, 1); lasttouch_x= touch.px, lasttouch_y= touch.py; touch_wasdown= true; } else { if(touch_wasdown) flux_mouse_event(lasttouch_x, lasttouch_y, 0); touch_wasdown= false; } flux_tick(); if(redraw_all) { redraw_rect(&viewport); update_rect(&viewport); } swiWaitForVBlank(); } return 0; }
void widget::redraw(const rectangle& rect, drawable* source, bool transform) { // FIXME: what is the benefit of copying the rectangle? rectangle redraw_rect(rect); parent_.lock()->redraw(redraw_rect, this, true); }