static void redraw_line(void){ cursor_shift(-cursor); render(stderr, line->buf, display_utf8_of_rune); cursor += display_width(line, 0, line->buf->c); erase_line(); cursor_shift(-display_width(line, line->off, line->buf->c)); }
void ticTacToeDisplay_gameOver() { display_init(); // Must init all of the software and underlying hardware for LCD. display_fillScreen(DISPLAY_BLACK); // Blank the screen. display_setRotation(true); ticTacToeDisplay_drawX(TICTACTOE_DISP_ROW_0,TICTACTOE_DISP_COLUMN_0); ticTacToeDisplay_drawX(TICTACTOE_DISP_ROW_0,TICTACTOE_DISP_COLUMN_2); display_drawFastHLine(display_width()/3, display_height()/2, display_width()/3, DISPLAY_CYAN); display_setCursor(TICTACTOE_DISP_COLUMN_1_PT,TICTACTOE_DISP_ROW_2_PT); display_println("Game Over"); }
static void real_pos(const editor_t *editor, vector_size_t *x, text_line_size_t *y) { *x = 1; for (vector_size_t i = editor->allow_edit_begin; i < editor->current_line; ++i) { if (contains_newline(editor_line(editor, i))) ++*x; } *y = editor->screen_pos + 1; if (editor->current_line) { for (vector_size_t i = editor->current_line - 1; i >= editor->allow_edit_begin;) { const text_line_t *tl = editor_line(editor, i); if (contains_newline(tl)) break; else *y += display_width(tl->buf, tl->size); if (i) --i; else break; } } }
void init() { heightfield hf; heightfieldinfo hfi; skybox sb; object3d plan = create_plan_xy(100, 100, 1, 1); material mat = material_create(NULL, 0, &color_red, 0, 0); matrix4 tmp; vector3 cam_pos = {0,50,0}; vector3 cam_up = {0,1,0}; vector3 cam_look = {0,50,-1}; viewport vp = viewport_create(0, 0, display_width(screen), display_height(screen)); /* Camera */ camfps = camera_create(60, ZFAR, ZNEAR, &cam_pos, &cam_look, &cam_up, vp); /* Heightfied creation */ hf = heightfield_create_from_file("data/height.png", 1000, 1000, 100); heightfield_set_textures_from_file(hf, "data/land.jpg", "data/detail.jpg"); heightfield_set_detail_scale(hf, 50, 50); matrix4_to_rot_x(tmp, -90); heightfield_set_world_matrix(hf, tmp); /* Heightfield infos*/ hfi = heightfieldinfo_create("data/land.jpg", hf, camfps, screen, 250, 250); /* Skybox */ sb = skybox_create(camfps, "data/left.jpg", "data/right.jpg", "data/front.jpg", "data/back.jpg", "data/top.jpg", "data/bottom.jpg", 10); /* Test plane */ object3d_set_material(plan, mat); /* Populate the scene */ scn = scene_create(); scene_set_camera(scn, camfps); scene_set_display(scn, screen); scene_add_object(scn, sb, (void *)skybox_to_opengl, NULL); scene_add_object(scn, hf, (void *)heightfield_to_opengl, NULL); scene_add_object(scn, plan, (void *)object3d_to_opengl, NULL); scene_add_object2d(scn, hfi, (void *)heightfieldinfo_to_opengl, NULL); fontgl_init(); font = fontgl_create("data/vera.ttf", 800, 600, 16); fontgl_set_color(font, 1,0,0); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); SDL_WarpMouse(CENTERX,CENTERY); SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(SDL_DISABLE); }
heightfieldinfo heightfieldinfo_create(char *landmap, heightfield hf, camera cam, display disp, float sizex, float sizey) { matrix4 world; heightfieldinfo hfi = malloc(sizeof(struct heightfieldinfo)); matrix4_to_translate(world, display_width(disp)-sizex, display_height(disp)-sizey, 0); object2d_init(SF_OBJECT2D(hfi), sizex, sizey, world, material_create_single_texture_from_file(landmap)); hfi->cam = cam; hfi->hf = hf; return hfi; }
void buttons_runTest() { buttons_init(); // Initialize buttons display_init(); // Initialize display, which sets Rotation = 1 by default display_fillScreen(DISPLAY_BLACK); // blank the screen display_setTextColor(DISPLAY_BLACK); // Change text color to black display_setTextSize(BUTTONS_TEXT_SIZE); // Make text larger // Set the values of the global variables x_max = display_width(); y_max = display_height(); // Set the values of screen positions x_fourth = FOURTH(x_max); x_half = HALF(x_max); x_three_fourths = THREE_FOURTHS(x_max); y_fourth = FOURTH(y_max); y_half = HALF(y_max); y_three_fourths = THREE_FOURTHS(y_max); // Do an initial read of button values int32_t buttonValues = buttons_read(); // Until all 4 BTNS are pressed simultaneously, write info to the LCD while (buttonValues != BUTTONS_ALL_BTNS_ON) { // Draw the Rects/Text on the LCD corresponding to current buttons buttons_write_LCD(buttonValues); // Poll new value of buttons buttonValues = buttons_read(); } // After all buttons are pushed simultaneously, finish test. display_fillScreen(DISPLAY_BLACK); // blank screen display_setTextColor(DISPLAY_CYAN); // change text color display_setCursor(0,0); // reset cursor to origin display_println("Button Test Finished!"); // print that the test is complete }
static void scene2d_to_opengl(scene scn) { if(scn->disp == NULL) return; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, display_width(scn->disp), display_height(scn->disp), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); /* Not needed, here only for experimenting frustum*/ glLoadIdentity(); slist_to_opengl(scn->render2d_list); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
int8_t simonDisplay_computeRegionNumber(int16_t x, int16_t y) { // Set the values of the sub box dimensions uint16_t x_max = display_width(); uint16_t y_max = display_height(); uint16_t box_width = GLOBALS_ONE_HALF(x_max); uint16_t box_height = GLOBALS_ONE_HALF(y_max); // Error condition for values off the screen if (x < 0 || y < 0 || x > x_max || y > y_max) { return SIMON_DISPLAY_ERROR; // Invalid touch data } // Parse through top row if (y < box_height) { // Check Region 0 if (x < box_width) { return SIMON_DISPLAY_REGION_0; } // Check Region 1 else { return SIMON_DISPLAY_REGION_1; } } // Parse through bottom row else { // Check Region 2 if (x < box_width) { return SIMON_DISPLAY_REGION_2; } // Check Region 3 else { return SIMON_DISPLAY_REGION_3; } } }
void simonDisplay_drawButton(uint8_t regionNumber) { // Set the values of the sub box dimensions uint16_t x_max = display_width(); uint16_t y_max = display_height(); // Compute dimensions of the 4 sub regions uint16_t box_width = GLOBALS_ONE_HALF(x_max); uint16_t box_height = GLOBALS_ONE_HALF(y_max); // Compute dimensions of half the button sizes for convenience in drawing uint16_t button_half_width = GLOBALS_ONE_HALF(SIMON_DISPLAY_BUTTON_WIDTH); uint16_t button_half_height = GLOBALS_ONE_HALF(SIMON_DISPLAY_BUTTON_HEIGHT); // Variables to be used in computing the centerpoint of each subregion uint16_t origin_x, origin_y; // The dimensions of the button is define by the header file switch (regionNumber) { case SIMON_DISPLAY_REGION_0: // Compute the origin point of the box origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height; // Draw the RED square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_RED // color ); break; case SIMON_DISPLAY_REGION_1: // Compute the origin point of the box origin_x = box_width; origin_y = 0; origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width + origin_x; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height + origin_y; // Draw the YELLOW square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_YELLOW // color ); break; case SIMON_DISPLAY_REGION_2: // Compute the origin point of the box origin_x = 0; origin_y = box_height; origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width + origin_x; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height + origin_y; // Draw the BLUE square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_BLUE // color ); break; case SIMON_DISPLAY_REGION_3: // Compute the origin point of the box origin_x = box_width; origin_y = box_height; origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width + origin_x; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height + origin_y; // Draw the GREEN square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_GREEN // color ); break; default: printf("Draw button default case hit\n"); // shouldn't hit this break; } }
void simonDisplay_drawSquare(uint8_t regionNo, bool erase) { // Set the values of the sub box dimensions uint16_t x_max = display_width(); uint16_t y_max = display_height(); // Compute dimensions of the 4 sub regions uint16_t box_width = GLOBALS_ONE_HALF(x_max); uint16_t box_height = GLOBALS_ONE_HALF(y_max); // Variables to be used in computing the centerpoint of each subregion uint16_t origin_x, origin_y; // The dimensions of the button is define by the header file switch (regionNo) { case SIMON_DISPLAY_REGION_0: // Compute the origin point of the box origin_x = 0; origin_y = 0; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the RED square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_RED // color ); } break; case SIMON_DISPLAY_REGION_1: // Compute the origin point of the box origin_x = box_width; origin_y = 0; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the YELLOW square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_YELLOW // color ); } break; case SIMON_DISPLAY_REGION_2: // Compute the origin point of the box origin_x = 0; origin_y = box_height; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the BLUE square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLUE // color ); } break; case SIMON_DISPLAY_REGION_3: // Compute the origin point of the box origin_x = box_width; origin_y = box_height; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the GREEN square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_GREEN // color ); } break; default: printf("Draw square default case hit\n"); // shouldn't hit this break; } }
// This will draw the four board lines. void ticTacToeDisplay_drawBoardLines() { display_drawFastVLine(display_width()/3, 0, display_height(), DISPLAY_CYAN); display_drawFastVLine(2*(display_width()/3), 0, display_height(), DISPLAY_CYAN); display_drawFastHLine(0, display_height()/3, display_width(), DISPLAY_CYAN); display_drawFastHLine(0,(2*display_height()/3), display_width(), DISPLAY_CYAN); }
// After a touch has been detected and after the proper delay, this sets the row and column arguments // according to where the user touched the board. void ticTacToeDisplay_touchScreenComputeBoardRowColumn(uint8_t* row, uint8_t* column) { int16_t x = 0; int16_t y = 0; uint8_t z = 0; uint8_t rowval; uint8_t columnval; if(display_isTouched()) { display_clearOldTouchData(); utils_msDelay(50); display_getTouchedPoint(&x, &y, &z); *row = 0; *column = 0; // column 0 if (x <= display_width()/3) { //row 0 if (y <= display_height()/3) { rowval = 0; columnval = 0; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 0 column 0 \n\r" ); } //row 1 else if (y <= 2* display_height()/3) { rowval = 1; columnval = 0; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 1 column 0 \n\r" ); } //row 2 else { rowval = 2; columnval = 0; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 2 column 0 \n\r" ); } } // column 1 else if (x <= 2*(display_width()/3) ) { //row 0 if (y <= display_height()/3) { rowval = 0; columnval = 1; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 0 column 0 \n\r" ); } //row 1 else if (y <= 2* display_height()/3) { rowval = 1; columnval = 1; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 1 column 0 \n\r" ); } //row 2 else { rowval = 2; columnval = 1; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 2 column 0 \n\r" ); } } // column 2 else { //row 0 if (y <= display_height()/3) { rowval = 0; columnval = 2; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 0 column 0 \n\r" ); } //row 1 else if (y <= 2* display_height()/3) { rowval = 1; columnval = 2; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 1 column 0 \n\r" ); } //row 2 else { rowval = 2; columnval = 2; if (ticTacToeDisplay_SW()) { ticTacToeDisplay_drawO(rowval, columnval); } else { ticTacToeDisplay_drawX(rowval, columnval); } printf("row 2 column 0 \n\r" ); } } } }