BoundingBox OSMMapParamFactory::getWorldBoxForParam(int x, int y, int zoomIndex)
{
   int gz = m_impl->grid.getGridSize();

   BoundingBox b(UPoint(x * gz, y * gz + gz),
                 UPoint(x * gz + gz, y * gz));

   // cout << "b initial: " << b << endl;
   
   GridBox res = {b, zoomIndex};

   invInvertGridBoxYAxis(res);

   // cout << "b after invaxis: " << b << endl;
   
   invOffsetGridBox(res.box, res.zoomIndex);

   // cout << "b after offset: " << b << endl;
   
   BoundingBox worldBox = m_impl->converter.gridToWorld(res);

   // cout << "b after projection: " << worldBox << endl;
   
   return worldBox;    
}
void OSMMapFactoryTest::testWorldToGridWhole()
{
   vector<MapParam> res;

   /**
    * Start by finding the request strings for bounding boxes on the
    * highest zoom level. Should always result in a single result.
    */
   m_impl->factory.getParamsFromWorldBox(res, mercatorWhole, MAX_SCALE);
   rtAssert(res.size() == 1);
   rtAssert(find(res.begin(), res.end(), "0/0/0.png") != res.end());
   res.clear();
   m_impl->factory.getParamsFromWorldBox(res, mercatorUpperRight, MAX_SCALE);

   // for(unsigned int i = 0; i < res.size(); i++) {
   //    cout << "MapParam[" << i << "] = " << res[i].getString() << endl;
   // }

   rtAssert(res.size() == 1);
   rtAssert(find(res.begin(), res.end(), "0/0/0.png") != res.end());

   res.clear();
   m_impl->factory.getParamsFromWorldBox(res, mercatorWhole, MAX_SCALE_MINUS_ONE);

   rtAssert(res.size() == 4);
   
   rtAssert(find(res.begin(), res.end(), "1/0/0.png") != res.end());
   rtAssert(find(res.begin(), res.end(), "1/0/1.png") != res.end());
   rtAssert(find(res.begin(), res.end(), "1/1/0.png") != res.end());
   rtAssert(find(res.begin(), res.end(), "1/1/1.png") != res.end());

   res.clear();
   m_impl->factory.getParamsFromWorldBox(res,
                                         mercatorUpperRight,
                                         MAX_SCALE_MINUS_ONE);

   // for(unsigned int i = 0; i < res.size(); i++) {
   //    cout << "MapParam[" << i << "] = " << res[i].getString() << endl;
   // }

   rtAssert(res.size() == 1);

   rtAssert(find(res.begin(), res.end(), "1/1/0.png") != res.end());
   
   /**
    *  Test offsetting by one pixel
    */
   GridBox gbMO = {BoundingBox(UPoint(127, 256), UPoint(256, 128)), 0};

   res.clear();
   m_impl->factory.getParamsFromGridBox(res, gbMO);

   // A box offset by one pixels should result in two tiles being requested.
   rtAssert(res.size() == 2);
}
Exemple #3
0
//---------------------------------------------------------------------------------------
void RightAligner::add_border_segment(LUnits y0, LUnits y1, LUnits x)
{
    if (m_border.size() == 0)
    {
        m_border.push_back( UPoint(x, y0) );
        m_border.push_back( UPoint(LOMSE_MAX_X, y1) );
    }
    else
    {
        //find first point with y >= y0
        LUnits xNext = LOMSE_MAX_X;
        std::list<UPoint>::iterator it;
        for (it = m_border.begin(); it != m_border.end(); ++it)
        {
            if ((*it).y == y0)
            {
                //replace
                xNext = (*it).x;
                (*it).x = x;
                ++it;
                break;
            }
            else if ((*it).y > y0 || (*it).y == LOMSE_MAX_Y)
            {
                //insert before
                m_border.insert(it, UPoint(x, y0));  //'it' still points to greater point
                break;
            }
            xNext = (*it).x;
        }

        //insert second point

        //remove intermediate points
        while((*it).y < y1 && (*it).y != LOMSE_MAX_Y)
        {
            xNext = (*it).x;
            m_border.erase(it++);
        }

        if ((*it).y == y1)
        {
            //no need to do anything. point is still valid!
        }
        else if ((*it).y > y1 || (*it).y == LOMSE_MAX_Y)
        {
            //insert before
            UPoint p2(xNext, y1);
            m_border.insert(it, p2);
        }
    }
}
Exemple #4
0
void GraphicButton::draw(Image& dest, SPoint off)
{
    if (!m_visible) return;

    if (m_pressed)
    {
        m_surfPressed->blitTo(dest, UPoint(off.x + x, off.y + y));
    }
    else
    {
        m_surfNormal->blitTo(dest, UPoint(off.x + x, off.y + y));
    };
}
Exemple #5
0
UPoint Settings::ToggleResolution() {
    UPoint resolution;

    if(m_resolution.x < 800)
	resolution = UPoint(800, 600);
    else if(m_resolution.x < 1024)
	resolution = UPoint(1024, 768);
    else
	resolution = UPoint(640, 480);

    SetResolution(resolution);

    return m_resolution;
}
Exemple #6
0
void GameMan::TakeMapScreenshot(std::string filename)
{
    int w = m_map->w;
    int h = m_map->h;
    Image img(UPoint(w * 16, h * 16));


    for (int i = 0 ; i < w; i++)
	for (int j = 0 ; j < h; j++)
	    m_map->getCell(UPoint(i, j))->draw(img, SPoint(16*i, 16*j));

    img.saveBMP(filename);

}
void SkirmishGameState::resize()
{
    GameMenuState::resize();
    m_mapWidget->setPosition(UPoint(0, m_topFrame->getSize().y));
    UPoint resolution = set->GetResolution();
    UPoint mapSize(resolution.x - m_sideBarFrame->getSize().x, resolution.y - m_mapWidget->getPosition().y);
    mapSize.x -= mapSize.x % BLOCKSIZE;
    mapSize.y -= mapSize.y % BLOCKSIZE;    

    mapSize += BLOCKSIZE;

    m_mapWidget->setSize(mapSize);

    char mission[] = "SCENARIO:SCEN%c%.3d.INI";
    char house;
    if(m_house == HOUSE_HARKONNEN)
	house = 'H';
    else if(m_house == HOUSE_ATREIDES)
	house = 'A';
    else if(m_house == HOUSE_ORDOS)
	house = 'O';
    else if(m_house == HOUSE_FREMEN)
	house = 'F';
    else if(m_house == HOUSE_MERCENARY)
	house = 'M';
    else
	house = 0;
    sprintf(mission, mission, house, m_level);

    GameMan::Instance()->LoadScenario(mission);
    //TODO: adjust to make it relative to current resolution rather than 320x200
    m_mapWidget->setMapPosition(GameMan::Instance()->getTacticalPos());
}
Exemple #8
0
//---------------------------------------------------------------------------------------
void CheckboxCtrl::on_draw(Drawer* pDrawer, RenderOptions& UNUSED(opt))
{
    select_font();
    Color color = (m_fEnabled ? m_currentColor : Color(192, 192, 192));
    pDrawer->set_text_color(color);
    URect pos = determine_text_position_and_size();

    pDrawer->begin_path();
    pDrawer->fill( Color(0,0,0,0) );
    pDrawer->stroke(color);
    pDrawer->stroke_width( pos.height * 0.075f );
    pDrawer->rect(UPoint(m_pos.x, m_pos.y +100.0f), USize(400.0f, 400.0f), 50.0f);
    pDrawer->end_path();

    pDrawer->draw_text(pos.x + 600.0f, pos.y, m_label);

    if (m_status)
    {
//        pDrawer->draw_text(pos.x + 50.0f, pos.y, "X");
        pDrawer->begin_path();
        pDrawer->fill(color);
        pDrawer->add_path(*this);
        pDrawer->end_path();
    }
}
//---------------------------------------------------------------------------------------
void MetronomeMarkEngraver::create_symbol_shape(int noteType, int dots)
{
    int iGlyph = select_glyph(noteType);
    Tenths yOffset = m_libraryScope.get_glyphs_table()->glyph_offset(iGlyph);
    LUnits y = m_uPos.y + m_pMeter->tenths_to_logical(yOffset, m_iInstr, m_iStaff);
    ShapeId idx = 0;
    GmoShape* pShape = LOMSE_NEW GmoShapeMetronomeGlyph(m_pCreatorImo, idx, iGlyph,
                                               UPoint(m_uPos.x, y), m_color,
                                               m_libraryScope, m_fontSize);
	m_pMainShape->add(pShape);
    m_uPos.x += pShape->get_width();

    if (dots > 0)
    {
        LUnits space = m_pMeter->tenths_to_logical(2.0, m_iInstr, m_iStaff);
        for (; dots > 0; dots--)
        {
            m_uPos.x += space;
            pShape = LOMSE_NEW GmoShapeMetronomeGlyph(m_pCreatorImo, idx,
                                               k_glyph_metronome_augmentation_dot,
                                               m_uPos, m_color,
                                               m_libraryScope, m_fontSize);
            m_pMainShape->add(pShape);
            m_uPos.x += pShape->get_width();
        }
    }
}
Exemple #10
0
//---------------------------------------------------------------------------------------
UPoint ClefEngraver::get_drag_offset()
{
    //return center of clef
    URect bounds = m_pClefShape->get_bounds();
    return UPoint(bounds.get_width() / 2.0,
                  bounds.get_height() / 2.0 );
}
void Application::InitVideo()
{
    Settings* set = Settings::Instance();
    UPoint resolution = set->GetResolution();
    
    int videoFlags = SDL_HWPALETTE | SDL_RESIZABLE;
    if (set->GetDoubleBuffered())
        videoFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
    if (set->GetFullScreen())
        videoFlags |= SDL_FULLSCREEN;


    SDL_Surface *surface = SDL_SetVideoMode(resolution.x, resolution.y, 8, videoFlags);
    
    if(!surface) {
        LOG(LV_ERROR, "Application", "Couldn't set video mode: %s", SDL_GetError());
        Die();
    } else
	surface->flags |= SDL_PREALLOC;

    *m_screen = surface;
    
    // reset the palette if we've got one 
    if (m_currentPalette)
        SetPalette();

    SDL_ShowCursor(SDL_DISABLE);

    m_rootWidget->setSize(resolution);
    m_rootWidget->setPosition(UPoint(0, 0));
}
//---------------------------------------------------------------------------------------
void TopLevelCaretPositioner::layout_caret(Caret* pCaret, DocCursor* pCursor)
{
    m_pCursor = pCursor;
    m_state = m_pCursor->get_state();

    ImoId id = m_state.get_parent_level_id();
    GmoBox* pBox = m_pGModel->get_box_for_imo(id);

    URect pos;
    if (pBox)
        pos = pBox->get_bounds();
    else
    {
        //at end of document
        pBox = get_box_for_last_element();
        if (pBox)
        {
            pos.set_top_left( UPoint(pBox->get_left(), pBox->get_bottom()) );
            pos.set_height(1000.0f);
            pos.set_width(1000.0f);
        }
        else
        {
            //empty document
            pos = URect(0.0f, 0.0f, 1000.0f, 1000.0f);
        }
    }

    pCaret->set_type(Caret::k_top_level);
    pCaret->set_top_level_box(pos);
    pCaret->set_position( pos.get_top_left() );
    pCaret->set_size( USize(pos.get_width(), pos.get_height()) );
}
Exemple #13
0
static unsigned int DGetMinError(unsigned int yAxisNumber, Feature *yFeature){
	/* Calculate angle of each point to the xAxis and sort them */
	UPoints angles(n);
	for (unsigned int i = 0; i < n; i++){
		angles[i] = UPoint((x[yAxisNumber][i] == 0 && curFeature[i] == 0) ? 0 : y[i] , atan2(x[yAxisNumber][i], curFeature[i]));
	}
	sort(angles.begin(), angles.end(), Compare);
/*
	for (unsigned i = 0; i < n; i++){
		cout << (angles[i].pattern > 0 ? 1 : angles[i].pattern < 0 ? 0 : 3);
	}
	cout << endl;
*/
	/* Look for the optimal threshold */
	int leftDiff = 0; unsigned int optThreshold = 0; int maxCorr = 0; double nextValue = angles[0].value;
	for (unsigned i = 0; i < n - 1; i++){
		leftDiff += angles[i].pattern;
		if (angles[i + 1].value == nextValue){ continue; } nextValue = angles[i].value;
		int corr = max(numMore - leftDiff, numLess + leftDiff);
		//int corr = abs(leftDiff) + abs(difference - leftDiff); 
		if (corr > maxCorr){ maxCorr = corr; optThreshold = i; }
//		cout << i << " " << corr << "; ";
	}
//	cout << endl;

	/* Determine the angle of the separating direction */
	yFeature->angle = (angles[optThreshold].value + angles[optThreshold + 1].value) / 2. - PI2; yFeature->error = n - maxCorr; yFeature->number = yAxisNumber;
	return yFeature->error;
}
void Application::BlitCursor()
{
    Rect src(0,0,16,16);
    UPoint dest(m_cursorX, m_cursorY);
    //src.w = surface->w / NUM_CURSORS;
    //src.h = surface->h;
    //src.x = src.w * m_cursorFrame;
    //src.y = 0;

    //reposition image so pointing on right spot

    switch (m_cursorFrame)
    {
    case CURSOR_NORMAL: src.setPosition(UPoint(0,0)); break;
    case CURSOR_UP: src.setPosition(UPoint(16,0)); break;
    case CURSOR_RIGHT: src.setPosition(UPoint(32,0)); break;
    case CURSOR_DOWN: src.setPosition(UPoint(48,0)); break;
    case CURSOR_LEFT: src.setPosition(UPoint(64,0)); break;
    case CURSOR_TARGET: src.setPosition(UPoint(80,0)); break;
    case CURSOR_SELECTION: src.setPosition(UPoint(96,0)); break;
    case NUM_CURSORS: break;
    }
    
    m_screen->blitFrom(*m_cursor, src, dest);
}
void SkirmishMenuState::drawSpecifics()
{
    DataCache::Instance()->getGameData("BigPlanet")->getImage();

    ImagePtr houseChoice = DataCache::Instance()->getGameData("UI_HouseChoiceBackground")->getImage()->getCopy();
    houseChoice->drawBorders1();
    Rect area(20, 53, 300, 53+95);
    houseChoice->greyOut(area);
    m_middleFrame->changeBackground(houseChoice);
    m_selectionBox->setPosition(area.getPosition() - 1);
    m_selectionBox->setSize(area.getSize());
    m_middleFrame->addChild(m_selectionBox);

    ImagePtr atreides = DataCache::Instance()->getGameData("UI_HeraldColoredAtreides")->getImage();
    ImagePtr transparent(new Image(atreides->getSize()));

    transparent->setColorKey();
    GraphicButton *atreidesButton = new GraphicButton(transparent, atreides);
    atreidesButton->setPosition(UPoint(0, 0));
    atreidesButton->onClick.connect(
            boost::bind(&SkirmishMenuState::setHouse, this, HOUSE_ATREIDES));

    m_selectionBox->addChild(atreidesButton);

    ImagePtr ordos = DataCache::Instance()->getGameData("UI_HeraldColoredOrdos")->getImage();
    transparent->setColorKey();
    GraphicButton *ordosButton = new GraphicButton(transparent, ordos);
    ordosButton->setPosition(UPoint(96, 0));
    ordosButton->onClick.connect(
            boost::bind(&SkirmishMenuState::setHouse, this, HOUSE_ORDOS));
    m_selectionBox->addChild(ordosButton);

    ImagePtr harkonnen = DataCache::Instance()->getGameData("UI_HeraldColoredHarkonnen")->getImage();
    transparent->setColorKey();
    GraphicButton *harkonnenButton = new GraphicButton(transparent, harkonnen);
    harkonnenButton->setPosition(UPoint(194, 0));
    harkonnenButton->onClick.connect(
            boost::bind(&SkirmishMenuState::setHouse, this, HOUSE_HARKONNEN));
    m_selectionBox->addChild(harkonnenButton);

    m_missionLabel->redraw();
}
void OSMMapFactoryTest::testGridToWorldWhole()
{
   MapParam p = m_impl->factory.getParamFromString("2/1/0.png");

   rtAssert(p.getZoomIndex() == 2);
   
   rtAssert(p.getString() == "2/1/0.png");

   p = m_impl->factory.getParamFromString("0/0/0.png");

   rtAssert(p.getWorldBox().topLeft.getX() == MIN_INT32 + 1);
   rtAssert(p.getWorldBox().topLeft.getY() == MAX_INT32);
   rtAssert(p.getWorldBox().bottomRight.getX() == MAX_INT32);
   rtAssert(p.getWorldBox().bottomRight.getY() == MIN_INT32 + 1);
   
   MapParam p1 = m_impl->factory.getParamFromString("1/0/0.png");
   MapParam p2 = m_impl->factory.getParamFromString("1/1/0.png");
   MapParam p3 = m_impl->factory.getParamFromString("1/1/1.png");
   MapParam p4 = m_impl->factory.getParamFromString("1/0/1.png");

   BoundingBox w1 = p1.getWorldBox();
   BoundingBox w2 = p2.getWorldBox();
   BoundingBox w3 = p3.getWorldBox();
   BoundingBox w4 = p4.getWorldBox();
   
   rtAssert(w1.bottomRight == UPoint(0, 0));
   rtAssert(w2.topLeft.getX() == 0);
   rtAssert(w2.bottomRight.getY() == 0);
   rtAssert(w3.topLeft == UPoint(0, 0));
   rtAssert(w4.topLeft.getY() == 0);
   rtAssert(w4.bottomRight.getX() == 0);

   rtAssert(p1.getZoomIndex() == 1);
   rtAssert(p2.getZoomIndex() == 1);
   rtAssert(p3.getZoomIndex() == 1);
   rtAssert(p4.getZoomIndex() == 1);
   
   rtAssert(w1.topLeft.getY() == w2.topLeft.getY());
   rtAssert(w3.bottomRight.getY() == w4.bottomRight.getY());
}
UPoint OSMMapParamFactory::getTranslationOffsets(int zoomIndex)
{
   BoundingBox wholeBox = m_impl->grid.getCompleteImageGridBox(zoomIndex);

   // We increment by one since we want the complete width and not the
   // distance between two pixels
   int extentX = (1 + wholeBox.bottomRight.getX()) - wholeBox.topLeft.getX();
   int extentY = (1 + wholeBox.topLeft.getY()) - wholeBox.bottomRight.getY();
   
   int translateX = extentX / 2;
   
   int translateY = extentY / 2;

   return UPoint(translateX, translateY);
}
void OSMMapFactoryTest::testGridToWorldSteps()
{
   BoundingBox w = m_impl->factory.getWorldBoxForParam(0, 0, 0);  
   
   rtAssert(w.topLeft.getX() == MIN_INT32 + 1);
   rtAssert(w.topLeft.getY() == MAX_INT32);
   rtAssert(w.bottomRight.getX() == MAX_INT32);
   rtAssert(w.bottomRight.getY() == MIN_INT32 + 1);

   BoundingBox w1 = m_impl->factory.getWorldBoxForParam(0, 0, 1);
   BoundingBox w2 = m_impl->factory.getWorldBoxForParam(1, 0, 1);
   BoundingBox w3 = m_impl->factory.getWorldBoxForParam(1, 1, 1);  
   BoundingBox w4 = m_impl->factory.getWorldBoxForParam(0, 1, 1);
   
   rtAssert(w1.bottomRight == UPoint(0, 0));
   rtAssert(w2.topLeft.getX() == 0);
   rtAssert(w2.bottomRight.getY() == 0);
   rtAssert(w3.topLeft == UPoint(0, 0));
   rtAssert(w4.topLeft.getY() == 0);
   rtAssert(w4.bottomRight.getX() == 0);

   rtAssert(w1.topLeft.getY() == w2.topLeft.getY());
   rtAssert(w3.bottomRight.getY() == w4.bottomRight.getY());
}
void Application::HandleEvents()
{
    SDL_Event event;

    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
            case SDL_QUIT:
                fprintf(stderr,"QUIT!\n");
                m_running = false;
                break;
	    case SDL_VIDEORESIZE:
		Settings::Instance()->SetResolution(UPoint(event.resize.w, event.resize.h));
		break;
            case SDL_MOUSEMOTION:
                m_cursorX = event.motion.x;
                m_cursorY = event.motion.y;

                m_rootWidget->handleMotion(SPoint(event.motion.x, event.motion.y)); 
                break;
            case SDL_MOUSEBUTTONDOWN:
                gpaloff++;
                m_rootWidget->handleButtonDown( event.button.button,
                                                SPoint(event.button.x, event.button.y));
                break;
            case SDL_MOUSEBUTTONUP:
                m_rootWidget->handleButtonUp(   event.button.button,
                                                SPoint(event.button.x, event.button.y));
                break;
            case SDL_KEYDOWN:
                if (event.key.keysym.sym == SDLK_F11)
                    Settings::Instance()->ToggleFullscreen();
            
                m_rootWidget->handleKeyDown(&(event.key.keysym));
                break;
            case SDL_KEYUP:
                m_rootWidget->handleKeyUp(&(event.key.keysym));
                break;
        }
    }
}
Exemple #20
0
//---------------------------------------------------------------------------------------
void TableRowLayouter::layout_in_box()
{
    LOMSE_LOG_DEBUG(Logger::k_layout, string(""));

    set_cursor_and_available_space();
    LUnits yPos = m_pageCursor.y;

    //loop to layout the cells in this rows group range
    vector<LUnits> cellHeights;
    cellHeights.assign(m_cellLayouters.size(), 0.0f);

    int iRow = m_iFirstRow;
    for (int i=0; i < m_numRows; ++i, ++iRow)
    {
        LUnits xPos = m_pItemMainBox->get_content_left();
        for (int iCol=0; iCol < m_numColumns; ++iCol)
        {
            int iCell = iRow * m_numColumns + iCol;
            if (m_cellLayouters[iCell] != nullptr)
            {
                LUnits height = layout_cell(m_cellLayouters[iCell], m_pItemMainBox,
                                            UPoint(xPos, m_pageCursor.y));
                cellHeights[iCell] = height;
            }
            xPos += m_columnsWidth[iCol];
        }
    }

    //set height and final position of cells
    TableCellSizer sizer(m_cellLayouters, cellHeights, m_iFirstRow,
                         m_numRows, m_numColumns);
    sizer.assign_height_and_reposition_cells();
    yPos += sizer.get_total_height();

    //update cursor and available space
    LUnits height = yPos - m_pageCursor.y;
    m_pageCursor.y = yPos;
    m_availableHeight -= height;

    set_layout_is_finished(true);
}
void SkirmishMenuState::resize()
{
    MainMenuBaseState::resize();
    UPoint resolution = set->GetResolution();

    m_missionLabel->setPosition(SPoint(8,8));
    m_missionCounter->setPosition(m_missionLabel->getPosition() + SPoint(m_missionLabel->getSize().x + 5, 0));
    m_butPlus->setPosition(m_missionCounter->getPosition() + SPoint(m_missionCounter->getSize().x + 5, -2));
    m_butMinus->setPosition(m_missionCounter->getPosition() + SPoint(m_missionCounter->getSize().x + 5, 8));

    ImagePtr tmp(new Image(m_missionLabel->getSize() + m_missionLabel->getPosition() + SPoint(m_missionCounter->getSize().x + m_butPlus->getSize().x + 20, 5)));
    tmp->setColorKey();
    tmp->drawBorders1();

    m_missionFrame->changeBackground(tmp);

    SPoint midPos = m_menuFrame->getPosition() + SPoint(m_menuFrame->getSize().x, m_menuBottomFrame->getPosition().y);
    SPoint pos = midPos + (UPoint(resolution.x - midPos.x,m_menuBottomFrame->getSize().y)/2) - (m_missionFrame->getSize()/2);

    m_missionFrame->setPosition(pos);
}
StructureClass::StructureClass(const PlayerClass& newOwner, const std::string& structureName, uint32_t attribute) : ObjectClass(newOwner, structureName, attribute | OBJECT_STRUCTURE)
{
    m_justPlacedTimer = 0;
    try {
	    m_firstAnimFrame = python::extract<int>(m_pyObject.attr("firstAnimFrame"));
	    m_lastAnimFrame = python::extract<int>(m_pyObject.attr("lastAnimFrame"));
	    m_powerRequirement = python::extract<int>(m_pyObject.attr("powerRequirement"));
    }
    catch(python::error_already_set const &)
    {
        LOG(LV_FATAL, m_objectType, "Error loading object: %s", getObjectName().c_str());
        PyErr_Print();
        exit(EXIT_FAILURE);
    }

    m_selectionBox.reset(new Image(UPoint(w,h)));
    m_selectionBox->setColorKey();
    Rect rect(0, 0, w, h);
    m_selectionBox->drawRect(rect, COLOUR_WHITE);

}
//---------------------------------------------------------------------------------------
void ScoreCaretPositioner::caret_at_end_of_staff(Caret* pCaret)
{
    //cursor is at end of a staff or end of score. Score is not empty.
    //No current staffobj but a previous one must exist.
    //Place cursor 0.8 lines (8 tenths) at the right of last staffobj

    //get info for prev object
    SpElementCursorState spState = m_pScoreCursor->get_state();
    m_pScoreCursor->move_prev();
    ImoId id = m_pScoreCursor->id();
    int staff = m_pScoreCursor->staff();
    m_pScoreCursor->restore_state(spState);

    URect bounds = get_bounds_for_imo(id, staff);

    bounds.x += tenths_to_logical(8);
    set_caret_y_pos_and_height(&bounds, id, staff);

    pCaret->set_type(Caret::k_line);
    pCaret->set_position( UPoint(bounds.right(), bounds.top()) );
    pCaret->set_size( USize(bounds.get_width(), bounds.get_height()) );
    set_caret_timecode(pCaret);
}
Exemple #24
0
//---------------------------------------------------------------------------------------
GmoShape* ClefEngraver::create_shape(ImoClef* pCreatorImo, UPoint uPos, int clefType,
                                     int symbolSize, Color color)
{
    m_nClefType = clefType;
    m_symbolSize = symbolSize;
    m_iGlyph = find_glyph(clefType);

    // get the shift to the staff on which the clef must be drawn
    LUnits y = uPos.y + m_pMeter->tenths_to_logical(get_glyph_offset(), m_iInstr, m_iStaff);

    //Add minimum space before clef change
    LUnits x = uPos.x;
    if (symbolSize == k_size_cue)
        x += m_pMeter->tenths_to_logical(20.0f, m_iInstr, m_iStaff);

    double fontSize = determine_font_size();

    //create the shape object
    ShapeId idx = 0;
    m_pClefShape = LOMSE_NEW GmoShapeClef(pCreatorImo, idx, m_iGlyph, UPoint(x, y),
                                        color, m_libraryScope, fontSize);
    return m_pClefShape;
}
Exemple #25
0
bool GameMan::LoadScenario(std::string scenarioName)
{
    eastwood::IniFile *myInifile = new eastwood::IniFile(ResMan::Instance()->getFile(scenarioName));

    int tacticalPos = myInifile->getIntValue("BASIC", "TacticalPos", 0);
    m_tacticalPos = SPoint(tacticalPos % 64, tacticalPos / 64);

    int SeedNum = myInifile->getIntValue("MAP", "Seed", -1);

    if (SeedNum == -1)
    {
	LOG(LV_ERROR, "GameMan", "Cannot find Seednum in %s!", scenarioName.c_str());
	delete m_map;
	return false;
    }

    std::string FieldString = myInifile->getStringValue("MAP", "Field");
    std::string BloomString = myInifile->getStringValue("MAP", "Bloom");

    m_map = MapGenerator::Instance()->createOldMap(FieldString, SeedNum, BloomString);
    // now set up all the players

    AddPlayer(HOUSE_ATREIDES, false, 1);
    AddPlayer(HOUSE_ORDOS, false, 2);
    AddPlayer(HOUSE_HARKONNEN, false, 2);
    AddPlayer(HOUSE_SARDAUKAR, false, 2);
    AddPlayer(HOUSE_FREMEN, false, 2);
    AddPlayer(HOUSE_MERCENARY, false, 2);

    eastwood::IniFile::KeyListHandle myListHandle;

    myListHandle = myInifile->KeyList_Open("UNITS");

    while (!myInifile->KeyList_EOF(myListHandle))
    {
	std::string tmpkey = myInifile->KeyList_GetNextKey(&myListHandle);
	std::string tmp = myInifile->getStringValue("UNITS", tmpkey);
	std::string HouseStr, UnitStr;
	int health, pos;
	sScanf(tmp, "%S,%S,%d,%d", &HouseStr, &UnitStr, &health, &pos);

	int house;

	if ((HouseStr == "Atreides") || (HouseStr == "ATREIDES"))
	    house = HOUSE_ATREIDES;
	else if ((HouseStr == "Ordos") || (HouseStr == "ORDOS"))
	    house = HOUSE_ORDOS;
	else if ((HouseStr == "Harkonnen") || (HouseStr == "HARKONNEN"))
	    house = HOUSE_HARKONNEN;
	else if ((HouseStr == "Fremen") || (HouseStr == "FREMEN"))
	    house = HOUSE_FREMEN;
	else if ((HouseStr == "Sardaukar") || (HouseStr == "SARDAUKAR"))
	    house = HOUSE_SARDAUKAR;
	else if ((HouseStr == "Mercenary") || (HouseStr == "MERCENARY"))
	    house = HOUSE_MERCENARY;
	else
	{
	    LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid house string: %s", HouseStr.c_str());
	    house = HOUSE_ATREIDES;
	}

	if (pos <= 0)
	{
	    LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid position string: %d", pos);
	    pos = 0;
	}

	ObjectPtr newUnit = m_players[house].placeUnit(UnitStr, UPoint(pos % 64, pos / 64));
	if (!newUnit)
	    LOG(LV_WARNING, "GameMan", "LoadScenario: This file is not a valid unit entry: %d. (invalid unit position)", pos);
    }

    myInifile->KeyList_Close(&myListHandle);


    myListHandle = myInifile->KeyList_Open("STRUCTURES");

    while (!myInifile->KeyList_EOF(myListHandle))
    {
	std::string tmpkey = myInifile->KeyList_GetNextKey(&myListHandle);
	std::string tmp = myInifile->getStringValue("STRUCTURES", tmpkey);

	if (tmpkey.find("GEN") == 0)
	{
	    // Gen Object/Structure
	    std::string PosStr = tmpkey.substr(3, tmpkey.size() - 3);
	    int pos = atoi(PosStr.c_str());

	    std::string HouseStr, BuildingStr;
	    sScanf(tmp, "%S,%S", &HouseStr, &BuildingStr);

	    int house;

	    if ((HouseStr == "Atreides") || (HouseStr == "ATREIDES"))
		house = HOUSE_ATREIDES;
	    else if ((HouseStr == "Ordos") || (HouseStr == "ORDOS"))
		house = HOUSE_ORDOS;
	    else if ((HouseStr == "Harkonnen") || (HouseStr == "HARKONNEN"))
		house = HOUSE_HARKONNEN;
	    else if ((HouseStr == "Fremen") || (HouseStr == "FREMEN"))
		house = HOUSE_FREMEN;
	    else if ((HouseStr == "Sardaukar") || (HouseStr == "SARDAUKAR"))
		house = HOUSE_SARDAUKAR;
	    else if ((HouseStr == "Mercenary") || (HouseStr == "MERCENARY"))
		house = HOUSE_MERCENARY;
	    else
	    {
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid house string: %s", HouseStr.c_str());
		house = HOUSE_ATREIDES;
	    }

	    /*
	    //FIXME: Fix this here and in addPlayer
	    if(m_players->size() > house) {
	    LOG(LV_ERROR, "MapGenerator","player[%d]== NULL",(int) house);
	    exit(EXIT_FAILURE);
	    }
	    */


	    //Using INVALID_POS instead of NONE to avoid warnings.
	    //FIXME: Maybe we should rename INVALID_POS to INVALID or sth
	    if (BuildingStr == "Concrete")
		m_players[house].placeStructure(INVALID_POS, INVALID_POS, "Slab1", UPoint(pos % 64, pos / 64));
	    else if (BuildingStr == "Wall")
		m_players[house].placeStructure(INVALID_POS, INVALID_POS, "Wall", UPoint(pos % 64, pos / 64));
	    else
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid building string: %s", BuildingStr.c_str());
	}
	
	else
	{
	    // other structure
	    std::string HouseStr, BuildingStr;
	    int health, pos;
	    sScanf(tmp, "%S,%S,%d,%d", &HouseStr, &BuildingStr, &health, &pos);

	    int house;

	    if ((HouseStr == "Atreides") || (HouseStr == "ATREIDES"))
		house = HOUSE_ATREIDES;
	    else if ((HouseStr == "Ordos") || (HouseStr == "ORDOS"))
		house = HOUSE_ORDOS;
	    else if ((HouseStr == "Harkonnen") || (HouseStr == "HARKONNEN"))
		house = HOUSE_HARKONNEN;
	    else if ((HouseStr == "Fremen") || (HouseStr == "FREMEN"))
		house = HOUSE_FREMEN;
	    else if ((HouseStr == "Sardaukar") || (HouseStr == "SARDAUKAR"))
		house = HOUSE_SARDAUKAR;
	    else if ((HouseStr == "Mercenary") || (HouseStr == "MERCENARY"))
		house = HOUSE_MERCENARY;
	    else
	    {
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid house string: %s", HouseStr.c_str());
		house = HOUSE_ATREIDES;
	    }

	    //Using INVALID_POS instead of NONE to avoid warnings.
	    //FIXME: Maybe we should rename INVALID_POS to INVALID or sth
	    ObjectPtr newStructure = m_players[house].placeStructure(INVALID_POS, INVALID_POS, BuildingStr, UPoint(pos % 64, pos / 64));

	    if (newStructure == NULL)
		LOG(LV_WARNING, "GameMan", "LoadScenario: Invalid position: %d", pos);
	}
    }

    myInifile->KeyList_Close(&myListHandle);
    return true;
}
//---------------------------------------------------------------------------------------
UPoint BarlineEngraver::get_drag_offset()
{
    //return left side, vertical center
    URect bounds = m_pBarlineShape->get_bounds();
    return UPoint(0.0, bounds.get_height() / 2.0);
}
//---------------------------------------------------------------------------------------
void ScorePlayerCtrl::on_draw(Drawer* pDrawer, RenderOptions& UNUSED(opt))
{
    Color color = (m_fEnabled ? m_currentColor : Color(192, 192, 192));
    Color white(255, 255, 255);
    Color black(0, 0, 0);
    Color dark(83, 80, 72);
    Color clear = white;
    LUnits x = m_pos.x;
    LUnits y = m_pos.y;
    LUnits width = m_width;     //m_fFullView ? 4000.0f : m_width;

    //draw box gradient and border
    //dark.a = 45;
    Color light(dark);
    light = light.gradient(white, 0.2);

    pDrawer->begin_path();
    pDrawer->fill(dark);
    pDrawer->stroke(black);
    pDrawer->stroke_width(15.0);

    pDrawer->gradient_color(white, 0.0, 0.1);
    pDrawer->gradient_color(white, dark, 0.1, 0.7);
    pDrawer->gradient_color(dark, light, 0.7, 1.0);
    pDrawer->fill_linear_gradient(m_pos.x, m_pos.y,
                                  m_pos.x, m_pos.y + m_height);

    pDrawer->rect(UPoint(x, y), USize(width, m_height), 100.0f);
    pDrawer->end_path();

    switch (m_playButtonState)
    {
    case k_play:
//            //triangle (play)
//            pDrawer->begin_path();
//            pDrawer->fill(clear);
//            pDrawer->stroke(color);
//            pDrawer->move_to(x + 360.0f, y + 130.0f);
//            pDrawer->line_to(x + 640.0f, y + 300.0f);
//            pDrawer->line_to(x + 360.0f, y + 470.0f);
//            pDrawer->close_subpath();
//            pDrawer->end_path();
//            break;

        //triangle (play)
        if (!m_fFullView)
        {
            //mouse out
            pDrawer->begin_path();
            pDrawer->fill(clear);
            pDrawer->stroke(color);
            pDrawer->move_to(x + 360.0f, y + 130.0f);
            pDrawer->line_to(x + 640.0f, y + 300.0f);
            pDrawer->line_to(x + 360.0f, y + 470.0f);
            pDrawer->close_subpath();
            pDrawer->end_path();
        }
        else
        {
            //mouse in
            pDrawer->begin_path();
            Color blurred(255, 255, 220);   // = color;
            Color none(255, 255, 255, 0);
            blurred.a = 150;
            pDrawer->fill(blurred);
            pDrawer->stroke(none);
            pDrawer->move_to(x + 360.0f - 50.0f, y + 130.0f - 80.0f);
            pDrawer->line_to(x + 640.0f + 100.0f, y + 300.0f);
            pDrawer->line_to(x + 360.0f - 50.0f, y + 470.0f + 80.0f);
            pDrawer->close_subpath();
            pDrawer->end_path();

            pDrawer->begin_path();
            blurred.a = 220;
            pDrawer->fill(blurred);
            pDrawer->stroke(none);
            pDrawer->move_to(x + 360.0f - 25.0f, y + 130.0f - 40.0f);
            pDrawer->line_to(x + 640.0f + 50.0f, y + 300.0f);
            pDrawer->line_to(x + 360.0f - 25.0f, y + 470.0f + 40.0f);
            pDrawer->close_subpath();
            pDrawer->end_path();

//                pDrawer->begin_path();
//                pDrawer->fill(color);
//                pDrawer->stroke(color);
//                pDrawer->move_to(x + 360.0f, y + 130.0f);
//                pDrawer->line_to(x + 640.0f, y + 300.0f);
//                pDrawer->line_to(x + 360.0f, y + 470.0f);
//                pDrawer->close_subpath();
//                pDrawer->end_path();


// see www.crossgl.com/aggpas/documentation

            Color red(255,0,0);
            Color yellow(255,255,0);
            red = red.gradient(red, 0.2);

            pDrawer->begin_path();
            pDrawer->fill(red);
            pDrawer->stroke(red);
            pDrawer->stroke_width(10.0);
            pDrawer->gradient_color(red, 0.0, 0.1);
            pDrawer->gradient_color(red, yellow, 0.1, 0.90);
            pDrawer->gradient_color(yellow, white, 0.90, 1.0);
            pDrawer->fill_linear_gradient(x, y+130.0f, x, y+470.0f);
            pDrawer->move_to(x + 360.0f, y + 130.0f);
            pDrawer->line_to(x + 640.0f, y + 300.0f);
            pDrawer->line_to(x + 360.0f, y + 470.0f);
            pDrawer->close_subpath();
            pDrawer->end_path();

        }
        break;

//            //draw glowing line
// glow effect is just drawing a blured layer in light color, under main layer.
// in this test, instaed of blurring the original shape, just do a secon drawing more
// light
//            set_alpha(0.2)
//            set_line_width(5)
//            draw_line
//            set_alpha(0.07)
//            set_line_width(15)
//            draw_line


    case k_stop:
        //square (stop)
        pDrawer->begin_path();
        pDrawer->fill(clear);
        pDrawer->stroke(color);
        pDrawer->rect(UPoint(x+370.0f, y+170.0f), USize(260.0f, 260.0f), 0.0f);
        pDrawer->end_path();
        break;

    case k_pause:
        //two bars (pause)
        pDrawer->begin_path();
        pDrawer->fill(clear);
        pDrawer->stroke(color);
        pDrawer->rect(UPoint(x+150.0f, y+150.0f), USize(120.0f, 300.0f), 0.0f);
        pDrawer->rect(UPoint(x+330.0f, y+150.0f), USize(120.0f, 300.0f), 0.0f);
        pDrawer->end_path();
        break;

    default:
        ;
    }
}
Exemple #28
0
void BoringButton::redraw()
{
    m_surfNormal.reset(new Image(UPoint(w,h)));
    m_surfPressed.reset(new Image(UPoint(w,h)));
	m_surface = m_surfNormal;
    if (m_menuButton)
    {

        m_surfNormal->fillRect(115);
        m_surfPressed->fillRect(116);
        
        /*
         * Button normal
         */   
        // top lines 
        m_surfNormal->drawHLine(UPoint(0, 0), w-1, 229, false);
        m_surfNormal->drawHLine(UPoint(0, 1), w-3, 108, false);

        // left lines
        m_surfNormal->drawVLine(UPoint(0, 0), h-1, 229, false);
        m_surfNormal->drawVLine(UPoint(1, 1), h-2, 108, false);
       
        // bottom lines
        m_surfNormal->drawHLine(UPoint(1, h-2), w-2, 226, false);
        m_surfNormal->drawHLine(UPoint(0, h-1), w-1, 229, false);
        
        // right lines
        m_surfNormal->drawVLine(UPoint(w-1, 0), h-1, 229, false);
        m_surfNormal->drawVLine(UPoint(w-2, 1), h-2, 226, false);
        
        // final pixels to make it look really duneish
        m_surfNormal->putPixel(UPoint(1, h-2), 115);
        m_surfNormal->putPixel(UPoint(w-2, 1), 115);
        m_surfNormal->putPixel(UPoint(w-2, h-2), 227);


        /*
         * Button pressed
         */   
        // top lines 
        m_surfPressed->drawHLine(UPoint(0, 0), w-1, 229, false);
        m_surfPressed->drawHLine(UPoint(0, 1), w-3, 226, false);

        // left lines
        m_surfPressed->drawVLine(UPoint(0, 0), h-1, 229, false);
        m_surfPressed->drawVLine(UPoint(1, 1), h-2, 226, false);
       
        // bottom lines
        m_surfPressed->drawHLine(UPoint(1, h-2), w-2, 226, false);
        m_surfPressed->drawHLine(UPoint(0, h-1), w-1, 229, false);
        
        // right lines
        m_surfPressed->drawVLine(UPoint(w-1, 0), h-1, 229, false);
        m_surfPressed->drawVLine(UPoint(w-2, 1), h-2, 226, false);
        
        // final pixels to make it look really duneish
        m_surfPressed->putPixel(UPoint(1, h-2), 227);
        m_surfPressed->putPixel(UPoint(w-2, 1), 227);
        m_surfPressed->putPixel(UPoint(w-2, h-2), 227);
        
    } else
    {
//        Rect rect(0,0, w, h);
        m_surfNormal->fillRect(133);
        m_surfPressed->fillRect(134);

	//FIXME: This causes a crash when calling destructor
	/*m_surfNormal->drawRect(rect, 0, false);
        m_surfPressed->drawRect(rect, 0, false);*/
        
        m_surfNormal->drawHLine(UPoint(1, 1), w-2, 132, false);
        m_surfNormal->drawVLine(UPoint(1, 2), h-2, 132, false);
        
    }
    
    eastwood::FntFile* font = FontManager::Instance()->getFont("INTRO:INTRO.FNT");

    uint16_t fontColour;
    
    m_menuButton ? fontColour = 49 : fontColour = 105;

    uint16_t textw, texth;
    font->extents(m_caption.c_str(), textw, texth);

    m_surfNormal->renderText(m_caption.c_str(), font,
                    (w / 2) - (textw / 2), 
                    ((h / 2) - (texth / 2)), fontColour);
    m_surfPressed->renderText(m_caption.c_str(), font,
                    (w / 2) - (textw / 2), 
                    ((h / 2) - (texth / 2)), fontColour);


}