Пример #1
0
// needed to initialize function pointer of AbstractShapeFactory
struct IShape* AbstractShapeFactory_getShape( // need a 'this' pointer -> 'self'
    const struct AbstractShapeFactory* self, const char* shapeType){
  assert(self != NULL);
  assert(shapeType != NULL);
  if(shapeType[0] == '\0'){                 // testing for empty string
    return NULL;
  }
  if(strcasecmp(shapeType,"CIRCLE") == 0){  // case insensitive comp on POSIX
    return &Circle_new(self->getColor())->base.base;
  } else if (strcasecmp(shapeType,"RECTANGLE") == 0){
    return &Rectangle_new(self->getColor())->base.base;
  } else if (strcasecmp(shapeType,"SQUARE") == 0){
    return &Square_new(self->getColor())->base.base;
  }
  assert(0);
}
Пример #2
0
const char *FileBrowsePanel_Main(SDL_Surface *screen) {
	fprintf(stderr, "FileBrowsePanel_Main: Currently unsupported.\n");
	return NULL;
	@OLD main function stuff
	// Create font
	font = Static_getFont("fonts/ariblk.ttf", 20);
	
	// Create a fileInfo type array containing content of current folder
	prevClicked = 0xFFFFFFFF;
	firstScreenIndex = 0;
	selIndex = 0xFFFFFFFF;
	
	// initialize screen context
	Screen_init(&sc, screen, 0);
	Screen_setBackground(&sc, "img/green-design-background.jpg");
	sc.drag_on = false;
	
	tblist = NULL;
	
	getCurrentFolderContent(&tblist, &tblistCount, sc.screen, font, 
							FBP_FILE_INFO_BGCOLOR_UNSEL, 0x000000, fileTypes, &nameHeight,
							textblock_filename_clicked);
	//~ u32 i=0; for (; i < tblistCount; i++) 
		//~ fprintf(stderr, "widget[%u/%u] id=%u\t%s\n", i, tblistCount, 
			//~ tblist[i].text_block.widget.id, tblist[i].text_block.text);
	u32 i;
	nameHeight += 5;
	
	char current_dir[PATH_MAX_SIZE];
	getcwd(current_dir, PATH_MAX_SIZE);
	
	// Update actual folder path
	//~ TextBlock *tb_currentFolder = malloc(sizeof(TextBlock));
	//~ tb_currentFolder->text = (char*) malloc(PATH_MAX_SIZE*sizeof(char));
	//~ getcwd(tb_currentFolder->text, PATH_MAX_SIZE-1);
	//~ TextBlock_setFont(tb_currentFolder, font);
	//~ TextBlock_setBackgroundColor(tb_currentFolder, 0xD9FFAD);
	//~ TextBlock_setForegroundColor(tb_currentFolder, 0x000000);
	//~ TextBlock_refresh(tb_currentFolder);
	//~ Widget *tb_currentFolder_widget = &(tb_currentFolder->widget);
	//~ tb_currentFolder_widget->id = 4;
	//~ tb_currentFolder_widget->draggable = true;
	//~ tb_currentFolder_widget->mevent = true;
	
	border_rect = malloc(sizeof(Rectangle));
	Rectangle *border_rect2 = malloc(sizeof(Rectangle));
	Rectangle_new(border_rect, sc.screen, 0xE2F3D3);
	Rectangle_new(border_rect2, sc.screen, 0x2EAE00);
	border_rectWidget = &(border_rect->widget);
	border_rect2Widget = &(border_rect2->widget);
	
	u16 height = (W_SCREEN_HEIGHT<<1)/3;
	height -= (height-UPPER_RESERV)%nameHeight;
	border_rectWidget->pos.y = 100;
	border_rectWidget->pos.w = 850;
	border_rectWidget->pos.x = 100;
	border_rectWidget->pos.h = height;
	border_rect2Widget->pos.y = border_rectWidget->pos.y - 5;
	border_rect2Widget->pos.x = border_rectWidget->pos.x - 5;
	border_rect2Widget->pos.w = border_rectWidget->pos.w + 10;
	border_rect2Widget->pos.h = border_rectWidget->pos.h + 10;
	Rectangle_refresh(border_rect);
	Rectangle_refresh(border_rect2);
	
	// Preview view rectangle
	p_x = border_rect2Widget->maxx + 10;
	p_y = border_rect2Widget->pos.y + 10;
	p_w = W_SCREEN_WIDTH - border_rect2Widget->pos.w - border_rect2Widget->pos.x - 20;
	p_h = border_rect2Widget->pos.h - 20;
	
	Button *butOk = malloc(sizeof(Button));
	Button *butAnuluj = malloc(sizeof(Button));
	
	Button_new(butOk, sc.screen, "OK", true);
	Widget *butOk_widget = &(butOk->widget);
	butOk_widget->click_handler = button_ok_clicked;
	Button_applyDefaultStyle(butOk, 879, 874, font, 50, 5);
	Button_setFixedWidth(butOk, true);
	
	Button_new(butAnuluj, sc.screen, "Anuluj", true);
	Widget *butAnuluj_widget = &(butAnuluj->widget);
	butAnuluj_widget->click_handler = button_anuluj_clicked;
	Button_applyDefaultStyle(butAnuluj, 1061, 874, font, 33, 5);
	Button_setFixedWidth(butAnuluj, true);
	
	b8 got_event=false;
	sel = false;
	char *ret_path = NULL;

	preview = malloc(sizeof(Image));
	Image_new(preview, NULL, 0, 0); // invisible preview image
	
	//~ border_rectWidget->pos.y  = 100;
	//~ border_rectWidget->pos.w  = W_SCREEN_WIDTH-200;
	//~ border_rect2Widget->pos.y = border_rectWidget->pos.y - 5;
	//~ border_rect2Widget->pos.w = border_rectWidget->pos.w + 10;
	//~ border_rectWidget->pos.x  = (W_SCREEN_WIDTH-border_rectWidget->pos.w)>>1;
	//~ border_rect2Widget->pos.x = border_rectWidget->pos.x - 5;
	
	while (! sc.has_exited) {
		if (sc.need_reload) {
			sc.need_reload = false;
			SDL_BlitSurface(sc.background->widget.surf, NULL, sc.screen, NULL);
			if (preview->widget.visible) {
				Widget_draw(&(preview->widget), &sc, false);
			}
			u16 height = (W_SCREEN_HEIGHT<<1)/3;
			height -= (height-UPPER_RESERV)%nameHeight;
			border_rectWidget->pos.h = height;
			border_rect2Widget->pos.h = border_rectWidget->pos.h + 10;
			Rectangle_refresh(border_rect);
			Rectangle_refresh(border_rect2);
			
			
			Widget_draw(border_rect2Widget, &sc, false);
			Widget_draw(border_rectWidget, &sc, false);
			Widget_draw(butOk_widget, &sc, false);
			
			showFiles();
			Widget_draw(butOk_widget, &sc, false);
			Widget_draw(butAnuluj_widget, &sc, true);
		}
		

		while (SDL_WaitEvent(sc.pevent)) {
			got_event = true;
			switch (sc.event.type) {
				case SDL_KEYDOWN:	// only for testing purpouses
					if (sc.event.key.keysym.sym == SDLK_ESCAPE)
						sc.has_exited = true;
					else {
						if (sc.event.key.keysym.sym == SDLK_F2) {
							fprintf(stderr, "Debug list:\n");
							for (i = 0; i < tblistCount; i++) {
								fprintf(stderr, "TextBlock [%u/%u] id=%u text=%s\n", i, tblistCount, tblist[i].text_block.widget.id, tblist[i].text_block.text);
							}
						}
					}
					break;
				case SDL_QUIT:
						sc.has_exited = true;
					break;
				case SDL_MOUSEBUTTONDOWN:
					if (sc.event.button.button == 4) {	 // wheel up
						if (firstScreenIndex > 0) {
							firstScreenIndex--;
							sc.need_reload = true;
						}
						break;
					}
					else {
						if (sc.event.button.button == 5) { // wheel down
							if (lastScreenIndex < tblistCount-1) {
								firstScreenIndex++;
								sc.need_reload = true;
							}
							break;
						}
					}
				default:
					Widget_mevent(butOk_widget, &sc);// if (sc.event_handled) break;
					Widget_mevent(butAnuluj_widget, &sc); //if (sc.event_handled) break;
					
					if (sc.event.type != SDL_MOUSEMOTION) {
						for (i = firstScreenIndex; i <= lastScreenIndex; i++) {
							Widget_mevent(&(tblist[i].text_block.widget), &sc);
							//if (sc.event_handled) break;
						}
					}
					break;
			}
			if (got_event) break;
		}
		
		
	}
	to_end:
	
	if ((sel) || (selIndex != 0xFFFFFFFF)) {
		ret_path = realpath(tblist[selIndex].text_block.text, ret_path);
		if (! ret_path) {
			fprintf(stderr, "FileBrowsePanel_Main:FileBrowsePanel > Failed to realpath on selected path %s\n", tblist[selIndex].text_block.text);
		}
	}
	
	// Remember to copy text of selected file
	for (i = 0; i < tblistCount; i++) {
		fprintf(stderr, "Delete TextBlock %u, %s\n", i, tblist[i].text_block.text);
		delete(&(tblist[i].text_block));
	}
	
	free(tblist);
	
	delete(&sc);
	
	delete(butOk);
	delete(butAnuluj);
	delete(border_rect);
	delete(border_rect2);
	
	
	free(butOk);
	free(butAnuluj);
	free(border_rect);
	free(border_rect2);
	free(preview);
	if (chdir(current_dir)) {	// go back to previous directory
		fprintf(stderr, "FileBrowsePanel_Main:FileBrowsePanel > Failed to go back to previous directory %s\n", current_dir);
	}
	
	fprintf(stderr, "FileBrowsePanel: Exiting\n");
	return ret_path;
	**/
}