Example #1
0
int main(int argc, char *argv[]){
  pdf          *demo;
  page         *currPage;
  char         tempString[1024];
  int          count, x, y;

  // Initialise the library
  initpanda();

  // Open our demo PDF
  if((demo = pdfopen("output.pdf", "w")) == NULL)
    error("demo: could not open output.pdf to write to.");

  // Create a page
  currPage = pdfpage(demo, gPageSizeA4);

  x = 0;
  y = 16;

  for(count = 0; count < 10000; count++){
    textbox(demo, currPage, y, x, y + 10, x + 10, "x");

    x += 5;
    
    if(x > 594){
      x = 0;
      y += 16;
    }
  }

  pdfclose(demo);

  exit(0);
}
Example #2
0
void henon_shower(stamp_structure * s)
{
	henon_str *p = &s->s.h;
	char tbuf[128];
	char *lines[20];
	int i, items = 0;

	lines[items++] = strdup("Henon Parameters");
	sprintf(tbuf, "Flock size: %d", p->fflock2ptr->n);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Window: (%g %g) (%g %g)",
		p->flox, p->floy, p->fhix, p->fhiy);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Fanciness: %d", p->fancyflag);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Ribbonlength: %d", p->ribbonlength);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Tracetype: %d", p->tracetype);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Chaoticity: %g", p->fha);
   lines[items++] = strdup(tbuf);
	lines[items] = NULL;
	textbox(lines);
	for (i = 0; i < items; i++)
		free(lines[i]);
}
Example #3
0
void yorke_shower(stamp_structure * s)
{
	yorke_str *p = &s->s.y;
	char tbuf[128];
	int items = 0, i;
	char *lines[20];
   extern char *topologymsg[];

	lines[items++] = strdup("Yorke Parameters");
	sprintf(tbuf, "Flock type: %s", SML[p->flocktype]);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Window: (%g %g) (%g %g)",
		p->flox, p->floy, p->fhix, p->fhiy);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Omegas: %g %g", p->omega1, p->omega2);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Ribbonlength: %d", p->ribbonlength);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Tracetype: %d", p->tracetype);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Topology: %s", topologymsg[p->yorketopologyflag]);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Epsilon: %g", p->epsilon);
	lines[items] = NULL;
	textbox(lines);
	for (i = 0; i < items; i++)
		free(lines[i]);
}
int inputBox(const char * text, int height, int width, poptContext optCon, 
		int flags, char ** result) {
    newtComponent form, entry, okay, cancel, answer, tb;
    char * val;
    int rc = DLG_OKAY;
    int top;

    val = poptGetArg(optCon);
    tb = textbox(height - 3 - buttonHeight, width - 2,
			text, flags, &top);

    form = newtForm(NULL, NULL, 0);
    entry = newtEntry(1, top + 1, val, width - 2, &val, 
			NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);

    newtFormAddComponents(form, tb, entry, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    *result = val;

    return rc;
}
Example #5
0
void logistic_shower(stamp_structure * s)
{
	logistic_str *p = &s->s.lo;

	char *lines[20];
	char tbuf[128];
	int i, items = 0;

	lines[items++] = strdup("Logistic Parameters");

	sprintf(tbuf, "Window: (%g %g) (%g %g)",
		p->flox, p->floy, p->fhix, p->fhiy);
	lines[items++] = strdup(tbuf);

	sprintf(tbuf, "Tracetype: %d", p->tracetype);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Chaoticity: %g", p->lvfx);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Humpspot: %g", p->humpspot);
	lines[items++] = strdup(tbuf);
	lines[items] = NULL;
	textbox(lines);
	for (i = 0; i < items; i++)
		free(lines[i]);

}
Example #6
0
void lorenz_shower(stamp_structure * s)
{
	lorenz_str *p = &s->s.lz;
	char tbuf[128];
	int items = 0, i;
	char *lines[20];

	lines[items++] = strdup("Lorenz Parameters");
	sprintf(tbuf, "Flock size: %d", p->fflock3ptr->n);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Starting trihedrons: %d", p->trihedroncount);
	lines[items++] = strdup(tbuf);
   sprintf(tbuf, "Ending trihedrons: %d",p->end_trihedroncount);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Window: (%g %g %g)", p->flox, p->floy, p->floz);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "        (%g %g %g)", p->fhix, p->fhiy, p->floz);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Axis: %c", p->view);
	lines[items++] = strdup(tbuf);
	sprintf(tbuf, "Accuracy: %d", (int)(1.0/p->accuracy + .5));
	lines[items++] = strdup(tbuf);
	lines[items] = NULL;
	textbox(lines);
	for (i = 0; i < items; i++)
		free(lines[i]);
}
Example #7
0
void createUI(NVGcontext *vg, float w, float h)
{
    int col;

    uiClear();

    {
        int root = uiItem(); 
        // position root element
        uiSetLayout(root,UI_LEFT|UI_TOP);
        uiSetMargins(root,50,50,0,0);
        uiSetSize(root,250,400);
    }

    col = column(0);
    uiSetLayout(col, UI_TOP|UI_HFILL);

    button(col, __LINE__, BND_ICONID(6,3), "Item 1", demohandler);
    button(col, __LINE__, BND_ICONID(6,3), "Item 2", demohandler);

    {
        int h = hgroup(col);
        radio(h, __LINE__, BND_ICONID(6,3), "Item 3.0", &enum1);
        radio(h, __LINE__, BND_ICONID(0,10), NULL, &enum1);
        radio(h, __LINE__, BND_ICONID(1,10), NULL, &enum1);
        radio(h, __LINE__, BND_ICONID(6,3), "Item 3.3", &enum1);
    }

    {
        int colr;
        int rows = row(col);
        int coll = vgroup(rows);
        label(coll, -1, "Items 4.0:");
        coll = vgroup(coll);
        button(coll, __LINE__, BND_ICONID(6,3), "Item 4.0.0", demohandler);
        button(coll, __LINE__, BND_ICONID(6,3), "Item 4.0.1", demohandler);
        colr = vgroup(rows);
        uiSetFrozen(colr, option1);
        label(colr, -1, "Items 4.1:");
        colr = vgroup(colr);
        slider(colr, __LINE__, "Item 4.1.0", &progress1);
        slider(colr,__LINE__, "Item 4.1.1", &progress2);
    }

    button(col, __LINE__, BND_ICONID(6,3), "Item 5", NULL);

    check(col, __LINE__, "Frozen", &option1);
    check(col, __LINE__, "Item 7", &option2);
    check(col, __LINE__, "Item 8", &option3);

    textbox(col, (UIhandle)textbuffer, textbuffer, 32);

    uiLayout();
}
Example #8
0
static void show_menu(void)
{
    char buf[16];
    SDL_Rect dest;
    int h = LINE2-LINE1;
    int f = 9*h/10;
    int i;

    dest.x = dest.y = dest.w = dest.h = 0;
    SDL_BlitSurface(menubg, NULL, darea, &dest);

    for (i = 0; i < 10; i++)
	checkbox(tatami_x[i], LINE2, f, -1, conf_tatamis[i]);

    textbox(L1, LINE3, TEXTBOX_W, f, dspnames[display_type]);

    textbox(L1, LINE4, TEXTBOX_W, f, red_background ? "Red" : "Blue");

    checkbox(L1, LINE5, f, 1, mirror_display);

}
Example #9
0
void build_democontent(int parent) {
    // some persistent variables for demonstration
    static float progress1 = 0.25f;
    static float progress2 = 0.75f;
    static int option1 = 1;
    static int option2 = 0;
    static int option3 = 0;

    int col = column();
    uiInsert(parent, col);
    uiSetMargins(col, 10, 10, 10, 10);
    uiSetLayout(col, UI_TOP|UI_HFILL);
    
    column_append(col, button(BND_ICON_GHOST, "Item 1", demohandler));
    if (option3)
        column_append(col, button(BND_ICON_GHOST, "Item 2", demohandler));

    {
        int h = column_append(col, hbox());
        hgroup_append(h, radio(BND_ICON_GHOST, "Item 3.0", &enum1));
        if (option2)
            uiSetMargins(hgroup_append_fixed(h, radio(BND_ICON_REC, NULL, &enum1)), -1,0,0,0);
        uiSetMargins(hgroup_append_fixed(h, radio(BND_ICON_PLAY, NULL, &enum1)), -1,0,0,0);
        uiSetMargins(hgroup_append(h, radio(BND_ICON_GHOST, "Item 3.3", &enum1)), -1,0,0,0);
    }
    
    {
        int rows = column_append(col, row());
        int coll = row_append(rows, vgroup());
        vgroup_append(coll, label(-1, "Items 4.0:"));
        coll = vgroup_append(coll, vbox());
        vgroup_append(coll, button(BND_ICON_GHOST, "Item 4.0.0", demohandler));
        uiSetMargins(vgroup_append(coll, button(BND_ICON_GHOST, "Item 4.0.1", demohandler)),0,-2,0,0);
        int colr = row_append(rows, vgroup());
        uiSetMargins(colr, 8, 0, 0, 0);
        uiSetFrozen(colr, option1);
        vgroup_append(colr, label(-1, "Items 4.1:"));
        colr = vgroup_append(colr, vbox());
        vgroup_append(colr, slider("Item 4.1.0", &progress1));
        uiSetMargins(vgroup_append(colr, slider("Item 4.1.1", &progress2)),0,-2,0,0);
    }
    
    column_append(col, button(BND_ICON_GHOST, "Item 5", NULL));

    static char textbuffer[1024] = "The quick brown fox.";
    column_append(col, textbox(textbuffer, 1024));

    column_append(col, check("Frozen", &option1));
    column_append(col, check("Item 7", &option2));
    column_append(col, check("Item 8", &option3));
}
Example #10
0
bool FH2LocalClient::Prepare4BattleOnly(void)
{
    // get color
    if(! GetPlayersInfo()) return false;

    if(2 > players.size())
    {
	GetLoadMaps(true, false);

	LocalEvent & le = LocalEvent::Get();
	Cursor & cursor = Cursor::Get();
	Display & display = Display::Get();

	cursor.Hide();
	TextBox textbox("wait other player", Font::BIG, BOXAREA_WIDTH);
	Dialog::Box box(10 + textbox.h(), Dialog::CANCEL);
	const Rect & pos = box.GetArea();                                                                                          
	textbox.Blit(pos.x, pos.y + 20);

	ButtonGroups btnGroups(box.GetArea(), Dialog::CANCEL);
	btnGroups.Draw();

	cursor.Show();
	display.Flip();

	QueueMessage packet;

	DEBUG(DBG_NETWORK, DBG_INFO, "wait: " << Network::GetMsgString(MSG_UPDATE_PLAYERS));

	while(le.HandleEvents())
	{
	    if(Dialog::ZERO != btnGroups.QueueEventProcessing())
		return false;

	    if(Ready())
    	    {
        	if(!Network::RecvMessage(*this, packet))
            	    return false;

        	if(MSG_UPDATE_PLAYERS == packet.GetID())
		    break;
    	    }
    	    DELAY(10);
	}

	MsgUpdatePlayers(packet);
    }

    return true;
}
Example #11
0
int main(int, char const**) {
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    // Set the Icon
    sf::Image icon;
    if (!icon.loadFromFile(resourcePath() + "icon.png")) {
        return EXIT_FAILURE;
    }
    window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());

    // Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile(resourcePath() + "sansation.ttf")) {
        return EXIT_FAILURE;
    }
	
	Textbox textbox(window, font);
	textbox.setDimensons(100, 100, 400, 50);
	textbox.setFocus(true);

    // Start the game loop
    while (window.isOpen()) {
        // Process events
        sf::Event event;
        while (window.pollEvent(event)) {
            // Close window: exit
            if(event.type == sf::Event::Closed) {
                window.close();
            }
			bool didHitReturn = textbox.pollEvent(event);
			if(didHitReturn) {
				// do stuff here using textbox.getString()
			}
        }

        // Clear screen
        window.clear();
		
		textbox.draw();

        // Update the window
        window.display();
    }

    return EXIT_SUCCESS;
}
bool Dialog::InputString(const std::string &header, std::string &res)
{
    const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM;

    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    cursor.Hide();
    Cursor::themes_t oldcursor = cursor.Themes();
    cursor.SetThemes(cursor.POINTER);

    //const bool pda = Settings::Get().PocketPC();
    if(res.size()) res.clear();
    res.reserve(48);
    size_t charInsertPos = 0;

    TextBox textbox(header, Font::BIG, BOXAREA_WIDTH);
    Point dst_pt;
    const Surface & sprite = AGG::GetICN((Settings::Get().ExtGameEvilInterface() ? ICN::BUYBUILD : ICN::BUYBUILE), 3);

    Box box(10 + textbox.h() + 10 + sprite.h(), OK|CANCEL);
    const Rect & box_rt = box.GetArea();

    // text
    dst_pt.x = box_rt.x + (box_rt.w - textbox.w()) / 2;
    dst_pt.y = box_rt.y + 10;
    textbox.Blit(dst_pt);

    dst_pt.y = box_rt.y + 10 + textbox.h() + 10;
    dst_pt.x = box_rt.x + (box_rt.w - sprite.w()) / 2;
    sprite.Blit(dst_pt, display);
    const Rect text_rt(dst_pt.x, dst_pt.y, sprite.w(), sprite.h());

    Text text("_", Font::BIG);
    sprite.Blit(text_rt, display);
    text.Blit(dst_pt.x + (sprite.w() - text.w()) / 2, dst_pt.y - 1);

    dst_pt.x = box_rt.x;
    dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h();
    Button buttonOk(dst_pt, system, 1, 2);

    dst_pt.x = box_rt.x + box_rt.w - AGG::GetICN(system, 3).w();
    dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 3).h();
    Button buttonCancel(dst_pt, system, 3, 4);

    buttonOk.SetDisable(res.empty());
    buttonOk.Draw();
    buttonCancel.Draw();

    cursor.Show();
    display.Flip();

    LocalEvent & le = LocalEvent::Get();
    bool redraw = true;

    // message loop
    while(le.HandleEvents())
    {
	buttonOk.isEnable() && le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();
        le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw();

	if(Settings::Get().PocketPC() && le.MousePressLeft(text_rt))
	{
	    PocketPC::KeyboardDialog(res);
	    redraw = true;
	}

        if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || (buttonOk.isEnable() && le.MouseClickLeft(buttonOk))) break;
	else
	if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)){ res.clear(); break; }
	else
	if(le.KeyPress())
	{
	    charInsertPos = String::InsertKeySym(res, charInsertPos, le.KeyValue(), le.KeyMod());
	    redraw = true;
	}

	if(redraw)
	{
	    buttonOk.SetDisable(res.empty());
	    buttonOk.Draw();

	    text.Set(String::InsertString(res, charInsertPos, "_"));

	    if(text.w() < sprite.w() - 24)
	    {
		cursor.Hide();
		sprite.Blit(text_rt, display);
		text.Blit(text_rt.x + (text_rt.w - text.w()) / 2, text_rt.y - 1);
		cursor.Show();
		display.Flip();
	    }
	    redraw = false;
	}
    }

    cursor.SetThemes(oldcursor);
    cursor.Hide();

    return res.size();
}
int gauge(const char * text, int height, int width, poptContext optCon, int fd, 
		int flags) {
    newtComponent form, scale, tb;
    int top;
    const char * arg;
    char * end;
    int val;
    FILE * f = fdopen(fd, "r");
    char buf[3000];
    char buf3[50];
    int i;

    setlinebuf(f);

    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
    val = strtoul(arg, &end, 10);
    if (*end) return DLG_ERROR;

    tb = textbox(height - 3, width - 2, text, flags, &top);

    form = newtForm(NULL, NULL, 0);

    scale = newtScale(2, height - 2, width - 4, 100);
    newtScaleSet(scale, val);

    newtFormAddComponents(form, tb, scale, NULL);

    newtDrawForm(form);
    newtRefresh();

    while (fgets(buf, sizeof(buf) - 1, f)) {
	buf[strlen(buf) - 1] = '\0';

	if (!strcmp(buf, "XXX")) {
	    fgets(buf3, sizeof(buf3) - 1, f);
	    buf3[strlen(buf3) - 1] = '\0';
	    arg = buf3;

	    i = 0;
	    while (fgets(buf + i, sizeof(buf) - 1 - i, f)) {
		buf[strlen(buf) - 1] = '\0';
		if (!strcmp(buf + i, "XXX")) {
		    *(buf + i) = '\0';
		    break;
		}
		i = strlen(buf);
	    }

	    newtTextboxSetText(tb, buf);
 	} else {
	    arg = buf;
	}

	val = strtoul(buf, &end, 10);
	if (!*end) {
	    newtScaleSet(scale, val);
	    newtDrawForm(form);
	    newtRefresh();
	}
    }

    return DLG_OKAY;
}
int checkList(const char * text, int height, int width, poptContext optCon,
		int useRadio, int flags, char *** selections) {
    newtComponent form, okay, tb, subform, answer;
    newtComponent sb = NULL, cancel = NULL;
    const char * arg;
    char * end;
    int listHeight;
    int numBoxes = 0;
    int allocedBoxes = 5;
    int i;
    int numSelected;
    int rc = DLG_OKAY;
    char buf[80], format[20];
    int maxWidth = 0;
    int top;
    struct {
	const char * text;
	const char * tag;
	newtComponent comp;
    } * cbInfo = malloc(allocedBoxes * sizeof(*cbInfo));
    char * cbStates = malloc(allocedBoxes * sizeof(cbStates));

    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
    listHeight = strtoul(arg, &end, 10);
    if (*end) return DLG_ERROR;

    while ((arg = poptGetArg(optCon))) {
	if (allocedBoxes == numBoxes) {
	    allocedBoxes += 5;
	    cbInfo = realloc(cbInfo, sizeof(*cbInfo) * allocedBoxes);
	    cbStates = realloc(cbStates, sizeof(*cbStates) * allocedBoxes);
	}

	cbInfo[numBoxes].tag = arg;
	if (!(arg = poptGetArg(optCon))) return DLG_ERROR;

	if (!(flags & FLAG_NOITEM)) {
	    cbInfo[numBoxes].text = arg;
	    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
	} else
	    cbInfo[numBoxes].text = "";

	if (!strcmp(arg, "1") || !strcasecmp(arg, "on") || 
		!strcasecmp(arg, "yes"))
	    cbStates[numBoxes] = '*';
	else
	    cbStates[numBoxes] = ' ';

	if (wstrlen(cbInfo[numBoxes].tag,-1) > (unsigned int)maxWidth)
	    maxWidth = wstrlen(cbInfo[numBoxes].tag,-1);

	numBoxes++;
    }

    form = newtForm(NULL, NULL, 0);

    tb = textbox(height - 3 - buttonHeight - listHeight, width - 2,
			text, flags, &top);

    if (listHeight < numBoxes) { 
	sb = newtVerticalScrollbar(width - 4, 
				   top + 1,
				   listHeight, NEWT_COLORSET_CHECKBOX,
				   NEWT_COLORSET_ACTCHECKBOX);
	newtFormAddComponent(form, sb);
    }
    subform = newtForm(sb, NULL, 0);
    newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX);

    sprintf(format, "%%-%ds  %%s", maxWidth);
    for (i = 0; i < numBoxes; i++) {
	sprintf(buf, format, cbInfo[i].tag, cbInfo[i].text);

	if (useRadio)
	    cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf,
					cbStates[i] != ' ', 
					i ? cbInfo[i - 1].comp : NULL);
	else
	    cbInfo[i].comp = newtCheckbox(4, top + 1 + i, buf,
			      cbStates[i], NULL, cbStates + i);

	newtFormAddComponent(subform, cbInfo[i].comp);
    }

    newtFormSetHeight(subform, listHeight);
    newtFormSetWidth(subform, width - 10);

    newtFormAddComponents(form, tb, subform, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    if (useRadio) {
	answer = newtRadioGetCurrent(cbInfo[0].comp);
	for (i = 0; i < numBoxes; i++) 
	    if (cbInfo[i].comp == answer) {
		*selections = malloc(sizeof(char *) * 2);
		(*selections)[0] = cbInfo[i].tag;
		(*selections)[1] = NULL;
		break;
	    }
    } else {
	numSelected = 0;
	for (i = 0; i < numBoxes; i++) {
	    if (cbStates[i] != ' ') numSelected++;
	}

	*selections = malloc(sizeof(char *) * (numSelected + 1));

	numSelected = 0;
	for (i = 0; i < numBoxes; i++) {
	    if (cbStates[i] != ' ') 
		(*selections)[numSelected++] = cbInfo[i].tag;
	}

	(*selections)[numSelected] = NULL;
    }

    return rc;
}
int listBox(const char * text, int height, int width, poptContext optCon,
		int flags, char ** result) {
    newtComponent form, okay, tb, answer, listBox;
    newtComponent cancel = NULL;
    const char * arg;
    char * end;
    int listHeight;
    int numItems = 0;
    int allocedItems = 5;
    int i, top;
    int rc = DLG_OKAY;
    char buf[80], format[20];
    int maxTagWidth = 0;
    int maxTextWidth = 0;
    int scrollFlag;
    struct {
	const char * text;
	const char * tag;
    } * itemInfo = malloc(allocedItems * sizeof(*itemInfo));

    if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
    listHeight = strtoul(arg, &end, 10);
    if (*end) return DLG_ERROR;

    while ((arg = poptGetArg(optCon))) {
	if (allocedItems == numItems) {
	    allocedItems += 5;
	    itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems);
	}

	itemInfo[numItems].tag = arg;
	if (!(arg = poptGetArg(optCon))) return DLG_ERROR;

	if (!(flags & FLAG_NOITEM)) {
	    itemInfo[numItems].text = arg;
	} else
	    itemInfo[numItems].text = "";

	if (wstrlen(itemInfo[numItems].text,-1) > (unsigned int)maxTextWidth)
	    maxTextWidth = wstrlen(itemInfo[numItems].text,-1);
	if (wstrlen(itemInfo[numItems].tag,-1) > (unsigned int)maxTagWidth)
	    maxTagWidth = wstrlen(itemInfo[numItems].tag,-1);

	numItems++;
    }

    form = newtForm(NULL, NULL, 0);

    tb = textbox(height - 4 - buttonHeight - listHeight, width - 2,
			text, flags, &top);

    if (listHeight >= numItems) {
	scrollFlag = 0;
	i = 0;
    } else {
	scrollFlag = NEWT_FLAG_SCROLL;
	i = 2;
    }

    listBox = newtListbox(3 + ((width - 10 - maxTagWidth - maxTextWidth - i) 
					/ 2),
			  top + 1, listHeight, 
			    NEWT_FLAG_RETURNEXIT | scrollFlag);

    sprintf(format, "%%-%ds  %%s", maxTagWidth);
    for (i = 0; i < numItems; i++) {
	sprintf(buf, format, itemInfo[i].tag, itemInfo[i].text);
	newtListboxAddEntry(listBox, buf, (void *) i);
    }

    newtFormAddComponents(form, tb, listBox, NULL);

    addButtons(height, width, form, &okay, &cancel, flags);

    answer = newtRunForm(form);
    if (answer == cancel)
	rc = DLG_CANCEL;

    i = (int) newtListboxGetCurrent(listBox);
    *result = itemInfo[i].tag;

    return rc;
}
int Dialog::ArmyJoinWithCost(const Troop & troop, u32 join, u32 gold, Heroes & hero)
{
    Display & display = Display::Get();
    const Settings & conf = Settings::Get();

    // cursor
    Cursor & cursor = Cursor::Get();
    int oldthemes = cursor.Themes();
    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    std::string message;

    if(troop.GetCount() == 1)
	message = _("The creature is swayed by your diplomatic tongue, and offers to join your army for the sum of %{gold} gold.\nDo you accept?");
    else
    {
        message = _("The creatures are swayed by your diplomatic\ntongue, and make you an offer:\n \n");

        if(join != troop.GetCount())
    	    message += _("%{offer} of the %{total} %{monster} will join your army, and the rest will leave you alone, for the sum of %{gold} gold.\nDo you accept?");
        else
    	    message += _("All %{offer} of the %{monster} will join your army for the sum of %{gold} gold.\nDo you accept?");
    }

    StringReplace(message, "%{offer}", join);
    StringReplace(message, "%{total}", troop.GetCount());
    StringReplace(message, "%{monster}", StringLower(troop.GetPluralName(join)));
    StringReplace(message, "%{gold}", gold);

    TextBox textbox(message, Font::BIG, BOXAREA_WIDTH);
    const int buttons = Dialog::YES | Dialog::NO;
    const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 6);
    int posy = 0;
    Text text;

    message = _("(Rate: %{percent})");
    StringReplace(message, "%{percent}", troop.GetMonster().GetCost().gold * join * 100 / gold);
    text.Set(message, Font::BIG);

    FrameBox box(10 + textbox.h() + 10 + text.h() + 40 + sprite.h() + 10, buttons);
    const Rect & pos = box.GetArea();

    posy = pos.y + 10;
    textbox.Blit(pos.x, posy);

    posy += textbox.h() + 10;
    text.Blit(pos.x + (pos.w - text.w()) / 2, posy);


    posy += text.h() + 40;
    sprite.Blit(pos.x + (pos.w - sprite.w()) / 2, posy);

    TextSprite tsTotal(GetString(gold) + " " + "(" + "total: " + GetString(world.GetKingdom(hero.GetColor()).GetFunds().Get(Resource::GOLD)) + ")", Font::SMALL,
	    pos.x + (pos.w - text.w()) / 2, posy + sprite.h() + 5);
    tsTotal.Show();

    ButtonGroups btnGroups(pos, buttons);
    Button btnMarket(pos.x + pos.w / 2 - 60 - 36, posy, (conf.ExtGameEvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS), 4, 5);
    Button btnHeroes(pos.x + pos.w / 2 + 60, posy, (conf.ExtGameEvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS), 0, 1);
    const Kingdom & kingdom = hero.GetKingdom();

    if(! kingdom.AllowPayment(payment_t(Resource::GOLD, gold)))
	btnGroups.DisableButton1(true);

    TextSprite tsEnough;

    if(kingdom.GetCountMarketplace())
    {
	if(kingdom.AllowPayment(payment_t(Resource::GOLD, gold)))
	    btnMarket.SetDisable(true);
	else
	{
	    std::string msg = _("Not enough gold (%{gold})");
	    StringReplace(msg, "%{gold}", gold - kingdom.GetFunds().Get(Resource::GOLD));
	    tsEnough.SetText(msg, Font::YELLOW_SMALL);
	    tsEnough.SetPos(btnMarket.x - 25, btnMarket.y - 17);
	    tsEnough.Show();
	    btnMarket.Draw();
	}
    }

    if(hero.GetArmy().GetCount() < hero.GetArmy().Size() || hero.GetArmy().HasMonster(troop))
	btnHeroes.SetDisable(true);
    else
    {
	TextBox textbox2(_("Not room in\nthe garrison"), Font::SMALL, 100);
	textbox2.Blit(btnHeroes.x - 35, btnHeroes.y - 30);
	btnHeroes.Draw();

	btnGroups.DisableButton1(true);
    }

    btnGroups.Draw();
    cursor.Show();
    display.Flip();

    LocalEvent & le = LocalEvent::Get();

    // message loop
    int result = Dialog::ZERO;

    while(result == Dialog::ZERO && le.HandleEvents())
    {
	if(btnMarket.isEnable())
    	    le.MousePressLeft(btnMarket) ? btnMarket.PressDraw() : btnMarket.ReleaseDraw();

	if(btnHeroes.isEnable())
    	    le.MousePressLeft(btnHeroes) ? btnHeroes.PressDraw() : btnHeroes.ReleaseDraw();

        if(!buttons && !le.MousePressRight()) break;

        result = btnGroups.QueueEventProcessing();

	if(btnMarket.isEnable() && le.MouseClickLeft(btnMarket))
	{
	    Marketplace(false);

	    cursor.Hide();
	    tsTotal.Hide();
	    tsTotal.SetText(GetString(gold) + " " + "(" + "total: " + GetString(world.GetKingdom(hero.GetColor()).GetFunds().Get(Resource::GOLD)) + ")");
	    tsTotal.Show();

	    if(kingdom.AllowPayment(payment_t(Resource::GOLD, gold)))
	    {
		tsEnough.Hide();
    		btnGroups.DisableButton1(false);
		btnGroups.Draw();
	    }
	    else
	    {
		tsEnough.Hide();
		std::string msg = _("Not enough gold (%{gold})");
		StringReplace(msg, "%{gold}", gold - kingdom.GetFunds().Get(Resource::GOLD));
		tsEnough.SetText(msg, Font::SMALL);
		tsEnough.Show();
	    }

	    cursor.Show();
	    display.Flip();
	}
	else
	if(btnHeroes.isEnable() && le.MouseClickLeft(btnHeroes))
	{
	    hero.OpenDialog(false, false);

	    if(hero.GetArmy().GetCount() < hero.GetArmy().Size())
	    {
    		btnGroups.DisableButton1(false);
		btnGroups.Draw();
	    }

	    cursor.Show();
	    display.Flip();
	}
    }

    cursor.Hide();
    cursor.SetThemes(oldthemes);
    cursor.Show();

    return result;
}
Example #17
0
void hbb::draw_full_ui_from_state(ListingDrawState const& state) {
    u8* fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
    draw_solid_background(fb, 240 * 320, 216, 201, 201);

    draw_ui_element(fb, state.category == SelectedCategory::kGames ? ListingUIElements::kGamesLight : ListingUIElements::kGamesDark);
    draw_ui_element(fb, state.category == SelectedCategory::kMedia ? ListingUIElements::kMediaLight : ListingUIElements::kMediaDark);
    draw_ui_element(fb, state.category == SelectedCategory::kEmulators ? ListingUIElements::kEmulatorsLight : ListingUIElements::kEmulatorsDark);
    draw_ui_element(fb, state.category == SelectedCategory::kTools ? ListingUIElements::kToolsLight : ListingUIElements::kToolsDark);
    draw_ui_element(fb, state.category == SelectedCategory::kMisc ? ListingUIElements::kMiscLight : ListingUIElements::kMiscDark);

    //Draw base graphics, based on selected state
    if (state.visible_titles[0].displayed == ListingTitleDisplay::kVisible) {
      draw_ui_element(fb, state.selected_title == 0 ? ListingUIElements::kTopRowDark : ListingUIElements::kTopRowLight);
    }
    if (state.visible_titles[1].displayed == ListingTitleDisplay::kVisible) {
      draw_ui_element(fb, state.selected_title == 1 ? ListingUIElements::kMiddleRowDark : ListingUIElements::kMiddleRowLight);
    }
    if (state.visible_titles[2].displayed == ListingTitleDisplay::kVisible) {
      draw_ui_element(fb, state.selected_title == 2 ? ListingUIElements::kBottomRowDark : ListingUIElements::kBottomRowLight);      
    }

    //Populate rows with title information
    const u32 kRowOffset = 71;
    for (int row = 0; row < 3; row++) {
      if (state.visible_titles[row].displayed == ListingTitleDisplay::kVisible) {
        draw_raw_sprite(state.visible_titles[row].icon, fb, 
            61, 13 + row * kRowOffset, 48, 48);
        _putnchar(fb, 121, 4 + row * kRowOffset, title_font,
            state.visible_titles[row].title.c_str(),
            state.visible_titles[row].title.size());
        textbox(fb, 121, 20 + row * kRowOffset, 177, 49, 12, description_font, 
            state.visible_titles[row].description);
        _putnchar_r(fb, 296, 55 + row * kRowOffset, author_font, 
            state.visible_titles[row].author.c_str(), 
            state.visible_titles[row].author.size());
      }
    }

    //Indicate owned titles (this is done last for layering reasions; we want this always on top)
    if (state.visible_titles[0].owned and 
        state.visible_titles[0].displayed == ListingTitleDisplay::kVisible) {
      draw_ui_element(fb, ListingUIElements::kTopOwnedIcon);
    }
    if (state.visible_titles[1].owned and 
        state.visible_titles[1].displayed == ListingTitleDisplay::kVisible) {
      draw_ui_element(fb, ListingUIElements::kMiddleOwnedIcon);
    }
    if (state.visible_titles[2].owned and 
        state.visible_titles[2].displayed == ListingTitleDisplay::kVisible) {
      draw_ui_element(fb, ListingUIElements::kBottomOwnedIcon);
    }

    draw_ui_element(fb, ListingUIElements::kUIBar);
    if (state.sort_order == ListingSortOrder::kAlphanumericDescending) {
      draw_ui_element(fb, ListingUIElements::kSortReversed);
    }

    if (state.scrollbar.displayed == ListingScrollbarDisplay::kVisible) {
      UIElement const& data = g_listing_ui_elements[static_cast<size_t>(
        state.scrollbar.active ? ListingUIElements::kScrollBarActive
        : ListingUIElements::kScrollBar)];
      // Range is [3,153], total of 150 potential values
      // percentage / 100 = position / potential
      // percentage / 100 * potential = position
      // Reorder the multiply and divide so that integer truncation is not an issue.
      s32 const scroll_offset = state.scrollbar.percentage * 150 / 100;
      draw_sprite(data.image, fb, data.x, data.y + scroll_offset);
    }
}
Example #18
0
//Renders the map according to data
void renderMap()
{
    COORD c;
    std::cout << std::endl;
    std::cout << std::endl;
    for (int i = 0; i < MAP_HEIGHT; i++){
        c.Y = i;
        for (int j = 0; j < MAP_WIDTH; j++){
            c.X = j;
            // Wall
            if (printMap[i][j] == 1){
                console.writeToBuffer(c, '|', 0x03);
            }
			// Lava
            else if (printMap[i][j] == 2){
                console.writeToBuffer(c, (char)247, 0x0C);
            }
			// Cobweb
            else if (printMap[i][j] == 3){
                console.writeToBuffer(c, 'X');
            }
			// Ammo for warrior
            else if (printMap[i][j] == 4){
                console.writeToBuffer(c, (char)236, 0x0B);
            }
			// Door
            else if (printMap[i][j] == 5){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // Bomb
            else if (printMap[i][j] == 6){
                console.writeToBuffer(c, (char)235, 0x0B);
            }
            // Ammo
            else if (printMap[i][j] == 7){
                console.writeToBuffer(c, (char)240, 0x0B);
            }
            // Health
            else if (printMap[i][j] == 8){
                console.writeToBuffer(c, (char)3, 0x0C);
            }
            // Spawn points
            else if (printMap[i][j] == 9){
                console.writeToBuffer(c, (char)241);
            }
            // From A - E & K, Map doors
            // Door A
            else if (printMap[i][j] == 'A'){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // Door B
            else if (printMap[i][j] == 'B'){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // Door C
            else if (printMap[i][j] == 'C'){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // Door D
            else if (printMap[i][j] == 'D'){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // Door E
            else if (printMap[i][j] == 'E'){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // Door K
            else if (printMap[i][j] == 'K'){
                console.writeToBuffer(c, (char)239, 0x0B);
            }
            // From Y - P, tutorial
            // Moving traps
            else if (printMap[i][j] == 'Z') {
                console.writeToBuffer(c, '*', 0x0E);
            }
            // Monster spawner
			else if (printMap[i][j] == 'Y') {
				console.writeToBuffer(c, (char)241);
			}
            // Health pack
			else if (printMap[i][j] == 'X') {
				console.writeToBuffer(c, (char)3, 0x0C);
			}
            // Ammo pack
			else if (printMap[i][j] == 'W') {
                console.writeToBuffer(c, (char)240, 0x0B);
			}
            // Bomb
			else if (printMap[i][j] == 'V') {
                console.writeToBuffer(c, (char)235, 0x0B);
			}
            // Super ghost
			else if (printMap[i][j] == 'U') {
				console.writeToBuffer(c, (char)69, 0x0A);
			}
            // Ghost
			else if (printMap[i][j] == 'T') {
				console.writeToBuffer(c, (char)69, 0x0E);
			}
            // Cobweb
			else if (printMap[i][j] == 'S') {
				console.writeToBuffer(c, 'X');
			}
            // Lava
			else if (printMap[i][j] == 'R') {
				console.writeToBuffer(c, (char)247, 0x0C);
			}
            // Wall
			else if (printMap[i][j] == 'Q') {
				console.writeToBuffer(c, '|', 0x03);
			}
            // Path for tutorial
			else if (printMap[i][j] == 'P') {
				console.writeToBuffer(c, ' ' , 0x03);
			}
            // Boss
            else if (printMap[i][j] == 'I') {
                console.writeToBuffer(c, (char)154, 0x0C);
            }
            else{
                console.writeToBuffer(c, " ");
            }
        }
        std::cout << std::endl;
    }
	textbox();      // Description for tutorial
	minimap();      // Minimap for gameplay
	HUD();          // HUD for gameplay
	
}
Example #19
0
Skill::Primary::skill_t Dialog::SelectSkillFromArena(void)
{
    Display & display = Display::Get();
    const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM;

    // cursor
    Cursor & cursor = Cursor::Get();
    Cursor::themes_t oldthemes = cursor.Themes();
    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    TextBox textbox(_("You enter the arena and face a pack of vicious lions. You handily defeat them, to the wild cheers of the crowd.  Impressed by your skill, the aged trainer of gladiators agrees to train you in a skill of your choice."), Font::BIG, BOXAREA_WIDTH);
    const Sprite & sprite = AGG::GetICN(ICN::XPRIMARY, 0);
    const u8 spacer = Settings::Get().QVGA() ? 5 : 10;

    Dialog::FrameBox box(textbox.h() + spacer + sprite.h() + 15, true);

    const Rect & box_rt = box.GetArea();
    Point dst_pt = box_rt;

    textbox.Blit(dst_pt);
    dst_pt.y += textbox.h() + spacer;

    Skill::Primary::skill_t  res = Skill::Primary::ATTACK;
    Rect rect1, rect2, rect3, rect4;

    if(Settings::Get().ExtHeroArenaCanChoiseAnySkills())
    {
	rect1 = Rect(dst_pt.x + box_rt.w / 2 - 2 * sprite.w() - 30, dst_pt.y, sprite.w(), sprite.h());
	rect2 = Rect(dst_pt.x + box_rt.w / 2 - sprite.w() - 10, dst_pt.y, sprite.w(), sprite.h());
	rect3 = Rect(dst_pt.x + box_rt.w / 2 + 10, dst_pt.y, sprite.w(), sprite.h());
	rect4 = Rect(dst_pt.x + box_rt.w / 2 + sprite.w() + 30, dst_pt.y, sprite.w(), sprite.h());
    }
    else
    {
	rect1 = Rect(dst_pt.x + box_rt.w / 2 - 2 * sprite.w() - 10, dst_pt.y, sprite.w(), sprite.h());
	rect2 = Rect(dst_pt.x + box_rt.w / 2 - sprite.w() + 15, dst_pt.y, sprite.w(), sprite.h());
	rect3 = Rect(dst_pt.x + box_rt.w / 2 + 40, dst_pt.y, sprite.w(), sprite.h());
    }

    InfoSkillClear(rect1, rect2, rect3, rect4);
    InfoSkillSelect(res, rect1, rect2, rect3, rect4);

    // info texts
    Text text(Skill::Primary::String(Skill::Primary::ATTACK), Font::SMALL);
    dst_pt.x = rect1.x + (rect1.w - text.w()) / 2;
    dst_pt.y = rect1.y + rect1.h + 5;
    text.Blit(dst_pt);

    text.Set(Skill::Primary::String(Skill::Primary::DEFENSE));
    dst_pt.x = rect2.x + (rect2.w - text.w()) / 2;
    dst_pt.y = rect2.y + rect2.h + 5;
    text.Blit(dst_pt);

    text.Set(Skill::Primary::String(Skill::Primary::POWER));
    dst_pt.x = rect3.x + (rect3.w - text.w()) / 2;
    dst_pt.y = rect3.y + rect3.h + 5;
    text.Blit(dst_pt);

    if(Settings::Get().ExtHeroArenaCanChoiseAnySkills())
    {
	text.Set(Skill::Primary::String(Skill::Primary::KNOWLEDGE));
	dst_pt.x = rect4.x + (rect4.w - text.w()) / 2;
	dst_pt.y = rect4.y + rect4.h + 5;
	text.Blit(dst_pt);
    }

    // buttons
    dst_pt.x = box_rt.x + (box_rt.w - AGG::GetICN(system, 1).w()) / 2;
    dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h();
    Button buttonOk(dst_pt.x, dst_pt.y, system, 1, 2);

    LocalEvent & le = LocalEvent::Get();
    bool redraw = false;

    buttonOk.Draw();
    cursor.Show();
    display.Flip();

    // message loop
    while(le.HandleEvents())
    {
	le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();

	if(Game::HotKeyPress(Game::EVENT_DEFAULT_LEFT) && Skill::Primary::UNKNOWN != InfoSkillPrev(res))
	{
	    res = InfoSkillPrev(res);
	    redraw = true;
	}
	else
	if(Game::HotKeyPress(Game::EVENT_DEFAULT_RIGHT) && Skill::Primary::UNKNOWN != InfoSkillNext(res))
	{
	    res = InfoSkillNext(res);
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(rect1))
	{
	    res = Skill::Primary::ATTACK;
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(rect2))
	{
	    res = Skill::Primary::DEFENSE;
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(rect3))
	{
	    res = Skill::Primary::POWER;
	    redraw = true;
	}
	else
	if(Settings::Get().ExtHeroArenaCanChoiseAnySkills() && le.MouseClickLeft(rect4))
	{
	    res = Skill::Primary::KNOWLEDGE;
	    redraw = true;
	}

	if(redraw)
	{
	    cursor.Hide();
	    InfoSkillClear(rect1, rect2, rect3, rect4);
	    InfoSkillSelect(res, rect1, rect2, rect3, rect4);
	    cursor.Show();
	    display.Flip();
	    redraw = false;
	}

        if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)) break;
    }

    cursor.Hide();
    cursor.SetThemes(oldthemes);
    cursor.Show();

    return res;
}
Example #20
0
bool add_high_score(u32 score, Font *font, Font *keyboard_font) {
	if (!is_high_score(score)) {
		return false;
	}

	RRKeyboard keyboard(options.full_path("keyboards/default.kb"), &screen_bottom, keyboard_font, 17, 100);
	Textbox textbox(&screen_bottom, font);

	textbox.set_x(5);
	textbox.set_y(60);
	textbox.set_dimensions(240, 22);
	textbox.set_value("");

	keyboard.draw();
	textbox.draw(true);

	font->print_string("You've got a top-10 high", 10, 10, &screen_bottom, RGB(31, 15, 0));
	font->print_string("score! Please enter your", 10, 25, &screen_bottom, RGB(31, 15, 0));
	font->print_string("name. (Press A to skip.)", 10, 40, &screen_bottom, RGB(31, 15, 0));

	char name[256] = "";
	touchPosition stylus;
	char key;
	u8 name_index = 0;

	while (1) {
		scanKeys();
		touchRead(&stylus);

		if ((key = keyboard.key_pressed(stylus))) {
			while (keysHeld() & KEY_TOUCH) { scanKeys(); swiWaitForVBlank(); }

			if (key == '\n') {
				break;
			} else if (key == '\b') {
				if (name_index) {
					name_index--;
					name[name_index] = '\0';
					textbox.set_value(name);
				}
			} else {
				name[name_index] = key;
				name_index++;
				textbox.set_value(name);
			}
		}

		textbox.draw(true);

		swiWaitForVBlank();
	}

	load_high_scores();

	for (u8 i = 0; i <= num_high_scores; i++) {
		if (i == num_high_scores || score > high_scores[i].score) {
			for (u8 j = num_high_scores; j > i; j--) {
				if (j < MAX_HIGH_SCORES) {
					strcpy(high_scores[j].name, high_scores[j - 1].name);
					high_scores[j].score = high_scores[j - 1].score;
				}
			}

			strcpy(high_scores[i].name, name);
			high_scores[i].score = score;

			num_high_scores++;

			break;
		}
	}

	save_high_scores();

	return true;
}