Pager and menu bar working together without interfering with each other
This commit is contained in:
+36
-8
@@ -38,6 +38,18 @@ EditorScene::EditorScene() {
|
|||||||
pager.SetWidth(32*4);
|
pager.SetWidth(32*4);
|
||||||
pager.SetHeight(32*4);
|
pager.SetHeight(32*4);
|
||||||
|
|
||||||
|
font.LoadSurface("rsc\\graphics\\fonts\\pk_white_8.bmp");
|
||||||
|
buttonImage.LoadSurface("rsc\\graphics\\interface\\button_menu.bmp");
|
||||||
|
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||||
|
|
||||||
|
menuBar.SetFont(&font);
|
||||||
|
menuBar.SetImage(&buttonImage);
|
||||||
|
|
||||||
|
menuBar.SetEntries({
|
||||||
|
{"File", "New", "Open", "Save", "Save As...", "Close", "Exit"},
|
||||||
|
{"Edit", "Null"}
|
||||||
|
});
|
||||||
|
|
||||||
// pager.SetOnNew([](Region* const ptr){
|
// pager.SetOnNew([](Region* const ptr){
|
||||||
// printf("New Region: %d, %d\n", ptr->GetX(), ptr->GetY());
|
// printf("New Region: %d, %d\n", ptr->GetX(), ptr->GetY());
|
||||||
// });
|
// });
|
||||||
@@ -71,7 +83,16 @@ void EditorScene::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::Render(SDL_Surface* const screen) {
|
void EditorScene::Render(SDL_Surface* const screen) {
|
||||||
|
//draw the map
|
||||||
pager.DrawTo(screen, &sheetList, camera.x, camera.y);
|
pager.DrawTo(screen, &sheetList, camera.x, camera.y);
|
||||||
|
|
||||||
|
//draw a big bar across the top
|
||||||
|
for (int i = 0; i < screen->w; i += buttonImage.GetClipW()) {
|
||||||
|
buttonImage.DrawTo(screen, i, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw the menu bar
|
||||||
|
menuBar.DrawTo(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -79,18 +100,18 @@ void EditorScene::Render(SDL_Surface* const screen) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
if (motion.state & SDL_BUTTON_LMASK) {
|
menuBar.MouseMotion(motion);
|
||||||
//
|
|
||||||
}
|
if (motion.state & SDL_BUTTON_RMASK) {
|
||||||
else if (motion.state & SDL_BUTTON_RMASK) {
|
|
||||||
camera.x += motion.xrel;
|
camera.x += motion.xrel;
|
||||||
camera.y += motion.yrel;
|
camera.y += motion.yrel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
switch(button.button) {
|
menuBar.MouseButtonDown(button);
|
||||||
case SDL_BUTTON_LEFT: {
|
|
||||||
|
if (button.button == SDL_BUTTON_LEFT && button.y >= buttonImage.GetClipH()) {
|
||||||
Region* ptr = pager.GetRegion(
|
Region* ptr = pager.GetRegion(
|
||||||
snapToBase(pager.GetWidth(), button.x - camera.x),
|
snapToBase(pager.GetWidth(), button.x - camera.x),
|
||||||
snapToBase(pager.GetHeight(), button.y - camera.y)
|
snapToBase(pager.GetHeight(), button.y - camera.y)
|
||||||
@@ -105,11 +126,13 @@ void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
0
|
0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
//
|
int entry, drop;
|
||||||
|
menuBar.MouseButtonUp(button, &entry, &drop);
|
||||||
|
|
||||||
|
cout << "Menu: (" << entry << "," << drop << ")" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::KeyDown(SDL_KeyboardEvent const& key) {
|
void EditorScene::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
@@ -117,6 +140,11 @@ void EditorScene::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
QuitEvent();
|
QuitEvent();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDLK_SPACE:
|
||||||
|
camera.x = 0;
|
||||||
|
camera.y = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,10 @@
|
|||||||
#include "region_pager.hpp"
|
#include "region_pager.hpp"
|
||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "raster_font.hpp"
|
||||||
|
#include "menu_bar.hpp"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
class EditorScene : public BaseScene {
|
class EditorScene : public BaseScene {
|
||||||
@@ -53,6 +57,11 @@ protected:
|
|||||||
RegionPager pager;
|
RegionPager pager;
|
||||||
std::list<TileSheet> sheetList;
|
std::list<TileSheet> sheetList;
|
||||||
|
|
||||||
|
RasterFont font;
|
||||||
|
Image buttonImage;
|
||||||
|
|
||||||
|
MenuBar menuBar;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
} camera;
|
} camera;
|
||||||
|
|||||||
Reference in New Issue
Block a user