#include #include #include #include #include "cursor.h" using std::string; using std::vector; template Cursor::Cursor() { active = false; } //Give items to the cursor, and set the selected item to be the first template void Cursor::activate(std::vector _items) { items = _items; selected = 0; active = true; } //Functionality that was not used for this game, may be used in future projects. template void Cursor::deactivate() { active = false; } //Draw the menu options on the screen based on the x and y coordinates for the menu to start at template void Cursor::draw(float _x_start, float _y_start, float _y_offset, ALLEGRO_FONT* _font) { vector items_text = get_item_strings(); x_start = _x_start; y_start = _y_start; y_offset = _y_offset; font = _font; for (unsigned int i = 0; i < items_text.size(); i++) { al_draw_text(font, al_map_rgb(255, 255, 255), x_start, y_start + (y_offset*i), ALLEGRO_ALIGN_LEFT, items_text.at(i).c_str()); } update_selector(); } //Change the selection of the cursor template void Cursor::down() { if (selected < items.size() - 1) { selected++; redraw(); } } template void Cursor::up() { if (selected > 0) { selected--; redraw(); } } template T Cursor::get_selected() { return items.at(selected); } //Clear screen before drawing menu template void Cursor::redraw() { al_clear_to_color(al_map_rgb(0, 0, 0)); draw(x_start, y_start, y_offset, font); } //Draw selector to highlight proper selected item template void Cursor::update_selector() { ALLEGRO_COLOR white = al_map_rgb(255, 255, 255); float offset = y_offset * selected; float x1 = x_start - 5; float y1 = y_start + offset; float x2 = x_start - 5; float y2 = y_start + 5 + offset; float x3 = x_start - 1; float y3 = y_start + 2.5 + offset; al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, white); } //Define how the template will function when given various types. Only string was needed for this project. template Cursor::Cursor(); template void Cursor::activate(std::vector _options); template void Cursor::deactivate(); template void Cursor::draw(float x_start, float y_start, float _y_offset, ALLEGRO_FONT* font); template void Cursor::redraw(); template void Cursor::up(); template void Cursor::down(); template string Cursor::get_selected(); template void Cursor::update_selector(); template <> vector Cursor::get_item_strings() { return items; }