// returns true when clicked on it bool cSteam::ButtonDraw(BITMAP *dest, int x, int y, int width, int height, char *title) { bool result=false; if (width < 12) width = 12; if (height < 12) height = 12; rectfill(dest, x, y, x+width, y+height, makecol(76,88,68)); // now draw lines line(dest, x, y, x+(width), y, makecol(136,145,128)); line(dest, x, y, x, y+(height), makecol(136,145,128)); line(dest, x+(width), y, x+(width), y+(height), makecol(40,46,34)); line(dest, x, y+(height), x+(width), y+(height), makecol(40,46,34)); // now draw text alfont_set_font_size(game_font, 14); // set size int color = COLOR_GREY; if ((mouse_x > x && mouse_x < (x+width)) && (mouse_y > y && mouse_y < (y+height))) { color = COLOR_WHITE; if (game.MOUSE_PRESSED_LEFT()) result = true; } alfont_textprintf(dest, game_font, x+2, y+2,color, title); return result; }
// draw a nice steam colored window void cSteam::WindowDraw(BITMAP *dest, int x, int y, int width, int height, char *title) { // Draw a neat looking window. // Minimum sizes are: 32x32 if (width < 32) width=32; if (height < 32) height=32; // first draw 'the 4' (corners) // UP LEFT draw_sprite(dest, (BITMAP *)graphics[STEAM_UPLEFT].dat, x, y); // UP RIGHT draw_sprite(dest, (BITMAP *)graphics[STEAM_UPRIGHT].dat, x+(width-16), y); // DOWN LEFT draw_sprite(dest, (BITMAP *)graphics[STEAM_DOWNLEFT].dat, x, y+(height-16)); // DOWN RIGHT draw_sprite(dest, (BITMAP *)graphics[STEAM_DOWNRIGHT].dat, x+(width-16), y+(height-16)); // draw the 'bars' line(dest, x+16, y, x+(width-16), y, makecol(136,145,128)); line(dest, x, y+16, x, y+(height-16), makecol(136,145,128)); line(dest, x+(width), y+16, x+(width), y+(height-16), makecol(40,46,34)); line(dest, x+16, y+(height), x+(width-16), y+(height), makecol(40,46,34)); // Fill it // middle rectfill(dest, x+16, y+16, x+(width-16), y+(height-16), makecol(76,88,68)); // up rectfill(dest, x+16, y+1, x+(width-16), y+16, makecol(76,88,68)); // down rectfill(dest, x+16, y+(height-16), x+(width-16), y+(height-1), makecol(76,88,68)); // left rectfill(dest, x+1, y+16, x+16, y+(height-16), makecol(76,88,68)); // right rectfill(dest, x+(width-16), y+16, x+(width-1), y+(height-16), makecol(76,88,68)); // title: // size of text = 12 alfont_set_font_size(game_font, 14); // set size alfont_textprintf(dest, game_font, x+17, y+2,makecol(255,255,255), title); // devide bar line(dest, x+17, y+17, x+(width-17), y+17, makecol(40,46,34)); line(dest, x+17, y+18, x+(width-17), y+18, makecol(136,145,128)); // ... }
/** * Draw the list, start from startId, until the max icons in the list to be drawn. * * @param startId */ void cBuildingListDrawer::drawList(cBuildingList *list, int listIDToDraw, int startId, bool shouldDrawStructureSize) { // starting draw coordinates int iDrawX=getDrawX(); int iDrawY=getDrawY(); int maxYClip = maxListYCoordinate; int minYClip = 45; int minXClip = game.screen_x - 69; int maxXClip = game.screen_x; set_clip_rect(bmp_screen, minXClip, minYClip, maxXClip, maxYClip); int end = startId + maximumItemsToDraw; // max 5 icons are showed at once // is building an item in the list? bool isBuildingItemInList = list->isBuildingItem(); // draw the icons for (int i = startId; i < end; i++) { cBuildingListItem * item = list->getItem(i); if (item == NULL) { break; // stop. List became empty. } int iDrawXEnd = iDrawX + 63; int iDrawYEnd = iDrawY + 47; // icon id must be set , assert it. assert(item->getIconId() > -1); rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(255, 255, 255)); line(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(255, 255, 255)); draw_sprite(bmp_screen, (BITMAP *)gfxinter[item->getIconId()].dat, iDrawX, iDrawY); if (shouldDrawStructureSize) { drawStructureSize(item->getBuildId(), iDrawX, iDrawY); } bool cannotPayIt = item->getBuildCost() > player[HUMAN].credits; // when this item is being built. if (item->isBuilding()) { int iTotalBuildPoints = 0; // get the total build time if (listIDToDraw == LIST_CONSTYARD) { iTotalBuildPoints = structures[item->getBuildId()].build_time; } else if (listIDToDraw != LIST_STARPORT) { iTotalBuildPoints = units[item->getBuildId()].build_time; } // Now calculate the right frame. float iPiece = iTotalBuildPoints / 31; // = 17 - 1 (of above) if (iPiece < 0.1) { iPiece = 0.1; } int iFrame = health_bar(31, item->getProgress(), iTotalBuildPoints); if (iFrame > 31) { iFrame = 31; } if (item->getProgress() < iTotalBuildPoints) { // draw the other progress stuff set_trans_blender(0, 0, 0, 128); draw_trans_sprite(bmp_screen, (BITMAP *)gfxinter[PROGRESSFIX].dat, iDrawX+2, iDrawY+2); draw_trans_sprite(bmp_screen, (BITMAP *)gfxinter[PROGRESS001+iFrame].dat, iDrawX+2, iDrawY+2); } else { // draw 'ready' text when done building. if (listIDToDraw == LIST_CONSTYARD) { draw_sprite(bmp_screen, (BITMAP *)gfxinter[READY01].dat, iDrawX+3, iDrawY+16); } } } else { // this item is not being built. So we do not draw a progress indicator. // however, it could be that an other item is being built. // draw the item 'unavailable' when: // - is not available (doh) // - we cant pay it // - some other item is being built // - list is being upgraded, so you cannot build items /*|| cannotPayIt*/ if (!item->isAvailable() || isBuildingItemInList || list->isUpgrading() || !list->isAcceptsOrders()) { set_trans_blender(0,0,0,128); fblend_trans((BITMAP *)gfxinter[PROGRESSNA].dat, bmp_screen, iDrawX, iDrawY, 64); } if (list->getType() == LIST_STARPORT) { if (cannotPayIt) { set_trans_blender(0,0,0,128); fblend_trans((BITMAP *)gfxinter[PROGRESSNA].dat, bmp_screen, iDrawX, iDrawY, 64); rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(game.fade_select, 0, 0)); line(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(game.fade_select, 0, 0)); line(bmp_screen, iDrawX, iDrawY+47, iDrawX+63, iDrawY, makecol(game.fade_select, 0, 0)); set_trans_blender(0,0,0,128); } } // last built id if (list->getLastClickedId() == i) { rect(bmp_screen, (iDrawX + 1), (iDrawY + 1), (iDrawXEnd - 1), (iDrawYEnd - 1), makecol(game.fade_select, game.fade_select, game.fade_select)); rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, makecol(game.fade_select, game.fade_select, game.fade_select)); } } int amountToShow = item->getTimesToBuild(); if (amountToShow <= 0) { amountToShow = item->getTimesOrdered(); } if (amountToShow > 0) { // draw number of times to build this thing (queueing) int textX = iDrawX + 41; int textY = iDrawY + 16; if (amountToShow < 10) { textX += 10; } // draw alfont_textprintf(bmp_screen, game_font, textX + 1,textY + 1, makecol(0,0,0), "%d", amountToShow); alfont_textprintf(bmp_screen, game_font, textX,textY, makecol(255,255,255), "%d", amountToShow); } // draw rectangle when mouse hovers over icon if (isOverItemCoordinates_Boolean(mouse_x, mouse_y, iDrawX, iDrawY)) { int iColor=makecol(game.fade_select, game.fade_select, game.fade_select); if (player[0].getHouse() == ATREIDES) { iColor = makecol(0, 0, game.fade_select); } if (player[0].getHouse() == HARKONNEN) { iColor = makecol(game.fade_select, 0, 0); } if (player[0].getHouse() == ORDOS) { iColor = makecol(0, game.fade_select, 0); } rect(bmp_screen, (iDrawX + 1), (iDrawY + 1), (iDrawXEnd - 1), (iDrawYEnd - 1), iColor); rect(bmp_screen, iDrawX, iDrawY, iDrawXEnd, iDrawYEnd, iColor); } iDrawY+=48; } set_clip_rect(bmp_screen, 0, 0, game.screen_x, game.screen_y); }
void cSteam::DrawMenuItems(int x, int y, int iMenu, bool bActive) { tMenuItem MENU_Items[10]; // max of 10 options unsigned int iWidth=0; // initialize menu stuff for (int i=0; i < 10; i++) { MENU_Items[i].iMainState = -1; MENU_Items[i].iSubState = -1; memset(MENU_Items[i].text, 0, sizeof(MENU_Items[i].text)); } // Main Menu if (iMenu == 0) { // copy the menu items for (int i=0; i < 6; i++) { MENU_Items[i].iMainState = MENU_MainMenu[i].iMainState; MENU_Items[i].iSubState = MENU_MainMenu[i].iSubState; memcpy(MENU_Items[i].text, MENU_MainMenu[i].text, sizeof(MENU_MainMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } // any other menu else if (iMenu == 1) { // copy the menu items for (int i=0; i < 6; i++) { MENU_Items[i].iMainState = MENU_OptionsMenu[i].iMainState; MENU_Items[i].iSubState = MENU_OptionsMenu[i].iSubState; memcpy(MENU_Items[i].text, MENU_OptionsMenu[i].text, sizeof(MENU_OptionsMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } else if (iMenu == 2) { // copy the menu items for (int i=0; i < 6; i++) { MENU_Items[i].iMainState = MENU_IngameMenu[i].iMainState; MENU_Items[i].iSubState = MENU_IngameMenu[i].iSubState; memcpy(MENU_Items[i].text, MENU_IngameMenu[i].text, sizeof(MENU_IngameMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } else if (iMenu == 3) { // copy the menu items for (int i=0; i < 10; i++) { MENU_Items[i].iMainState = EDITOR_MainMenu[i].iMainState; MENU_Items[i].iSubState = EDITOR_MainMenu[i].iSubState; memcpy(MENU_Items[i].text, EDITOR_MainMenu[i].text, sizeof(EDITOR_MainMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } alfont_set_font_size(game_font, 14); // set size int iTextY=y; // Now draw / print / react etc for (int id=0; id < 10; id++) { // valid if (strlen(MENU_Items[id].text) > 0) { // draw this thing on the screen int iColor=COLOR_GREY; if (strcmp(MENU_Items[id].text, "-") == 0) { // devide bar line(bmp_screen, x, iTextY+7, x+(iWidth*8), iTextY+7, makecol(40,46,34)); line(bmp_screen, x, iTextY+8, x+(iWidth*8), iTextY+8, makecol(136,145,128)); iTextY += 14; } else { if (bActive) { // determine if mouse is over this one int iWidth = strlen(MENU_Items[id].text) * 8; if ((mouse_x > x && mouse_x < (x+iWidth)) && (mouse_y > iTextY && mouse_y < (iTextY+12))) iColor = COLOR_WHITE; } alfont_textprintf(bmp_screen, game_font, x, iTextY, iColor, MENU_Items[id].text); iTextY += 14; if (iColor == COLOR_WHITE) if (game.MOUSE_PRESSED_LEFT()) { iMainState = MENU_Items[id].iMainState; iSubState = MENU_Items[id].iSubState; } } // its not a devider } } }