Merge branch 'y4mchanges' of https://github.com/y4my4my4m/ZealOS into y4my4my4m-y4mchanges

This commit is contained in:
TomAwezome 2021-11-24 02:31:12 -05:00
commit b873e13590
12 changed files with 483 additions and 0 deletions

2
build/start_zealos.sh Executable file
View file

@ -0,0 +1,2 @@
qemu-system-x86_64 -machine q35,kernel_irqchip=off,accel=kvm -cdrom ./ZealOS-2021-11-02-19_04_16.iso -hda ../dist/ZealOS.qcow2 -m 2G -smp $(nproc) -rtc base=localtime -soundhw pcspk -nic user,model=virtio-net-pci
# qemu-system-x86_64 -machine q35,kernel_irqchip=off,accel=kvm -hda ../dist/ZealOS.qcow2 -m 2G -smp $(nproc) -rtc base=localtime -soundhw pcspk -nic user,model=virtio-net-pci

398
src/Home/PaletteEditor/Load.CC Executable file
View file

@ -0,0 +1,398 @@
#define SLIDER_RANGE 255
#define SLIDER_SPACING 28
#define SLIDER_BORDER 2
#define PALETTES_PATH "~/PaletteEditor/Palettes/"
#include "~/PaletteEditor/PaletteSelect"
I64 current_palette = "*New Palette";
I64 SELECTED_COLOR = 0;
I64 l,r,t,b;
U8 *manual_value;
class CSliderState
{
I64 left_pos;
I64 middle_pos;
I64 right_pos;
I64 preview;
CBGR24 color;
} sld;
I0 DrawPixel(I64 x, I64 y, CBGR24 color)
{
text.fb_alias[x + y * GR_WIDTH] = color;
}
U0 DrawCtrlSlider(CDC *dc,CCtrl *c)
{
CSliderState *s=c->state;
I64 size=(c->win_task->pix_width/16);
I64 border=size/16;
I64 SLIDER_AMOUNT=3;
I64 i,k,j,l;
I64 pos,col;
CBGR24 tempColor;
///////////////////////
// CURRENT SELECTION //
///////////////////////
// current color box preview
dc->color=BLACK;
GrPrint(dc,10,10,"Preview:");
// pixel loop for current color preview
for(i=0; i<=12; i++)
for(j=0; j<=12; j++)
{
tempColor = gr_palette[SELECTED_COLOR];
if(i<border || i>12-border || j<border || j>12-border) tempColor = 0x000000;
DrawPixel(c->win_task->pix_left + 78 + i, t + 7 + j, tempColor);
}
GrPrint(dc,10,26,"Current Color: #%d", SELECTED_COLOR+1);
if(SELECTED_COLOR == 15) dc->color = LTGRAY;
else if(gr_palette[SELECTED_COLOR] > 0xCCCCCC) dc->color=DKGRAY;
else dc->color=15;
GrRect(dc,94,8,58,12);
dc->color=SELECTED_COLOR;
GrPrint(dc,95,10,"#%x%x%x", gr_palette[SELECTED_COLOR].r,
gr_palette[SELECTED_COLOR].g,
gr_palette[SELECTED_COLOR].b);
// palette name
dc->color=BLACK;
GrPrint(dc,10,43,"Palette: %s", current_palette);
////////////
// SLIDER //
////////////
//box
dc->color=LTRED;
GrRect(dc, c->left,
c->top,
SLIDER_SPACING*4+2,
SLIDER_SPACING*2+SLIDER_RANGE);
dc->color=BLUE;
GrRect(dc, c->left+SLIDER_BORDER,
c->top+SLIDER_BORDER,
SLIDER_SPACING*4+2-2*SLIDER_BORDER,
SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);
//slider
dc->color=BLACK;
for(i=1; i<=3; i++)
{
GrLine(dc, c->left+i*SLIDER_SPACING+i-1,
c->top+SLIDER_SPACING,
c->left+i*SLIDER_SPACING+i-1,
c->top+SLIDER_SPACING+SLIDER_RANGE-1);
}
//values
dc->color=LTRED;
for(i=1; i<=3; i++)
{
if (i==1) { pos=s->left_pos; col="R";}
if (i==2) { pos=s->middle_pos;col="G";}
if (i==3) { pos=s->right_pos; col="B";}
//values
GrPrint(dc, c->left+i*SLIDER_SPACING+i-FONT_WIDTH/2,
c->top+SLIDER_SPACING+SLIDER_RANGE+8,
"%d",pos);
//RGB label
GrPrint(dc, c->left+i*SLIDER_SPACING+3-FONT_WIDTH/2,
c->top+14,
"%s", col);
//knobs
GrRect(dc, c->left+i*SLIDER_SPACING+i-4,
c->top+SLIDER_SPACING+SLIDER_RANGE-1-pos-2,
7,5);
}
////////////////////
// COLORS PREVIEW //
////////////////////
dc->color=8;
GrRect(dc,0,c->win_task->pix_height + size*1.5 - size*2 ,c->win_task->pix_width,size*0.75);
for(i=0;i<16;i++){
for (j = 0; j <= size; j++){
for (k = 0; k <= size; k++){
tempColor=gr_palette[i];
// black borders
if(k<border || k>size-border || j < border || j>size-border-1)
{
if(SELECTED_COLOR==i) tempColor=0xFFFFFF;
else tempColor=0x000000;
}
// color preview
DrawPixel(c->win_task->pix_left + j + (size*i), c->win_task->pix_bottom - size*1.5 + k, tempColor);
}
}
// color label and text preview
// TODO: THIS LOGIC DOESNT WORK ON LIGHT THEMES
// if color too light or too dark add bg
if(i==15) dc->color = LTGRAY;
else if(gr_palette[i] < gr_palette[15]) dc->color=LTGRAY;
else if(gr_palette[i] > gr_palette[0]) dc->color=DKGRAY;
//else if(i == 7) dc->color=LTRED;
else dc->color=15;
if(i == SELECTED_COLOR) dc->color=0; GrRect(dc,6,(size*2)+65+16*i,80,18);
GrRect(dc,(size*i),c->win_task->pix_height-(size-size/2),size,size*1.5);
GrRect(dc,6,(size*2)+65+16*i,80,18);
if(i == SELECTED_COLOR) dc->color=15;
else dc->color=i;
I64 bias=(size/2)-4;
if(i >= 9) bias = (size/2)-8;
GrPrint(dc,bias+(i*size),c->win_task->pix_height-(size*.6)+(size/4), "%d", i+1);
GrPrint(dc,10,(size*2)+70+16*i,"#%d: Test",i+1);
}
// Add Save/Load button?
}
U0 PESave(Bool prompt, CCtrl *c)
{
CDoc *doc = DocNew(PALETTES_PATH);
I64 i;
for (i = 0; i < COLORS_NUM; i++)
{
if (i == COLORS_NUM-1) DocPrint(doc, "0x%X", gr_palette[i]);
else DocPrint(doc, "0x%X, ", gr_palette[i]);
}
DocWrite(doc, prompt);
DocDel(doc);
}
U0 PaletteSetTemp(Bool persistent=TRUE)
{//Activate temp palette.
GrPaletteSet(gr_palette);
LFBFlush;
if (persistent)
fp_set_std_palette = &PaletteSetTemp;
}
U0 PalettePrint(){
I64 i;
for(i=0; i<16; i++){
"%d: #%X\n",i,gr_palette[i];
}
}
U0 SelectColor(I64 color_number, CCtrl *c){
SELECTED_COLOR = color_number;
CSliderState *s=c->state;
s->left_pos = gr_palette[SELECTED_COLOR].r;
s->middle_pos= gr_palette[SELECTED_COLOR].g;
s->right_pos = gr_palette[SELECTED_COLOR].b;
}
U0 UpdateDerivedCtrlSlider(CCtrl *c)
{
CSliderState *s=c->state;
c->left=(c->win_task->pix_width/2)-(SLIDER_SPACING*3+2)/2;
c->right=c->left+3*SLIDER_SPACING+2;
c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
// I used to clamp between 0 and 127 and do math but i changed it to 256 for now.
s->left_pos=ClampI64(s->left_pos,0,SLIDER_RANGE);
s->middle_pos=ClampI64(s->middle_pos,0,SLIDER_RANGE);
s->right_pos=ClampI64(s->right_pos,0,SLIDER_RANGE);
// add the slider's RGB value to s->preview // opposite for BGR
s->preview = s->right_pos + s->middle_pos << 8 + s->left_pos << 16; //s->left_pos + s->middle_pos << 8 + s->right_pos << 16;
// cheap way to force redraw 32bit colors
// TODO: make this not stupid
// can I use *last_task?
if (c->win_task->pix_left != l ||
c->win_task->pix_right != r ||
c->win_task->pix_bottom != b ||
c->win_task->pix_top != t){
l=c->win_task->pix_left;
r=c->win_task->pix_right;
t=c->win_task->pix_top;
b=c->win_task->pix_bottom;
LFBFlush;
}
}
U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)
{
CSliderState *s=c->state;
if (x<c->left+1*SLIDER_SPACING+0+SLIDER_SPACING/3)
s->left_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
else if(x<c->left+2*SLIDER_SPACING+1+SLIDER_SPACING/3)
s->middle_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
else
s->right_pos=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
if (c->update_derived_vals)
(*c->update_derived_vals)(c);
// set palette
gr_palette[SELECTED_COLOR] = s->preview;
PaletteSetTemp(FALSE);
current_palette = "*New Palette";
}
CCtrl *SliderNew()
{
CCtrl *c=CAlloc(sizeof(CCtrl));
c->win_task=Fs;
c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;
c->type=CTRLT_GENERIC;
c->state=&sld;
MemSet(&sld,0,sizeof(CSliderState));
c->draw_it=&DrawCtrlSlider;
c->left_click=&LeftClickSlider;
c->update_derived_vals=&UpdateDerivedCtrlSlider;
QueueInsert(c,Fs->last_ctrl);
TaskDerivedValsUpdate;
return c;
}
U0 SliderDel(CCtrl *c)
{
QueueRemove(c);
Free(c);
}
public U0 PaletteEditor()
{
SettingsPush;
MenuPush(
"File {"
" Open(,CH_CTRLO);"
" SaveAs(,CH_CTRLA);"
" Abort(,CH_SHIFT_ESC);"
" Exit(,CH_ESC);"
"}"
"About {"
" Info(,CH_CTRLI);"
"}"
);
DocClear;
CCtrl *c=SliderNew;
I64 arg1,arg2,sc=0;
I64 original_left, original_right, original_top, original_bottom;
original_left = c->win_task->win_left;
original_right = c->win_task->win_right;
original_top = c->win_task->win_top;
original_bottom = c->win_task->win_bottom;
// windowed
c->win_task->win_left = (GR_WIDTH/23);
c->win_task->win_right = (GR_WIDTH/13);
c->win_task->win_top = GR_HEIGHT/80;
c->win_task->win_bottom = GR_HEIGHT/10;
// init pos for 32bit redraw
l=c->win_task->pix_left;
r=c->win_task->pix_right;
t=c->win_task->pix_top;
b=c->win_task->pix_bottom;
SelectColor(0,c);
try
{
while(TRUE)
{
switch(KeyGet(&sc))
{
case '#':
manual_value = StrGet(" Hex Value: #");
gr_palette[SELECTED_COLOR] = Str2I64(manual_value,16);
Free(manual_value);
SelectColor(SELECTED_COLOR,c);
LFBFlush;
DocClear;
break;
case 0:
switch (sc.u8[0])
{
case SC_CURSOR_UP:
case SC_CURSOR_LEFT:
if(SELECTED_COLOR==0) SELECTED_COLOR=16;
SelectColor(SELECTED_COLOR-1,c);
break;
case SC_CURSOR_DOWN:
case SC_CURSOR_RIGHT:
if(SELECTED_COLOR==15) SELECTED_COLOR=-1;
SelectColor(SELECTED_COLOR+1,c);
break;
}
break;
case CH_CTRLO:
current_palette = "";
current_palette = PaletteSelect;
break;
case CH_CTRLI: PopUpOk("\n\n Use the arrows to select color\n\n # to manually input hex value","\n\n\n\t\tMade by y4my4m\n\n"); break;
case CH_CTRLA: PESave(TRUE,c);break;
case CH_ESC: // should make it keep palette on ESC and discard on SHIFT_ESC
case CH_SHIFT_ESC:
LFBFlush;
DocClear;
throw;
}
Refresh;
}
}
catch
PutExcept;
MenuPop;
SettingsPop;
SliderDel(c);
DocBottom;
c->win_task->win_left = original_left;
c->win_task->win_right = original_right;
c->win_task->win_top = original_top;
c->win_task->win_bottom = original_bottom;
}

View file

@ -0,0 +1,40 @@
#define PALETTES_PATH "~/PaletteEditor/Palettes/"
public I64 PaletteSelect()
{
CDirEntry *tmpde1 = NULL, *tmpde2;
CDoc *doc = DocNew;
I64 res = 0;
I64 res2 = 0;
DocPrint(doc, "$$LTBLUE$$\n\n");
tmpde1 = FilesFind("~/PaletteEditor/Palettes/*.CC");
if (tmpde1)
{
while (tmpde1)
{
tmpde2 = tmpde1->next;
res++;
FileExtRemove(tmpde1->name);
DocPrint(doc, " $$MU,\"%d.%s\",LE=0x%X$$\n", res, tmpde1->name, tmpde1->name);
DirEntryDel(tmpde1);
tmpde1 = tmpde2;
}
}
DocPrint(doc, "\n\n$$BT+CX,\"CANCEL\",LE=DOCM_CANCEL$$\n\n");
res2 = PopUpMenu(doc);
DocDel(doc);
if (res2 != (DOCM_CANCEL || 0)) PaletteSet(res2, TRUE);
return res2;
}

View file

@ -0,0 +1 @@
0xFFFFFF, 0x867ADE, 0x00CC55, 0x5A878B, 0xB80000, 0xCC44CC, 0xDD8855, 0xBBBBBB, 0x777777, 0x0088FF, 0xAAFF66, 0xAAFFEE, 0xFF7777, 0xCA94E8, 0xEEEE77, 0x483AAA

View file

@ -0,0 +1 @@
0xEEFCD7, 0x79824F, 0x336019, 0x297582, 0xB34F4B, 0x8F49, 0xA24D1B, 0x444444, 0x6D6D6D, 0x94BFDE, 0xA1CE97, 0x6DB4BE, 0xE88E88, 0xCA94E8, 0xD4B475, 0x142223

View file

@ -0,0 +1 @@
0xE2E8EB, 0x5BD2D4, 0x496076, 0x307AFF, 0xD86D22, 0xFFD91F, 0xFFEF2F, 0x4F8A97, 0xA161C, 0xE24594, 0xA1CE97, 0x6DB4BE, 0xFF575B, 0xB1AA9E, 0xD53368, 0xE2331

View file

@ -0,0 +1 @@
0xE3E3E3, 0x4F84A6, 0x73A255, 0x297582, 0xB34F4B, 0x8A52C3, 0xB7822F, 0x444444,0x6D6D6D, 0x94BFDE, 0xA1CE97, 0x6DB4BE, 0xE88E88, 0xCA94E8, 0xD4B475, 0x1F1F1F

View file

@ -0,0 +1 @@
0x000000, 0x0000AA, 0x00AA00, 0x00AAAA, 0xAA0000, 0xAA00AA, 0xAA5500, 0xAAAAAA, 0x555555, 0x5555FF, 0x55FF55, 0x55FFFF, 0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF

View file

@ -0,0 +1 @@
0xE8E8E9, 0x374B88, 0x6C84FC, 0x297582, 0x63D64E, 0x397AFF, 0xB7822F, 0x25256E, 0x712, 0xFF2A76, 0xA1CE97, 0x6DB4BE, 0x9FA6FF, 0xCA94E8, 0xFFCC00, 0x132C

2
src/Home/PaletteEditor/Run.CC Executable file
View file

@ -0,0 +1,2 @@
#include "~/PaletteEditor/Load.CC";
PaletteEditor;

14
src/Home/PaletteGod.CC Executable file
View file

@ -0,0 +1,14 @@
public U0 PaletteGodGenerate()
{
I64 i;
 for(i=0; i<16; i++)
{
CBGR24 palette = GodPick & 0xFFFFFF;
gr_palette[i] = palette;
GrPaletteSet(gr_palette);
LFBFlush;
}
}
PaletteGodGenerate;

View file

@ -90,3 +90,24 @@ public U0 PaletteSetCommander(Bool persistent=TRUE)
if (persistent) if (persistent)
fp_set_std_palette = &PaletteSetCommander; fp_set_std_palette = &PaletteSetCommander;
} }
public U0 PaletteSet(U8 *palette_name="Slate", Bool persistent=TRUE)
{//Pass filename (without ext) as string to load palette
U8 *dir = "~/PaletteEditor/Palettes/";
U8 path = MStrPrint("%Q%Q%Q",dir,palette_name,".CC");
I64 temp_file, i;
U8 file = FileRead(path);
for (i = 0; i < COLORS_NUM; i++)
{
StrFirstRemove(file,",", temp_file);
gr_palette[i] = Str2I64(temp_file,16);
}
LFBFlush;
//this doesn't work yet...
// if (persistent)
// fp_set_std_palette = &PaletteSet;
}