static int dispMenu(void* scrbuf, int x, int y, const char* entrylist[], int selected) { //returns number of items in menu int h = 0; int w = 0; int i; for (i = 0; entrylist[i][0] != '\0'; i++) w = max(w, (int) strlen(entrylist[i])); h = i * (CHAR_HEIGHT + 4); w = 2 + (w + 1) * CHAR_WIDTH; dispRect(scrbuf, x, y, w + 2, h + 2, 0); filledRect(scrbuf, x + 1, y + 1, w, h, MENU_BACKGROUND_COLOR); dispHorizLine(scrbuf, x + 1, y + h + 2, w + 2, MENU_SHADOW_COLOR); dispHorizLine(scrbuf, x + 2, y + h + 3, w + 2, MENU_SHADOW_COLOR); dispVertLine(scrbuf, x + w + 2, y + 1, h + 2, MENU_SHADOW_COLOR); dispVertLine(scrbuf, x + w + 3, y + 2, h + 2, MENU_SHADOW_COLOR); y += 3; int j; for (j = 0; j < i; j++, y += CHAR_HEIGHT + 4) { if (j == selected - 1) { filledRect(scrbuf, x + 1, y - 2, w, CHAR_HEIGHT + 4, MENU_SELECTION_COLOR); dispStringColor(scrbuf, x + 3, y, entrylist[j], WHITE_COLOR, MENU_SELECTION_COLOR); } else dispString(scrbuf, x + 3, y, entrylist[j]); } return i; }
int main(int argc, char* args[]) { SDL_Renderer *renderer = init(640, 480); for (;;) { if (pollEventsForQuit()) goto quit; int rc1 = SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); if (rc1 != 0) { fprintf(stderr, "SDL_SetRenderDrawColor failed: %s\n", SDL_GetError()); exit(1); } SDL_RenderClear(renderer); filledRect(renderer, 640/2 - 50/2, 480/2 - 50/2, 50, 50, 255, 0, 0, 128); SDL_RenderPresent(renderer); // Update screen. } quit: SDL_DestroyRenderer(renderer); SDL_Quit(); return 0; }
void KisAsyncMergerTest::testFullRefreshWithClones() { const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 128, 128, colorSpace, "clones test"); KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace); device1->fill(image->bounds(), KoColor( Qt::white, colorSpace)); KisFilterSP filter = KisFilterRegistry::instance()->value("invert"); Q_ASSERT(filter); KisFilterConfiguration *configuration = filter->defaultConfiguration(0); Q_ASSERT(configuration); KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1); KisFilterMaskSP invertMask1 = new KisFilterMask(); invertMask1->initSelection(0, paintLayer1); invertMask1->setFilter(configuration); KisLayerSP cloneLayer1 = new KisCloneLayer(paintLayer1, image, "clone_of_1", OPACITY_OPAQUE_U8); /** * The clone layer must have a projection to allow us * to read what it got from its source. Just shift it. */ cloneLayer1->setX(10); cloneLayer1->setY(10); image->addNode(cloneLayer1, image->rootLayer()); image->addNode(paintLayer1, image->rootLayer()); image->addNode(invertMask1, paintLayer1); QRect cropRect(image->bounds()); KisFullRefreshWalker walker(cropRect); KisAsyncMerger merger; walker.collectRects(image->rootLayer(), image->bounds()); merger.startMerge(walker); // Wait for additional jobs generated by the clone are finished image->waitForDone(); QRect filledRect(10, 10, image->width() - cloneLayer1->x(), image->height() - cloneLayer1->y()); const int pixelSize = device1->pixelSize(); const int numPixels = filledRect.width() * filledRect.height(); QByteArray bytes(numPixels * pixelSize, 13); cloneLayer1->projection()->readBytes((quint8*)bytes.data(), filledRect); KoColor desiredPixel(Qt::black, colorSpace); quint8 *srcPtr = (quint8*)bytes.data(); quint8 *dstPtr = desiredPixel.data(); for(int i = 0; i < numPixels; i++) { if(memcmp(srcPtr, dstPtr, pixelSize)) { qDebug() << "expected:" << dstPtr[0] << dstPtr[1] << dstPtr[2] << dstPtr[3]; qDebug() << "result: " << srcPtr[0] << srcPtr[1] << srcPtr[2] << srcPtr[3]; QFAIL("Failed to compare pixels"); } srcPtr += pixelSize; } }
int filebrowser(void* scrbuf, char* file, char* title) { char currentdir[FILENAME_MAX + 1]; char* filenames[1024]; char filenameinput[FILENAME_MAX + 1] = ""; char blockc = '\0'; int focus_filenameinput = 1; int num_files; int filescroll = 0; int fileselected = 0; int i; int inputpause = 0; if (get_last_doc(currentdir) != 0) { getcwd(currentdir, FILENAME_MAX + 1); } else { *(strrchr(currentdir, '/') + 1) = '\0'; } num_files = get_filenames(currentdir, filenames); if (num_files == -1) return 1; wait_no_key_pressed(); while (1) { //disp: clearScreen(scrbuf); filledRect(scrbuf, 0, TITLE_Y, SCREEN_WIDTH, TITLE_HEIGHT, 0); dispStringColor(scrbuf, 4, (TITLE_HEIGHT - CHAR_HEIGHT) / 2, title, WHITE_COLOR, 0); dispHorizLine(scrbuf, 0, DIR_Y + DIR_HEIGHT - 1, 320, 0); dispString(scrbuf, 4, DIR_Y + (DIR_HEIGHT - CHAR_HEIGHT) / 2, currentdir); dispHorizLine(scrbuf, 0, FILENAMEINPUT_Y, 320, 0); dispString(scrbuf, 4, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, "Filename:"); dispString(scrbuf, 4 + 10 * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, filenameinput); if (focus_filenameinput)//if cursor is in the file name input field, disp an underline to show it putChar(scrbuf, 4 + (10 + strlen(filenameinput)) * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, '_'); for (i = filescroll; i < filescroll + FILES_SHOWN && i < num_files; i++) { //disp file symbol if (is_dir(filenames[i]) && strcmp(filenames[i], ".") && strcmp(filenames[i], "..")) putChar(scrbuf, CHAR_WIDTH * 2, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, '\\'); //disp filename, filesize and selection if (i != fileselected || focus_filenameinput) { dispString(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i]); if (!is_dir(filenames[i])) { char size[16]; get_filesize(filenames[i], size); dispString(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size); } } else { filledRect(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT - 1, SCREEN_WIDTH - CHAR_WIDTH * 4, CHAR_HEIGHT + 2, MENU_SELECTION_COLOR); dispStringColor(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i], WHITE_COLOR, MENU_SELECTION_COLOR); if (!is_dir(filenames[i])) { char size[16]; get_filesize(filenames[i], size); dispStringColor(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size, WHITE_COLOR, MENU_SELECTION_COLOR); } } } showBuffer(scrbuf); //input if (!any_key_pressed()) inputpause = 0; else inputpause--; if (isKeyPressed(KEY_NSPIRE_ESC)) break; if (isKeyPressed(KEY_NSPIRE_TAB)) { focus_filenameinput = !focus_filenameinput; wait_no_key_pressed(); } if (!focus_filenameinput) { if (isKeyPressed(KEY_NSPIRE_ENTER) && (blockc != '\n' || inputpause <= 0)) { inputpause = INPUTPAUSE; blockc = '\n'; if (is_dir(filenames[fileselected])) { chdir(filenames[fileselected]); filescroll = 0; fileselected = 0; free_filenames(filenames); getcwd(currentdir, FILENAME_MAX + 1); num_files = get_filenames(currentdir, filenames); } else { strcpy(file, currentdir); strcat(file, filenames[fileselected]); free_filenames(filenames); printf("%s\n", file); return 0; } } else if (isKeyPressed(KEY_NSPIRE_UP) && (blockc != 0x1 || inputpause <= 0)) { inputpause = INPUTPAUSE; blockc = 0x1; fileselected--; if (fileselected < 0) { fileselected = num_files - 1; filescroll = num_files - FILES_SHOWN; if (filescroll < 0) filescroll = 0; } else if (fileselected - filescroll < 0) filescroll--; strcpy(filenameinput, filenames[fileselected]); } else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockc != 0x2 || inputpause <= 0)) { inputpause = INPUTPAUSE; blockc = 0x2; fileselected++; if (fileselected >= num_files) { fileselected = 0; filescroll = 0; } else if (fileselected - filescroll >= FILES_SHOWN) ++filescroll; strcpy(filenameinput, filenames[fileselected]); } } else { //focus_filenameinput char c = readc(); if (c == blockc && inputpause > 0) continue; if (c != '\0' && c != '\t' && c != '\n') { inputpause = INPUTPAUSE; blockc = c; if (c == '\b') { if (filenameinput[0] != '\0') filenameinput[strlen(filenameinput) - 1] = '\0'; } else { filenameinput[strlen(filenameinput)] = c; filenameinput[strlen(filenameinput) + 1] = '\0'; } } if (isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_TAB)) { inputpause = INPUTPAUSE; focus_filenameinput = 0; } if (isKeyPressed(KEY_NSPIRE_ENTER)) { strcpy(file, currentdir); strcat(file, filenameinput); free_filenames(filenames); printf("%s\n", file); return 0; } } sleep(10); } free_filenames(filenames); return 1; }