int show_2numeric_input(const char * title, const char * subtitle, const char * msg1, int * value1_ref, int min_value1, int max_value1, const char * msg2, int * value2_ref, int min_value2, int max_value2) {
  char title16[(strlen(title) + 1) * 2];
  char subtitle16[(strlen(subtitle) + 1) * 2];
  char msg116[(strlen(msg1) + 1) * 2];
  char msg216[(strlen(msg2) + 1) * 2];
  ascii2utf16(title16, title, sizeof(title16));
  ascii2utf16(subtitle16, subtitle, sizeof(subtitle16));
  ascii2utf16(msg116, msg1, sizeof(msg116));
  ascii2utf16(msg216, msg2, sizeof(msg216));
  int cheatMode = 0;
  int real_min_value1 = min_value1;
  int real_min_value2 = min_value2;
  if(min_value1 == 0 || min_value1 == -1) {
    real_min_value1 = -2;
    cheatMode = 1;
  }
  if(min_value2 == 0 || min_value2 == -1) {
    real_min_value2 = -2;
    cheatMode = 1;
  }
  int result = (_show_2NumericInput(0, title16, subtitle16, msg116, value1_ref, 1, real_min_value1, max_value1, msg216, value2_ref, 1, real_min_value2, max_value2) == 5103);
  if(cheatMode){
    if(*value1_ref < min_value1)
      *value1_ref = min_value1;
    if(*value2_ref < min_value2)
      *value2_ref = min_value2;
  }

  return result;
}
Beispiel #2
0
unsigned _show_msgbox(const char *title, const char *msg, unsigned button_num, ...) {
	va_list ap;
	char title16[(strlen(title) + 1) * 2];
	char msg16[(strlen(msg) + 1) * 2];
	char undef_buf[8];
	unsigned button_pressed = 0;
	memset(undef_buf, 0, sizeof(undef_buf));
	va_start(ap, button_num);
	
	ascii2utf16(title16, title, sizeof(title16));
	ascii2utf16(msg16, msg, sizeof(msg16));
	*(char**)undef_buf = "DLG";
	BOOL incolor = lcd_isincolor();
	void *saved_screen = NULL;
	if (has_colors && !incolor) {
		if ((saved_screen = malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 2))) {
			// The screen buffer size of the color mode is used, but before switching to it
			memcpy(saved_screen, SCREEN_BASE_ADDRESS, SCREEN_WIDTH * SCREEN_HEIGHT * 2);
			memset(SCREEN_BASE_ADDRESS, 0xFF, SCREEN_WIDTH * SCREEN_HEIGHT * 2); // clrscr. avoid displaying a grayscaled buffer in colors
		}
		lcd_incolor();
	}
	/* required since OS 2.1 for OS key scan */
	int orig_mask = TCT_Local_Control_Interrupts(0);
	if (button_num == 2 || button_num == 3) {
		char *button1 = va_arg(ap, char*);
		char *button2 = va_arg(ap, char*);
		char button1_16[(strlen(button1) + 1) * 2];
		char button2_16[(strlen(button2) + 1) * 2];
		ascii2utf16(button1_16, button1, sizeof(button1_16));
		ascii2utf16(button2_16, button2, sizeof(button2_16));
		if (button_num == 2) {
			button_pressed = _show_msgbox_2b(0, title16, msg16, button1_16, 1, button2_16, 2, undef_buf);
		} else {
			char *button3 = va_arg(ap, char*);
			char button3_16[(strlen(button3) + 1) * 2];
			ascii2utf16(button3_16, button3, sizeof(button3_16));
			button_pressed = _show_msgbox_3b(0, title16, msg16, button1_16, 1, button2_16, 2, button3_16, 3, undef_buf);
		}
	} else {
Beispiel #3
0
const char16_t *calchook_ndls_run(void *, void *, unsigned int argc, char16_t *argv[])
{
	if(argc == 0)
		return u"\"Missing Argument!\"";

	unsigned int i;
	char *argv_prgm[argc];
	for(i = 0; i < argc; ++i)
	{
		size_t len = utf16_strlen(reinterpret_cast<uint16_t*>(argv[i]));
		argv_prgm[i] = new char[2*len + 1];
		if(!argv_prgm[i])
		{
			// Free already allocated argv_prgm
			for(unsigned int j = 0; j < i; ++j)
				delete[] argv_prgm[j];

			return u"\"Out of memory!\"";
		}

		// Strip quotes from strings
		if((*argv[i] == '"' && *(argv[i]+len-1) == '"')
			|| (*argv[i] == '\'' && *(argv[i]+len-1) == '\''))
		{
			*(argv[i]+len-1) = 0;
			utf162ascii(argv_prgm[i], reinterpret_cast<uint16_t*>(argv[i] + 1), 2*len);
		}
		else
			utf162ascii(argv_prgm[i], reinterpret_cast<uint16_t*>(argv[i]), 2*len);
	}

	int ret = ld_exec_with_args(argv_prgm[0], argc - 1, argv_prgm + 1, nullptr);

	// Free argv_prgm
	for(unsigned int j = 0; j < i; ++j)
		delete[] argv_prgm[j];

	// The return value is never freed, so use a static buffer
	static char16_t ret16[16]; static char retascii[16];
	snprintf(retascii, 16, "%d", ret);
	ascii2utf16(ret16, retascii, 16);
	return ret16;
}
Beispiel #4
0
void CreateMetrics(struct Metrics** ppMetrics, SquareLib square, Gc* pgc)
{
   *ppMetrics = malloc(sizeof(struct Metrics));
   struct Metrics* pMetrics = *ppMetrics;
   pMetrics->m_Square = square;

   int nWidth = GetSquareWidth(square);
   int nHeight = GetSquareHeight(square);

   pMetrics->m_nMaxColIndicators = 0;
   for(int x=0; x<nWidth; x++) {
      int nIndicators = GetNumSquareIndicatorsForCol(square, x);
      if( nIndicators > pMetrics->m_nMaxColIndicators )
         pMetrics->m_nMaxColIndicators = nIndicators;
   }
   //printf("Max col indicators: %d\n", pMetrics->m_nMaxColIndicators);

   pMetrics->m_nMaxRowIndicators = 0;
   for(int y=0; y<nHeight; y++) {
      int nIndicators = GetNumSquareIndicatorsForRow(square, y);
      if( nIndicators > pMetrics->m_nMaxRowIndicators )
         pMetrics->m_nMaxRowIndicators = nIndicators;
   }
   //printf("Max row indicators: %d\n", pMetrics->m_nMaxRowIndicators);

   char buffer[16];
   char buf[8];
   sprintf(buf, "%d", 8/*Example wide character*/);
   ascii2utf16(buffer, buf, 16);

   gui_gc_setFont(*pgc, SerifRegular7);
   const int nHorizontalSpacing = 3;
   int nWidthPerChar = gui_gc_getStringWidth(*pgc, gui_gc_getFont(*pgc), buf, 0, 1) + nHorizontalSpacing;

   const int nGapHorizontally = 4;
   const int nGapVertically = 4;
   int nIndicatorSpaceNeededHorizontally = pMetrics->m_nMaxRowIndicators * nWidthPerChar;
   int nSpaceAvailableHorizontally = SCREEN_WIDTH - nGapHorizontally - nIndicatorSpaceNeededHorizontally;
   //printf("Space available Horizontall: %d\n", nSpaceAvailableHorizontally);

   int nHeightPerChar = gui_gc_getStringSmallHeight(*pgc, gui_gc_getFont(*pgc), buf, 0, 1);
   //printf("HeightPerChar: %d\n", nHeightPerChar);
   const int nIndicatorGapVertically = 3;
   int nIndicatorSpaceNeededVertically = pMetrics->m_nMaxColIndicators * nHeightPerChar + nIndicatorGapVertically;
   //printf("IndicatorSpaceNeededVertically: %d\n", nIndicatorSpaceNeededVertically);
   int nSpaceAvailableVertically = SCREEN_HEIGHT - nGapVertically - nIndicatorSpaceNeededVertically;
   //printf("Space available vertically: %d\n", nSpaceAvailableVertically);

   int nMinSpaceAvailable = nSpaceAvailableHorizontally < nSpaceAvailableVertically ? nSpaceAvailableHorizontally - (nWidth-1) : nSpaceAvailableVertically - (nHeight-1);

   int nPieceWidth = nMinSpaceAvailable / nWidth;
   int nPieceHeight = nSpaceAvailableVertically / nHeight;
   pMetrics->m_nPieceDim = nPieceWidth < nPieceHeight ? nPieceWidth : nPieceHeight;
   //printf("PieceDim: %d\n", pMetrics->m_nPieceDim);

   int nBoardDim = ((pMetrics->m_nPieceDim * nWidth) > (pMetrics->m_nPieceDim * nHeight)) ? pMetrics->m_nPieceDim * nWidth : pMetrics->m_nPieceDim * nHeight;

   pMetrics->m_nLeftBoard = SCREEN_WIDTH - nGapHorizontally - nBoardDim;
   pMetrics->m_nTopBoard = nIndicatorSpaceNeededVertically;

   pMetrics->m_nLeft = pMetrics->m_nLeftBoard - nIndicatorSpaceNeededHorizontally;
   pMetrics->m_nTop = 0;
}
Beispiel #5
0
void DrawMenuPieces(struct MainMenu* pMenu, Gc* pgc)
{
   const int nDimensionSize = 6;

   int nPieceWidth = SCREEN_WIDTH/nDimensionSize;
   int nPieceHeight = (SCREEN_HEIGHT-60)/nDimensionSize;
   int nMinPieceDim = nPieceWidth > nPieceHeight ? nPieceHeight : nPieceWidth;

   int nWidthNeeded = nDimensionSize*nMinPieceDim;
   int nHeightNeeded = nDimensionSize*nMinPieceDim;
   int x = (SCREEN_WIDTH - nWidthNeeded)/2;
   int y = (SCREEN_HEIGHT - nHeightNeeded)/2;

   for(int nX=0; nX<nDimensionSize; nX++) {
      for(int nY=0; nY<nDimensionSize; nY++) {
         int nPieceX = x + nX*nMinPieceDim;
         int nPieceY = y + nY*nMinPieceDim;

         int nLevelNum = nY*nDimensionSize + nX + 1/*0-based to 1-based*/;

         int bCurrentRow = 0;
         int nColorIndex = 0;
         if( pMenu->m_eChoice == Play ) {
            if( pMenu->m_nLevelNum >= 1 && pMenu->m_nLevelNum <= 6 && nLevelNum >= 1 && nLevelNum <= 6 ) {
               nColorIndex = 0;
               bCurrentRow = 1;
            } else if( pMenu->m_nLevelNum >= 7 && pMenu->m_nLevelNum <= 12 && nLevelNum >= 7 && nLevelNum <= 12 ) {
               nColorIndex = 1;
               bCurrentRow = 1;
            } else if( pMenu->m_nLevelNum >= 13 && pMenu->m_nLevelNum <= 18 && nLevelNum >= 13 && nLevelNum <= 18 ) {
               nColorIndex = 2;
               bCurrentRow = 1;
            } else if( pMenu->m_nLevelNum >= 19 && pMenu->m_nLevelNum <= 24 && nLevelNum >= 19 && nLevelNum <= 24 ) {
               nColorIndex = 3;
               bCurrentRow = 1;
            } else if( pMenu->m_nLevelNum >= 25 && pMenu->m_nLevelNum <= 30 && nLevelNum >= 25 && nLevelNum <= 30 ) {
               nColorIndex = 4;
               bCurrentRow = 1;
            } else if( pMenu->m_nLevelNum >= 31 && nLevelNum >= 31 ) {
               nColorIndex = 5;
               bCurrentRow = 1;
            }
         }
         if( bCurrentRow == 1 ) {
            LevelColors clr = g_Colors[nColorIndex];
            gui_gc_setColorRGB(*pgc, clr.r, clr.g, clr.b);
            //gui_gc_setColorRGB(*pgc, 0, 220, 0);
         } else {
            gui_gc_setColorRGB(*pgc, 0x59, 0x59, 0x59);
         }
         gui_gc_fillRect(*pgc, nPieceX + 2, nPieceY + 2, nMinPieceDim-3, nMinPieceDim-3);

         if( pMenu->m_eChoice == Play && pMenu->m_nLevelNum == nLevelNum ) {
            gui_gc_setColorRGB(*pgc, 255, 0, 0);

            gui_gc_drawRect(*pgc, nPieceX, nPieceY, nMinPieceDim, nMinPieceDim);
         }

         gui_gc_setColorRGB(*pgc, 255, 255, 255);
         char buf[8];
         sprintf(buf, "%d", nLevelNum);
         char buffer[16];
         ascii2utf16(buffer, buf, 16);

         int nHeightSpaceDesired = gui_gc_getStringSmallHeight(*pgc, gui_gc_getFont(*pgc), buf, 0, 1);
      int nWidthSpaceDesired = gui_gc_getStringWidth(*pgc, gui_gc_getFont(*pgc), buf, 0, 1);

         int nXOffset = nMinPieceDim/2 - nWidthSpaceDesired/2;
         int nYOffset = 2;

         int nPosX = nPieceX + nXOffset;
         int nPosY = nPieceY + nYOffset;

         gui_gc_drawString(*pgc, buffer, nPosX, nPosY, GC_SM_TOP);

         int nStars = 0;
         GetBeatLevel(pMenu->m_pConfig, nLevelNum-1, &nStars);
         int a = nMinPieceDim/3;
         for(int nStarsToDraw=0; nStarsToDraw<nStars; nStarsToDraw++) {
            DrawStar(pgc, nPieceX+nStarsToDraw*a+a/2+1, nPosY+nMinPieceDim-a, a);
         }
      }
   }
}