void MemberExpiration::render_main(zr_window *window)
{

	zr_context context;
	zr_context layout;
	zr_begin(&context, window);
	{
		zr_header(&context, "Get member expiration", 0, 0, ZR_HEADER_LEFT);
		zr_layout_row_dynamic(&context, 30, 1);
		zr_label(&context, "Please select a month:", ZR_TEXT_LEFT);

		zr_label(&context, "Months:", ZR_TEXT_LEFT);
		zr_layout_row_dynamic(&context, 30, 3);
		zr_combo_begin(&context, &layout, patch::to_string(months[selected]).c_str(), &active);
		{
			zr_layout_row_dynamic(&layout, 25, 3);
			for (int i = 0; i < size; ++i) {
				if (selected == i) continue;
				if (zr_combo_item(&layout, ZR_TEXT_LEFT, patch::to_string(months[i]).c_str())) {
					selected = i;
				}
			}
		}
		zr_combo_end(&context, &layout, &active);

		for(int i = 0; i < *num_members; i++)
		{
			if(members[i]->expiration_date.month == (selected + 1))
			{
				zr_layout_row_dynamic(&context, 30, 2);
				zr_label(&context, ("Member Name: " + members[i]->name).c_str(), ZR_TEXT_LEFT);
				if(members[i]->member_type == 1)
					zr_label(&context, "Renewal Cost: $111.00", ZR_TEXT_LEFT);
				else
					zr_label(&context, "Renewal Cost: $55.00", ZR_TEXT_LEFT);
			}
		}

		zr_layout_row_static(&context, 30, 240, 6);
		if (zr_button_text(&context, "Back", ZR_BUTTON_DEFAULT)) { changeWindow(MAIN);}

	}
	zr_end(&context, window);
}
Exemple #2
0
void AddItem::render_main(zr_window *window){
	zr_context context;
	zr_context layout;
	zr_begin(&context, window);
	{
		if(state == 0) {
			zr_header(&context, "Add and Delete Item", 0, 0, ZR_HEADER_LEFT);

			zr_layout_row_static(&context, 30, 240, 3);
			if (zr_button_text(&context, "Add Item", ZR_BUTTON_DEFAULT)) {
				state = 1;
				fail = 0;
			}
			if (zr_button_text(&context, "Delete Item", ZR_BUTTON_DEFAULT)) {
				state = 2;
				fail = 0;
			}

			for (int i = 0; i < 12; i++)
			zr_layout_row_static(&context, 30, 240, 1);
			zr_layout_row_static(&context, 30, 240, 6);
			if (zr_button_text(&context, "Back", ZR_BUTTON_DEFAULT)) { changeWindow(MAIN);}
		} else if(state == 1) {
			zr_header(&context, "Add Item", 0, 0, ZR_HEADER_LEFT);
			zr_layout_row_dynamic(&context, 30, 1);
			if (fail == 1) zr_label(&context, "Error! Item name is empty", ZR_TEXT_LEFT);
			if (fail == 2) zr_label(&context, "Error! Dollar is empty (is it empty? does it contain regular characters?)", ZR_TEXT_LEFT);
			if (fail == 3) zr_label(&context, "Error! Cents is empty", ZR_TEXT_LEFT);
			if (fail == 5) zr_label(&context, "Error! Cents is longer then two characters", ZR_TEXT_LEFT);
			if (fail == 4) zr_label(&context, "Created Item successfully!", ZR_TEXT_LEFT);
			zr_layout_row_dynamic(&context, 30, 1);
			zr_label(&context, "Please input the necessary data to create an item:", ZR_TEXT_LEFT);
			zr_layout_row_static(&context, 30, 240, 3);
			zr_label(&context, "Item Name:", ZR_TEXT_LEFT);
			zr_editbox(&context, eb[ITEM]);
			zr_layout_row_static(&context, 30, 240, 3);
			zr_label(&context, "Dollars:", ZR_TEXT_LEFT);
			zr_editbox(&context, eb[DOLLAR]);
			zr_layout_row_static(&context, 30, 240, 3);
			zr_label(&context, "Cents:", ZR_TEXT_LEFT);
			zr_editbox(&context, eb[CENTS]);

			for (int i = 0; i < 8; i++)
			zr_layout_row_static(&context, 30, 240, 1);
			zr_layout_row_static(&context, 30, 240, 6);
			if (zr_button_text(&context, "Submit", ZR_BUTTON_DEFAULT)) {
				if (eb[ITEM]->glyphes == 0) fail = 1;
				else if (eb[DOLLAR]->glyphes == 0) fail = 2;
				else if (eb[CENTS]->glyphes == 0) fail =3;
				else {
					// Dollars
					char *arrD = static_cast<char* >(eb[DOLLAR]->buffer.memory.ptr);
					char *arrC = static_cast<char* >(eb[CENTS]->buffer.memory.ptr);
					int iteratorD = 0, multD = eb[DOLLAR]->glyphes - 1, retD = 0;
					int iteratorC = 0, multC = eb[CENTS]->glyphes - 1, retC = 0;

					while (iteratorD < eb[DOLLAR]->glyphes && arrD[iteratorD] >= 48 && arrD[iteratorD] <= 57) {
						retD += int(arrD[iteratorD] - 48) * round(pow(10, multD));
						multD--;
						iteratorD++;
					}

					while (iteratorC < eb[CENTS]->glyphes && arrC[iteratorC] >= 48 && arrC[iteratorC] <= 57) {
						retC += int(arrC[iteratorC] - 48) * round(pow(10, multC));
						multC--;
						iteratorC++;
					}

					if (eb[DOLLAR]->glyphes <= 0) {
						fail = 2;
					} else if (eb[CENTS]->glyphes <= 0) {
						fail = 3;
					} else if (eb[CENTS]->glyphes > 2) {
						fail = 5;
					} else {
						fail = 4;
						int iterator = 0;
						Item** temp = items;
						*num_items += 1;
						Item** temp2 = new Item*[*num_items];
						for (int i = 0; i < *num_items - 1; i++){
							temp2[i] = new Item();
							temp2[i]->item_name = temp[i]->item_name;
							temp2[i]->price.cents = temp[i]->price.cents;
							temp2[i]->price.dollars = temp[i]->price.dollars;
							temp2[i]->quantity_sold = temp[i]->quantity_sold;
						}
						temp2[*num_items - 1] = new Item();
						temp2[*num_items - 1]->item_name = string(static_cast<char *>(eb[ITEM]->buffer.memory.ptr));
						temp2[*num_items - 1]->price.dollars = retD;
						temp2[*num_items - 1]->price.cents = retC;
						temp2[*num_items - 1]->quantity_sold = 0;

						for(int i = 0; i < num_days; i++)
						{
							for(int j = 0; j < purchases_a_day[i]; j++)
							{
								iterator = 0;
								while (iterator < *num_items && trips[i][j].item->item_name != temp2[iterator]->item_name) {
									iterator++;
								}
								trips[i][j].item = temp2[iterator];
							}
						}
						items = temp2;
						for (int i = 0; i < *num_items - 1; i++) delete temp[i];
						delete [] temp;
						issue_update(); //super important!
					}
				}
			}
			if (zr_button_text(&context, "Back", ZR_BUTTON_DEFAULT)) {
				state = 0;
				fail = 0;
			}
		} else if (state == 2) {
			zr_header(&context, "Delete Item", 0, 0, ZR_HEADER_LEFT);
			zr_layout_row_static(&context, 30, 240, 3);
			if (zr_button_text(&context, "Search by item name", ZR_BUTTON_DEFAULT)) {
				state = 3;
				fail = 0;
			}
			for (int i = 0; i < 12; i++)
			zr_layout_row_static(&context, 30, 240, 1);
			zr_layout_row_static(&context, 30, 240, 6);
			if (zr_button_text(&context, "Back", ZR_BUTTON_DEFAULT)) {
				state = 0;
				fail = 0;
			}
		} else if(state == 3) {
			zr_header(&context, "Delete Item", 0, 0, ZR_HEADER_LEFT);
			zr_layout_row_dynamic(&context, 30, 1);
			if (fail == 1) zr_label(&context, "Error! Empty field", ZR_TEXT_LEFT);
			if (fail == 2) zr_label(&context, "Error! Could not find item", ZR_TEXT_LEFT);
			if (fail == 3) zr_label(&context, "Success! Deleted item", ZR_TEXT_LEFT); //not really a fail
			zr_layout_row_dynamic(&context, 30, 1);
			zr_label(&context, "Please input an item:", ZR_TEXT_LEFT);
			zr_layout_row_static(&context, 30, 240, 3);
			zr_editbox(&context, eb[S_ITEM]);
			zr_layout_row_dynamic(&context, 30, 6);
			if (zr_button_text(&context, "Submit", ZR_BUTTON_DEFAULT)) {
				if (eb[S_ITEM]->glyphes != 0) {
					int iterator = 0, iterator2 = 0;
					char *arr = static_cast<char* >(eb[S_ITEM]->buffer.memory.ptr);
					while (iterator < *num_items) {
						if (eb[S_ITEM]->glyphes != items[iterator]->item_name.size()) {
							iterator++;
							continue;
						}
						while (iterator2 < eb[S_ITEM]->glyphes && arr[iterator2] == items[iterator]->item_name[iterator2]) iterator2++;
						if (iterator2 >= eb[S_ITEM]->glyphes) break;
						iterator2 = 0;
						iterator++;
					}
					if (iterator >= *num_items) {
						fail = 2;
					} else {
						fail = 3;
						items[iterator]->deleted = true;
						issue_update(); //super important!
					}
				} else {
					fail = 1;
				}
				zr_layout_row_static(&context, 30, 240, 1);
				zr_layout_row_static(&context, 30, 240, 6);
				if (zr_button_text(&context, "Back", ZR_BUTTON_DEFAULT)) { changeWindow(MAIN);}
			}
			for (int i = 0; i < 9; i++)
			zr_layout_row_static(&context, 30, 240, 1);
			zr_layout_row_static(&context, 30, 240, 6);
			if (zr_button_text(&context, "Back", ZR_BUTTON_DEFAULT)) { changeWindow(MAIN);}
		}
	}
	zr_end(&context, window);
}
Exemple #3
0
void AddUser::render_main(zr_window *window) {
	zr_context context;
	zr_begin(&context, window);
	{
		static const char *ratings[] = { "very interested",
				"somewhat interested", "not interested", "never call again" };
		zr_header(&context, "Add Customer", 0, 0, ZR_HEADER_LEFT);
		zr_layout_row_dynamic(&context, 30, 1);
		zr_label(&context, "Note: Username and Password will be auto-generated "
				"upon adding customer if fields left empty", ZR_TEXT_LEFT);

		// name box
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Name:", ZR_TEXT_LEFT);
		zr_editbox(&context, &nameBox);
		if (isNameDuplicate) {
			zr_label(&context, "Could not add: Name already exists",
					ZR_TEXT_LEFT);
		} else if (isNameEmpty) {
			zr_label(&context, "Could not add: Please enter a name",
					ZR_TEXT_LEFT);
		}

		// street box
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Street:", ZR_TEXT_LEFT);
		zr_editbox(&context, &streetBox);
		if (isStreetEmpty) {
			zr_label(&context, "Could not add: Please enter an address",
					ZR_TEXT_LEFT);
		}

		// state zipcode box
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "State and Zip Code:", ZR_TEXT_LEFT);
		zr_editbox(&context, &stateZipCodeBox);
		if (isStateEmpty) {
			zr_label(&context, "Could not add: Please enter an address",
					ZR_TEXT_LEFT);
		}

		// username box
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Username:"******"Could not add: Username already exists",
					ZR_TEXT_LEFT);
		}
		else if (isUsernameInvalid) {
			zr_label(&context, "Could not add: Spaces disallowed",
					ZR_TEXT_LEFT);
		}

		// password box
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Password:"******"Could not add: Spaces disallowed",
					ZR_TEXT_LEFT);
		}

		// product spinners
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Minimal Packages:", ZR_TEXT_LEFT);
		zr_spinner_int(&context, 0, &product1Value, 9999, 1, &product1State);

		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Extreme Packages:", ZR_TEXT_LEFT);
		zr_spinner_int(&context, 0, &product2Value, 9999, 1, &product2State);

		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Ultimate Packages:", ZR_TEXT_LEFT);
		zr_spinner_int(&context, 0, &product3Value, 9999, 1, &product3State);

		// Rating drop down menu
		zr_layout_row_static(&context, 30, 240, 3);
		zr_label(&context, "Rating: ", ZR_TEXT_LEFT);
		zr_combo_begin(&context, &ratingComboBox, ratings[currentRatingInt],
				&ratingComboBoxState);
		{
			zr_layout_row_dynamic(&ratingComboBox, 25, 1);
			for (int i = 0; i < 4; i++) {
				if (zr_combo_item(&ratingComboBox, ratings[i], ZR_TEXT_LEFT)) {
					currentRatingInt = i;
				}
			}
		}
		zr_combo_end(&context, &ratingComboBox, &ratingComboBoxState);

		// Received Pamphlet and Key Customer Box checkboxes
		zr_layout_row_static(&context, 30, 240, 3);
		zr_checkbox(&context, "Requested Pamphlet", &isPamphletBoxUnTicked);
		zr_checkbox(&context, "Key Customer", &isKeyBoxUnTicked);

		// submit box row
		zr_layout_row_dynamic(&context, 30, 1);
		if (zr_button_text(&context, "Submit", ZR_BUTTON_DEFAULT)) {
			// initialize
			isNewCustomerAdded = false;
			isNameDuplicate = false;
			isNameEmpty = false;
			isInvalidCustomer = false;
			isNameEmpty = false;
			isStateEmpty = false;
			isStreetEmpty = false;
			isUsernameDuplicate = false;
			isUsernameInvalid = false;
			isPasswordInvalid = false;
			name = "";
			street = "";
			stateZipCode = "";
			username = "";
			password = "";

			// get the characters in the name box
			for (unsigned int i = 0; i < nameBox.glyphes; i++) {
				name += ((char*) nameBox.buffer.memory.ptr)[i];
			}
			// trim spaces
			name = trimSpaces(name);
			// check if name empty
			if (name.length() == 0) {
				isNameEmpty = true;
				isInvalidCustomer = true;
			} else {
				// else search for duplicates
				SearchCustomerVector = *customers;
				while (!SearchCustomerVector.empty() && !isNameDuplicate) {
					if (SearchCustomerVector.front().GetName() == name) {
						isNameDuplicate = true;
						isInvalidCustomer = true;
					} else {
						SearchCustomerVector.erase(
								SearchCustomerVector.begin());
					}
				}
			}

			// get the characters in the street box
			for (unsigned int i = 0; i < streetBox.glyphes; i++) {
				street += ((char*) streetBox.buffer.memory.ptr)[i];
			}
			// trim spaces
			street = trimSpaces(street);
			// check if street empty
			if (street.length() == 0) {
				isStreetEmpty = true;
				isInvalidCustomer = true;
			}

			// get the characters in the state zip code box
			for (unsigned int i = 0; i < stateZipCodeBox.glyphes; i++) {
				stateZipCode += ((char*) stateZipCodeBox.buffer.memory.ptr)[i];
			}
			// trim spaces
			stateZipCode = trimSpaces(stateZipCode);
			// check if state zip code empty
			if (stateZipCode.length() == 0) {
				isStateEmpty = true;
				isInvalidCustomer = true;
			}

			// get the characters in the username box
			for (unsigned int i = 0; i < usernameBox.glyphes; i++) {
				username += ((char*) usernameBox.buffer.memory.ptr)[i];
			}
			// check if username empty, if so generate a default username
			if (username.length() == 0 && !isNameEmpty) {
				username = GenerateUsername(name);
			} else if (hasSpaces(username)) {
				// otherwise search for spaces
				isUsernameInvalid = true;
				isInvalidCustomer = true;
			} else {
				// otherwise search for duplicates
				SearchCustomerVector = *customers;
				while (!SearchCustomerVector.empty() && !isUsernameDuplicate) {
					if (SearchCustomerVector.front().GetUsername()
							== username) {
						isUsernameDuplicate = true;
						isInvalidCustomer = true;
					} else {
						SearchCustomerVector.erase(
								SearchCustomerVector.begin());
					}
				}
			}

			// get the characters in the password box
			for (unsigned int i = 0; i < passwordBox.glyphes; i++) {
				password += ((char*) passwordBox.buffer.memory.ptr)[i];
			}
			// check if password empty, if so generate a default password
			if (password.length() == 0) {
				password = GeneratePassword();
			}
			else if (hasSpaces(password)) {
				// otherwise check for spaces
				isPasswordInvalid = true;
				isInvalidCustomer = true;
			}

			// get whether key
			if (!isKeyBoxUnTicked) {
				isKey = true;
			} else {
				isKey = false;
			}

			// get pamphlet
			if (!isPamphletBoxUnTicked) {
				isPamphletReceived = true;
			} else {
				isPamphletReceived = false;
			}
			// get rating
			rating = ratings[currentRatingInt];

			if (!isInvalidCustomer) {
				newCustomer = new Customer(name, street, stateZipCode,
						isPamphletReceived, isKey, rating, username, password,
						product1Value, product2Value, product3Value);

				customers->push_back(*newCustomer);

				std::sort(customers->begin(), customers->end());
				SaveCustomers(customers);
				issue_update();
				isNewCustomerAdded = true;
			}

		}
		zr_layout_row_dynamic(&context, 30, 1);
		if (zr_button_text(&context, "Main Menu", ZR_BUTTON_DEFAULT)) {
			changeWindow(ADMIN);
		}
		if (isNewCustomerAdded) {
			newCustomerNotification = "You have added customer "
					+ newCustomer->GetName() + " with username "
					+ newCustomer->GetUsername();
			zr_layout_row_dynamic(&context, 30, 1);
			zr_label(&context, newCustomerNotification.c_str(), ZR_TEXT_LEFT);
		}
	}
	zr_end(&context, window);
}
Exemple #4
0
static void
node_editor_demo(struct zr_context *ctx, struct node_editor *nodedit)
{
    int n = 0;
    struct zr_rect total_space;
    const struct zr_input *in = &ctx->input;
    struct zr_command_buffer *canvas;
    struct node *updated = 0;
    struct zr_panel layout;

    if (zr_begin(ctx, &layout, "Node Editor", zr_rect(50, 50, 650, 650),
        ZR_WINDOW_BORDER|ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_CLOSABLE|ZR_WINDOW_MOVABLE))
    {
        /* allocate complete window space */
        canvas = zr_window_get_canvas(ctx);
        total_space = zr_window_get_content_region(ctx);
        zr_layout_space_begin(ctx, ZR_STATIC, total_space.h, (zr_size)nodedit->node_count);
        {
            struct zr_panel node, menu;
            struct node *it = nodedit->begin;
            struct zr_rect size = zr_layout_space_bounds(ctx);

            if (nodedit->show_grid) {
                /* display grid */
                float x, y;
                const float grid_size = 32.0f;
                const struct zr_color grid_color = zr_rgb(50, 50, 50);
                for (x = (float)fmod(size.x - nodedit->scrolling.x, grid_size); x < size.w; x += grid_size)
                    zr_draw_line(canvas, x+size.x, size.y, x+size.x, size.y+size.h, grid_color);
                for (y = (float)fmod(size.y - nodedit->scrolling.y, grid_size); y < size.h; y += grid_size)
                    zr_draw_line(canvas, size.x, y+size.y, size.x+size.w, y+size.y, grid_color);
            }

            /* execute each node as a moveable group */
            while (it) {
                /* calculate scrolled node window position and size */
                zr_layout_space_push(ctx, zr_rect(it->bounds.x - nodedit->scrolling.x,
                    it->bounds.y - nodedit->scrolling.y, it->bounds.w, it->bounds.h));

                /* execute node window */
                if (zr_group_begin(ctx, &node, it->name, ZR_WINDOW_MOVABLE|ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_BORDER|ZR_WINDOW_TITLE))
                {
                    /* always have last selected node on top */
                    if (zr_input_mouse_clicked(in, ZR_BUTTON_LEFT, node.bounds) &&
                        (!(it->prev && zr_input_mouse_clicked(in, ZR_BUTTON_LEFT,
                        zr_layout_space_rect_to_screen(ctx, node.bounds)))) &&
                        nodedit->end != it)
                    {
                        updated = it;
                    }

                    /* ================= NODE CONTENT =====================*/
                    zr_layout_row_dynamic(ctx, 25, 1);
                    zr_button_color(ctx, it->color, ZR_BUTTON_DEFAULT);
                    it->color.r = (zr_byte)zr_propertyi(ctx, "#R:", 0, it->color.r, 255, 1,1);
                    it->color.g = (zr_byte)zr_propertyi(ctx, "#G:", 0, it->color.g, 255, 1,1);
                    it->color.b = (zr_byte)zr_propertyi(ctx, "#B:", 0, it->color.b, 255, 1,1);
                    it->color.a = (zr_byte)zr_propertyi(ctx, "#A:", 0, it->color.a, 255, 1,1);
                    /* ====================================================*/
                    zr_group_end(ctx);
                }
                {
                    /* node connector and linking */
                    float space;
                    struct zr_rect bounds;
                    bounds = zr_layout_space_rect_to_local(ctx, node.bounds);
                    bounds.x += nodedit->scrolling.x;
                    bounds.y += nodedit->scrolling.y;
                    it->bounds = bounds;

                    /* output connector */
                    space = node.bounds.h / ((it->output_count) + 1);
                    for (n = 0; n < it->output_count; ++n) {
                        struct zr_rect circle;
                        circle.x = node.bounds.x + node.bounds.w-4;
                        circle.y = node.bounds.y + space * (n+1);
                        circle.w = 8; circle.h = 8;
                        zr_draw_circle(canvas, circle, zr_rgb(100, 100, 100));

                        /* start linking process */
                        if (zr_input_has_mouse_click_down_in_rect(in, ZR_BUTTON_LEFT, circle, zr_true)) {
                            nodedit->linking.active = zr_true;
                            nodedit->linking.node = it;
                            nodedit->linking.input_id = it->ID;
                            nodedit->linking.input_slot = n;
                        }

                        /* draw curve from linked node slot to mouse position */
                        if (nodedit->linking.active && nodedit->linking.node == it &&
                            nodedit->linking.input_slot == n) {
                            struct zr_vec2 l0 = zr_vec2(circle.x + 3, circle.y + 3);
                            struct zr_vec2 l1 = in->mouse.pos;
                            zr_draw_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y,
                                l1.x - 50.0f, l1.y, l1.x, l1.y, zr_rgb(100, 100, 100));
                        }
                    }

                    /* input connector */
                    space = node.bounds.h / ((it->input_count) + 1);
                    for (n = 0; n < it->input_count; ++n) {
                        struct zr_rect circle;
                        circle.x = node.bounds.x-4;
                        circle.y = node.bounds.y + space * (n+1);
                        circle.w = 8; circle.h = 8;
                        zr_draw_circle(canvas, circle, zr_rgb(100, 100, 100));
                        if (zr_input_is_mouse_released(in, ZR_BUTTON_LEFT) &&
                            zr_input_is_mouse_hovering_rect(in, circle) &&
                            nodedit->linking.active && nodedit->linking.node != it) {
                            nodedit->linking.active = zr_false;
                            node_editor_link(nodedit, nodedit->linking.input_id,
                                nodedit->linking.input_slot, it->ID, n);
                        }
                    }
                }
                it = it->next;
            }

            /* reset linking connection */
            if (nodedit->linking.active && zr_input_is_mouse_released(in, ZR_BUTTON_LEFT)) {
                nodedit->linking.active = zr_false;
                nodedit->linking.node = NULL;
                fprintf(stdout, "linking failed\n");
            }

            /* draw each link */
            for (n = 0; n < nodedit->link_count; ++n) {
                struct node_link *link = &nodedit->links[n];
                struct node *ni = node_editor_find(nodedit, link->input_id);
                struct node *no = node_editor_find(nodedit, link->output_id);
                float spacei = node.bounds.h / ((ni->output_count) + 1);
                float spaceo = node.bounds.h / ((no->input_count) + 1);
                struct zr_vec2 l0 = zr_layout_space_to_screen(ctx,
                    zr_vec2(ni->bounds.x + ni->bounds.w, 3+ni->bounds.y + spacei * (link->input_slot+1)));
                struct zr_vec2 l1 = zr_layout_space_to_screen(ctx,
                    zr_vec2(no->bounds.x, 3 + no->bounds.y + spaceo * (link->output_slot+1)));

                l0.x -= nodedit->scrolling.x;
                l0.y -= nodedit->scrolling.y;
                l1.x -= nodedit->scrolling.x;
                l1.y -= nodedit->scrolling.y;
                zr_draw_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y,
                    l1.x - 50.0f, l1.y, l1.x, l1.y, zr_rgb(100, 100, 100));
            }

            if (updated) {
                /* reshuffle nodes to have last recently selected node on top */
                node_editor_pop(nodedit, updated);
                node_editor_push(nodedit, updated);
            }

            /* node selection */
            if (zr_input_mouse_clicked(in, ZR_BUTTON_LEFT, zr_layout_space_bounds(ctx))) {
                it = nodedit->begin;
                nodedit->selected = NULL;
                nodedit->bounds = zr_rect(in->mouse.pos.x, in->mouse.pos.y, 100, 200);
                while (it) {
                    struct zr_rect b = zr_layout_space_rect_to_screen(ctx, it->bounds);
                    b.x -= nodedit->scrolling.x;
                    b.y -= nodedit->scrolling.y;
                    if (zr_input_is_mouse_hovering_rect(in, b))
                        nodedit->selected = it;
                    it = it->next;
                }
            }

            /* contextual menu */
            if (zr_contextual_begin(ctx, &menu, 0, zr_vec2(100, 220), zr_window_get_bounds(ctx))) {
                const char *grid_option[] = {"Show Grid", "Hide Grid"};
                zr_layout_row_dynamic(ctx, 25, 1);
                if (zr_contextual_item(ctx, "New", ZR_TEXT_CENTERED))
                    node_editor_add(nodedit, "New", zr_rect(400, 260, 180, 220),
                            zr_rgb(255, 255, 255), 1, 2);
                if (zr_contextual_item(ctx, grid_option[nodedit->show_grid],ZR_TEXT_CENTERED))
                    nodedit->show_grid = !nodedit->show_grid;
                zr_contextual_end(ctx);
            }
        }
        zr_layout_space_end(ctx);

        /* window content scrolling */
        if (zr_input_is_mouse_hovering_rect(in, zr_window_get_bounds(ctx)) &&
            zr_input_is_mouse_down(in, ZR_BUTTON_MIDDLE)) {
            nodedit->scrolling.x += in->mouse.delta.x;
            nodedit->scrolling.y += in->mouse.delta.y;
        }
    }
    zr_end(ctx);
}
Exemple #5
0
static int
file_browser_run(struct file_browser *browser, int width, int height)
{
    struct zr_context context;
    struct media *media = &browser->media;
    struct icons *icons = &media->icons;
    struct zr_rect total_space;

    browser->window.bounds.w = width;
    browser->window.bounds.h = height;
    zr_begin(&context, &browser->window, NULL);
    {
        struct zr_context sub;
        float row_layout[3];
        /* output path directory selector in the menubar */
        zr_menubar_begin(&context);
        {
            char *d = browser->directory;
            char *begin = d + 1;
            zr_layout_row_dynamic(&context, 25, 6);
            zr_style_push_property(&browser->config, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));
            while (*d++) {
                if (*d == '/') {
                    *d = '\0';
                    if (zr_button_text(&context, begin, ZR_BUTTON_DEFAULT)) {
                        *d++ = '/'; *d = '\0';
                        file_browser_reload_directory_content(browser, browser->directory);
                        break;
                    }
                    *d = '/';
                    begin = d + 1;
                }
            }
            zr_style_pop_property(&browser->config);
        }
        zr_menubar_end(&context);

        /* window layout */
        total_space = zr_space(&context);
        row_layout[0] = (total_space.w - 8) * browser->ratio_sel;
        row_layout[1] = 8;
        row_layout[2] = (total_space.w - 8) * browser->ratio_dir;
        zr_layout_row(&context, ZR_STATIC, total_space.h, 3, row_layout);
        zr_style_push_property(&browser->config, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 4));

        /* output special important directory list in own window */
        zr_group_begin(&context, &sub, NULL, ZR_WINDOW_NO_SCROLLBAR|ZR_WINDOW_BORDER, browser->sel);
        {
            struct zr_image home = icons->home.img;
            struct zr_image desktop = icons->desktop.img;
            struct zr_image computer = icons->computer.img;

            zr_layout_row_dynamic(&sub, 40, 1);
            zr_style_push_property(&browser->config, ZR_PROPERTY_ITEM_SPACING, zr_vec2(0, 0));
            if (zr_button_text_image(&sub, home, "home", ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
                file_browser_reload_directory_content(browser, browser->home);
            if (zr_button_text_image(&sub,desktop,"desktop",ZR_TEXT_CENTERED, ZR_BUTTON_DEFAULT))
                file_browser_reload_directory_content(browser, browser->desktop);
            if (zr_button_text_image(&sub,computer,"computer",ZR_TEXT_CENTERED,ZR_BUTTON_DEFAULT))
                file_browser_reload_directory_content(browser, "/");
            zr_style_pop_property(&browser->config);
        }
        zr_group_end(&context, &sub, &browser->sel);

        {
            /* scaler */
            struct zr_rect bounds;
            struct zr_input *in = &browser->input;
            zr_layout_peek(&bounds, &context);
            zr_spacing(&context, 1);
            if ((zr_input_is_mouse_hovering_rect(in, bounds) ||
                zr_input_is_mouse_prev_hovering_rect(in, bounds)) &&
                zr_input_is_mouse_down(in, ZR_BUTTON_LEFT))
            {
                float sel = row_layout[0] + in->mouse.delta.x;
                float dir = row_layout[2] - in->mouse.delta.x;
                browser->ratio_sel = sel / (total_space.w - 8);
                browser->ratio_dir = dir / (total_space.w - 8);
            }
        }

        /* output directory content window */
        zr_group_begin(&context, &sub, NULL, ZR_WINDOW_BORDER, browser->dir);
        {
            int index = -1;
            size_t i = 0, j = 0, k = 0;
            size_t rows = 0, cols = 0;
            size_t count = browser->dir_count + browser->file_count;

            cols = 4;
            rows = count / cols;
            for (i = 0; i <= rows; i += 1) {
                {
                    /* draw one row of icons */
                    size_t n = j + cols;
                    zr_layout_row_dynamic(&sub, 135, cols);
                    zr_style_push_color(&browser->config, ZR_COLOR_BUTTON, zr_rgb(45, 45, 45));
                    zr_style_push_color(&browser->config, ZR_COLOR_BORDER, zr_rgb(45, 45, 45));
                    for (; j < count && j < n; ++j) {
                        if (j < browser->dir_count) {
                            /* draw and execute directory buttons */
                            if (zr_button_image(&sub,icons->directory.img,ZR_BUTTON_DEFAULT))
                                index = (int)j;
                        } else {
                            /* draw and execute files buttons */
                            struct icon *icon;
                            size_t fileIndex = ((size_t)j - browser->dir_count);
                            icon = media_icon_for_file(media,browser->files[fileIndex]);
                            if (zr_button_image(&sub, icon->img, ZR_BUTTON_DEFAULT)) {
                                strncpy(browser->file, browser->directory, MAX_PATH_LEN);
                                n = strlen(browser->file);
                                strncpy(browser->file + n, browser->files[fileIndex], MAX_PATH_LEN - n);
                                return 0;
                            }
                        }
                    }
                    zr_style_pop_color(&browser->config);
                    zr_style_pop_color(&browser->config);
                }
                {
                    /* draw one row of labels */
                    size_t n = k + cols;
                    zr_layout_row_dynamic(&sub, 20, cols);
                    for (; k < count && k < n; k++) {
                        if (k < browser->dir_count) {
                            zr_label(&sub, browser->directories[k], ZR_TEXT_CENTERED);
                        } else {
                            size_t t = k-browser->dir_count;
                            zr_label(&sub,browser->files[t],ZR_TEXT_CENTERED);
                        }
                    }
                }
            }

            if (index != -1) {
                size_t n = strlen(browser->directory);
                strncpy(browser->directory + n, browser->directories[index], MAX_PATH_LEN - n);
                n = strlen(browser->directory);
                if (n < MAX_PATH_LEN - 1) {
                    browser->directory[n] = '/';
                    browser->directory[n+1] = '\0';
                }
                file_browser_reload_directory_content(browser, browser->directory);
            }
        }
        zr_group_end(&context, &sub, &browser->dir);
        zr_style_pop_property(&browser->config);
    }
    zr_end(&context, &browser->window);
    return 1;
}
void CustomerListWindow::render_main(zr_window *window) {
	zr_context context;
	zr_begin(&context, window);
	{
		zr_header(&context, "Customer List", 0, 0, ZR_HEADER_LEFT);
		zr_layout_row_dynamic(&context, 30, 1);
		if (zr_button_text(&context, "Main Menu", ZR_BUTTON_DEFAULT)) {
			changeWindow(ADMIN);
		}
		{
			try {
				if (customers->empty()) {
					throw 0;
				}
				zr_checkbox(&context, "Key only", &isCheckBoxUnTicked);

				// need a copy of the list for output
				vector<Customer> CustomerOutputVector = *customers;
				for (int i = 0; !CustomerOutputVector.empty(); i++) {
					if ((isCheckBoxUnTicked == 0
							&& CustomerOutputVector.front().GetIsKey())
							| (isCheckBoxUnTicked == 1)) {
						// name row
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Name: ", ZR_TEXT_LEFT);
						zr_label(&context,
								CustomerOutputVector.front().GetName().c_str(),
								ZR_TEXT_LEFT);

						// address row
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Address: ", ZR_TEXT_LEFT);
						output =
								CustomerOutputVector.front().GetStreet() + ", "
										+ CustomerOutputVector.front().GetStateZipCode();
						zr_label(&context, output.c_str(), ZR_TEXT_LEFT);

						// Pamphlet row
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Sent Pamphlet? ", ZR_TEXT_LEFT);
						output =
								CustomerOutputVector.front().GetStreet() + ", "
										+ CustomerOutputVector.front().GetStateZipCode();
						if (CustomerOutputVector.front().GetPamphlet()) {
							output = "Yes";
						} else {
							output = "No";
						}
						zr_label(&context, output.c_str(), ZR_TEXT_LEFT);

						// Key row
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Type: ", ZR_TEXT_LEFT);
						if (CustomerOutputVector.front().GetIsKey()) {
							output = "Key";
						} else {
							output = "Nice to have";
						}
						zr_label(&context, output.c_str(), ZR_TEXT_LEFT);

						// Rating row
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Rating: ", ZR_TEXT_LEFT);
						zr_label(&context,
								CustomerOutputVector.front().GetRating().c_str(),
								ZR_TEXT_LEFT);

						// Username row
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Username: "******"Minimum Package Purchases: ",
								ZR_TEXT_LEFT);
						productQuantityStream
								<< CustomerOutputVector.front().GetMinimumPurchases()
								<< " ($"
								<< CustomerOutputVector.front().GetMinimumPurchases()
										* Customer::minimumPackageCost
								<< "/Month)";
						output = productQuantityStream.str();
						zr_label(&context, output.c_str(), ZR_TEXT_LEFT);

						// Extreme Package Row
						zr_layout_row_dynamic(&context, 30, 2);
						productQuantityStream.str("");
						productQuantityStream.clear();
						zr_label(&context, "Extreme Package Purchases: ",
								ZR_TEXT_LEFT);
						productQuantityStream
								<< CustomerOutputVector.front().GetExtremePurchases()
								<< " ($"
								<< CustomerOutputVector.front().GetExtremePurchases()
										* Customer::extremePackageCost
								<< "/Month)";
						output = productQuantityStream.str();
						zr_label(&context, output.c_str(), ZR_TEXT_LEFT);

						// Ultimate Package Row
						productQuantityStream.str("");
						productQuantityStream.clear();
						zr_layout_row_dynamic(&context, 30, 2);
						zr_label(&context, "Ultimate Package Purchases: ",
								ZR_TEXT_LEFT);
						productQuantityStream
								<< CustomerOutputVector.front().GetUltimatePurchases()
								<< " ($"
								<< CustomerOutputVector.front().GetUltimatePurchases()
										* Customer::ultimatePackageCost
								<< "/Month)";

						output = productQuantityStream.str();
						zr_label(&context, output.c_str(), ZR_TEXT_LEFT);

						// Edit and Remove Button Row
						zr_layout_row_dynamic(&context, 30, 2);
						editButtonString = "Edit "
								+ CustomerOutputVector.front().GetName();

						if (zr_button_text(&context, editButtonString.c_str(),
								ZR_BUTTON_DEFAULT)) {
							*customer_index = i;
							issue_update();
							changeWindow(EDIT_CUSTOMER);
						}
						removeButtonString = "Remove "
								+ CustomerOutputVector.front().GetName();
						if (zr_button_text(&context, removeButtonString.c_str(),
								ZR_BUTTON_DEFAULT)) {
							customers->erase(customers->begin() + i);
							SaveCustomers(customers);
							issue_update();
						}
					}

					CustomerOutputVector.erase(CustomerOutputVector.begin());
				}

				zr_layout_row_dynamic(&context, 30, 1);
				zr_checkbox(&context, "Key only", &isCheckBoxUnTicked);
				if (zr_button_text(&context, "Main Menu", ZR_BUTTON_DEFAULT)) {
					changeWindow(ADMIN);
				}
			} catch (...) {
				zr_label(&context, "There are currently no customers",
						ZR_TEXT_LEFT);
			}
		}

	}
	zr_end(&context, window);
}
Exemple #7
0
static int
control_window(struct zr_context *ctx, struct demo *gui)
{
    int i;
    struct zr_panel layout;
    if (zr_begin(ctx, &layout, "Control", zr_rect(0, 0, 350, 520),
        ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE|
        ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER))
    {
        /* Style */
        if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Metrics", ZR_MINIMIZED)) {
            zr_layout_row_dynamic(ctx, 20, 2);
            zr_label(ctx,"Total:", ZR_TEXT_LEFT);
            zr_labelf(ctx, ZR_TEXT_LEFT, "%lu", gui->status.size);
            zr_label(ctx,"Used:", ZR_TEXT_LEFT);
            zr_labelf(ctx, ZR_TEXT_LEFT, "%lu", gui->status.allocated);
            zr_label(ctx,"Required:", ZR_TEXT_LEFT);
            zr_labelf(ctx, ZR_TEXT_LEFT, "%lu", gui->status.needed);
            zr_label(ctx,"Calls:", ZR_TEXT_LEFT);
            zr_labelf(ctx, ZR_TEXT_LEFT, "%lu", gui->status.calls);
            zr_layout_pop(ctx);
        }
        if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Properties", ZR_MINIMIZED)) {
            zr_layout_row_dynamic(ctx, 22, 3);
            for (i = 0; i <= ZR_PROPERTY_SCROLLBAR_SIZE; ++i) {
                zr_label(ctx, zr_get_property_name((enum zr_style_properties)i), ZR_TEXT_LEFT);
                zr_property_float(ctx, "#X:", 0, &ctx->style.properties[i].x, 20, 1, 1);
                zr_property_float(ctx, "#Y:", 0, &ctx->style.properties[i].y, 20, 1, 1);
            }
            zr_layout_pop(ctx);
        }
        if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Rounding", ZR_MINIMIZED)) {
            zr_layout_row_dynamic(ctx, 22, 2);
            for (i = 0; i < ZR_ROUNDING_MAX; ++i) {
                zr_label(ctx, zr_get_rounding_name((enum zr_style_rounding)i), ZR_TEXT_LEFT);
                zr_property_float(ctx, "#R:", 0, &ctx->style.rounding[i], 20, 1, 1);
            }
            zr_layout_pop(ctx);
        }
        if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Color", ZR_MINIMIZED))
        {
            struct zr_panel tab, combo;
            enum theme old = gui->theme;
            static const char *themes[] = {"Black", "White", "Red", "Blue", "Dark", "Grey"};

            zr_layout_row_dynamic(ctx,  25, 2);
            zr_label(ctx, "THEME:", ZR_TEXT_LEFT);
            if (zr_combo_begin_text(ctx, &combo, themes[gui->theme], 300)) {
                zr_layout_row_dynamic(ctx, 25, 1);
                gui->theme = zr_combo_item(ctx, themes[THEME_BLACK], ZR_TEXT_CENTERED) ? THEME_BLACK : gui->theme;
                gui->theme = zr_combo_item(ctx, themes[THEME_WHITE], ZR_TEXT_CENTERED) ? THEME_WHITE : gui->theme;
                gui->theme = zr_combo_item(ctx, themes[THEME_RED], ZR_TEXT_CENTERED) ? THEME_RED : gui->theme;
                gui->theme = zr_combo_item(ctx, themes[THEME_BLUE], ZR_TEXT_CENTERED) ? THEME_BLUE : gui->theme;
                gui->theme = zr_combo_item(ctx, themes[THEME_DARK], ZR_TEXT_CENTERED) ? THEME_DARK : gui->theme;
                if (old != gui->theme) set_style(ctx, gui->theme);
                zr_combo_end(ctx);
            }

            zr_layout_row_dynamic(ctx, 300, 1);
            if (zr_group_begin(ctx, &tab, "Colors", 0))
            {
                for (i = 0; i < ZR_COLOR_COUNT; ++i) {
                    zr_layout_row_dynamic(ctx, 25, 2);
                    zr_label(ctx, zr_get_color_name((enum zr_style_colors)i), ZR_TEXT_LEFT);
                    if (zr_combo_begin_color(ctx, &combo, ctx->style.colors[i], 200)) {
                        zr_layout_row_dynamic(ctx, 25, 1);
                        ctx->style.colors[i].r = (zr_byte)zr_propertyi(ctx, "#R:", 0, ctx->style.colors[i].r, 255, 1,1);
                        ctx->style.colors[i].g = (zr_byte)zr_propertyi(ctx, "#G:", 0, ctx->style.colors[i].g, 255, 1,1);
                        ctx->style.colors[i].b = (zr_byte)zr_propertyi(ctx, "#B:", 0, ctx->style.colors[i].b, 255, 1,1);
                        ctx->style.colors[i].a = (zr_byte)zr_propertyi(ctx, "#A:", 0, ctx->style.colors[i].a, 255, 1,1);
                        zr_combo_end(ctx);
                    }
                }
                zr_group_end(ctx);
            }
            zr_layout_pop(ctx);
        }
    }
    zr_end(ctx);
    return !zr_window_is_closed(ctx, "Control");
}