Skip to content

Commit

Permalink
created screen_manage.c and top screen cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponali committed Mar 10, 2024
1 parent 4c884df commit 8445a82
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
Binary file added gfx/cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed scratch-3ds.3dsx
Binary file not shown.
6 changes: 2 additions & 4 deletions source/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ static void editorRender(bool scr){
u32 my_blocks_tab_color = C2D_Color32(255, 102, 128, 0xFF);
u32 extension_tab_color = C2D_Color32(15, 189, 140, 0xFF);
u32 colorarray[10] = {motion_tab_color,looks_tab_color,sound_tab_color,events_tab_color,control_tab_color,sensing_tab_color,operators_tab_color,variables_tab_color,my_blocks_tab_color,extension_tab_color};
int i;
for (i=0;i<2;i++)
{
renderBlock(scr?colorarray[i]:colorarray[i+2],blockMatrix[i][0],blockMatrix[i][1],scr?"top screen":"bottom screen");
for(int i=0;i<2;i++){
renderBlock(colorarray[i],blockMatrix[i][0],blockMatrix[i][1],"sample block text");
}

}
Expand Down
21 changes: 5 additions & 16 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ float min(a,b){return a<b?a:b;}

#include <citro2d.h>
#include <3ds.h>
#include "editor.c"

bool screenSwap=true;

void render(bool scr, float touchX, float touchY){
if(scr^screenSwap){
editorBackend(scr,touchX,touchY);
} else {
// temporary triangle
C2D_DrawTriangle(0,0,C2D_Color32(0xFF,10,10,0xFF),150,0,C2D_Color32(10,0xFF,10,0xFF),0,150,C2D_Color32(10,10,0xFF,0xFF),0);
}
}
#include "screen_manage.c"

int main(int argc, char* argv[]) {
gfxInitDefault();
Expand All @@ -34,8 +23,8 @@ int main(int argc, char* argv[]) {
hidScanInput();

u32 kDown = hidKeysDown();
if (kDown & KEY_L)
screenSwap=!screenSwap;
u32 kHeld = hidKeysHeld();
screenSwapCheck(kDown);
if (kDown & KEY_SELECT)
break;

Expand All @@ -47,14 +36,14 @@ int main(int argc, char* argv[]) {
C2D_TargetClear(bot, clear_color);
C2D_SceneBegin(bot);

render(false,touch.px,touch.py);
renderScreen(kDown,kHeld,false,touch.px,touch.py);

C2D_Flush();

C2D_TargetClear(top, clear_color);
C2D_SceneBegin(top);

render(true,0.0f,0.0f);
renderScreen(kDown,kHeld,true,touch.px,touch.py);

C2D_Flush();
C3D_FrameEnd(0);
Expand Down
46 changes: 46 additions & 0 deletions source/screen_manage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "editor.c"

static bool screenSwap=true;
static float cursorX=0;
static float cursorY=0;

static void updateCursor(u32 kHeld){
if(kHeld&KEY_DRIGHT){cursorX++;}
if(kHeld&KEY_DDOWN) {cursorY++;}
if(kHeld&KEY_DLEFT) {cursorX--;}
if(kHeld&KEY_DUP) {cursorY--;}
}

static void renderCursor(float cursorX, float cursorY, bool pressedA){
u32 c=C2D_Color32(10,10,10,0xFF);
if(pressedA){c=C2D_Color32(100,100,100,0xFF);}
C2D_DrawTriangle(cursorX+0,cursorY+0,c,cursorX+15,cursorY+0,c,cursorX+0,cursorY+15,c,0);
}

static void renderScreen(u32 kDown, u32 kHeld, bool scr, float touchX, float touchY){
updateCursor(kHeld);
bool pressedA=false;if(kHeld&KEY_A){pressedA=true;}
float useX=touchX;float useY=touchY;
if(scr){
if(pressedA){
useX=cursorX;
useY=cursorY;
} else {
useX=0.0f;useY=0.0f;
}
}
if(scr^screenSwap){
editorBackend(scr,useX,useY);
} else {
// temporary triangle
C2D_DrawTriangle(0,0,C2D_Color32(0xFF,10,10,0xFF),150,0,C2D_Color32(10,0xFF,10,0xFF),0,150,C2D_Color32(10,10,0xFF,0xFF),0);
}
if(scr){
renderCursor(cursorX,cursorY,pressedA);
}
}

static void screenSwapCheck(u32 kDown){
if (kDown & KEY_L)
screenSwap=!screenSwap;
}

0 comments on commit 8445a82

Please sign in to comment.