--- /dev/null
+\r
+#include "core.h"\r
+\r
+UI_InputBox *InputBox_Initialise(UI_Sheet_Control *sheetctrl, IO_MemoryControl *memctrl, uint x, uint y, uint xsize, uint ysize, uint txtbufsize, uint forecol, uint backcol, uint height)\r
+{\r
+ UI_InputBox *box;\r
+\r
+ box = MemoryBlock_Allocate_System(sizeof(UI_InputBox));\r
+ MemoryBlock_Write_Description(box, "UI_InputBox");\r
+\r
+ xsize = xsize & ~7;\r
+ ysize = ysize & ~15;\r
+ box->sheet = Sheet_Get(sheetctrl, xsize, ysize, 0, 0);\r
+ box->input_buf_size = txtbufsize;\r
+ box->input_buf = (uchar *)MemoryBlock_Allocate_User(box->input_buf_size, memctrl);\r
+ MemoryBlock_Write_Description(box->input_buf, "INPBOX_TXTBUF");\r
+ box->input_count = 0;\r
+ box->cursor.x = 0;\r
+ box->cursor.y = 0;\r
+ box->prompt.x = -8;\r
+ box->prompt.y = 0;\r
+ box->forecol = forecol;\r
+ box->backcol = backcol;\r
+ box->cursor_state = false;\r
+ box->record = true;\r
+ Draw_Fill_Rectangle(box->sheet->vram, box->sheet->size.x, box->backcol, 0, 0, box->sheet->size.x - 1, box->sheet->size.y - 1);\r
+ Sheet_Show(box->sheet, x, y, height);\r
+ return box;\r
+}\r
+\r
+int InputBox_Put_String(UI_InputBox *box, const uchar *s)\r
+{\r
+ uint i;\r
+ int count, old;\r
+\r
+ if(!box->record){\r
+ InputBox_Put_String_Main(box, s);\r
+ return 0;\r
+ }\r
+\r
+ count = 0;\r
+\r
+ for(i = 0; s[i] != 0x00; i++){\r
+ if(s[i] == '\b'){\r
+ if(count != 0){\r
+ count--;\r
+ }\r
+ } else{\r
+ count++;\r
+ }\r
+ }\r
+\r
+ if(count > (box->input_buf_size - box->input_count)){\r
+ return -1;\r
+ }\r
+\r
+ InputBox_Put_String_Main(box, s);\r
+\r
+ old = count;\r
+ count = 0;\r
+\r
+ for(i = 0; count < old; i++){\r
+ if(s[i] == '\b'){\r
+ if(count != 0) count--;\r
+ } else{\r
+ box->input_buf[box->input_count + count] = s[i];\r
+ count++;\r
+ }\r
+ }\r
+ box->input_buf[box->input_count + count] = 0x00;\r
+ box->input_count += count;\r
+\r
+ return count; \r
+}\r
+\r
+int InputBox_Put_Character(UI_InputBox *box, uchar c)\r
+{\r
+ uchar str[2];\r
+\r
+ str[0] = c;\r
+ str[1] = 0x00;\r
+ return InputBox_Put_String(box, str);\r
+}\r
+\r
+void InputBox_Put_String_Main(UI_InputBox *box, const uchar *str)\r
+{\r
+ int i;\r
+ uchar s[3];\r
+\r
+ InputBox_Check_NewLine(box);\r
+\r
+ for(i = 0; ; i++){\r
+ if(str[i] == 0x00){\r
+ break;\r
+ } else if(str[i] == '\r'){\r
+\r
+ } else if(str[i] == '\n'){\r
+ InputBox_NewLine_No_Prompt(box);\r
+ } else if(str[i] == '\t'){\r
+ for(;;){\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ box->cursor.x += 8;\r
+ InputBox_Check_NewLine(box);\r
+ if((box->cursor.x & 0x1f) == 0 && box->cursor.x != 0) break;\r
+ }\r
+ } else if(str[i] == '\b'){\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ box->cursor.x -= 8;\r
+ InputBox_Check_NewLine(box);\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ if(box->input_count != 0 && box->record){\r
+ box->input_count--;\r
+ box->input_buf[box->input_count] = 0x00;\r
+ }\r
+ } else{\r
+ s[0] = str[i];\r
+ s[1] = 0x00;\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ Sheet_Draw_Put_String(box->sheet, box->cursor.x, box->cursor.y, box->forecol, s);\r
+ box->cursor.x += 8;\r
+ InputBox_Check_NewLine(box);\r
+ }\r
+ }\r
+ return;\r
+}\r
+\r
+void InputBox_Check_NewLine(UI_InputBox *box)\r
+{\r
+ if(box->cursor.x <= box->prompt.x || box->cursor.x < 0){ /*\83v\83\8d\83\93\83v\83g\82Ü\82½\82Í\89æ\96Ê\82æ\82è\8d¶\82É\88Ú\93®\82µ\82æ\82¤\82Æ\82µ\82½*/\r
+ if(box->cursor.y != box->prompt.y){ /*\83v\83\8d\83\93\83v\83g\82Æ\93¯\82¶\8ds\82Å\82Í\82È\82¢*/\r
+ box->cursor.y -= 16;\r
+ box->cursor.x = box->sheet->size.x - 8;\r
+ } else{/*\83v\83\8d\83\93\83v\83g\82Æ\93¯\82¶\8ds*/\r
+ box->cursor.y = box->prompt.y;\r
+ box->cursor.x = box->prompt.x + 8;\r
+ }\r
+ } else if(box->cursor.x >= box->sheet->size.x){\r
+ if(box->cursor.y <= box->sheet->size.y - 17){\r
+ box->cursor.x = box->prompt.x + 8;\r
+ box->cursor.y += 16;\r
+ } else{\r
+ InputBox_Slide_Line(box);\r
+ box->cursor.x = box->prompt.x + 8;\r
+ if(box->prompt.y > 0){\r
+ box->prompt.y -= 16;\r
+ } else{\r
+ box->prompt.y = 0;\r
+ }\r
+ }\r
+ }\r
+ if(box->cursor.y < box->prompt.y){\r
+ box->cursor.y = box->prompt.y;\r
+ }\r
+ return;\r
+}\r
+\r
+void InputBox_NewLine_No_Prompt(UI_InputBox *box)\r
+{\r
+ if(box->cursor.y <= box->sheet->size.y - 17){\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ box->cursor.x = box->prompt.x + 8;\r
+ box->cursor.y = box->cursor.y + 16;\r
+ } else{\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ InputBox_Slide_Line(box);\r
+ box->cursor.x = box->prompt.x + 8;\r
+ }\r
+ InputBox_Check_NewLine(box);\r
+ return;\r
+}\r
+\r
+void InputBox_NewLine(UI_InputBox *box)\r
+{\r
+ if(box->cursor.y <= box->sheet->size.y - 17){\r
+ box->prompt.y = box->cursor.y + 16;\r
+ InputBox_Put_Prompt(box);\r
+ } else{\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 16 - 1, box->cursor.y + 16 - 1);\r
+ InputBox_Slide_Line(box);\r
+ box->prompt.y = box->sheet->size.y - 16;\r
+ InputBox_Put_Prompt(box);\r
+ }\r
+ return;\r
+}\r
+\r
+void InputBox_Slide_Line(UI_InputBox *box)\r
+{\r
+// Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ Draw_Slide_Line(box->sheet->vram, box->sheet->size.x, box->sheet->size.y, box->sheet->size.x, 0, 0);\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, 0, box->sheet->size.y - 16, box->sheet->size.x - 1, box->sheet->size.y - 1);\r
+ box->sheet->Refresh(box->sheet, 0, 0, box->sheet->size.x - 1, box->sheet->size.y - 1);\r
+ return;\r
+}\r
+\r
+void InputBox_Put_Prompt(UI_InputBox *box)\r
+{\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 16 - 1, box->cursor.y + 16 - 1);\r
+ box->prompt.x = 0;\r
+ Sheet_Draw_Put_String(box->sheet, box->prompt.x, box->prompt.y, box->forecol, ">");\r
+ box->cursor.x = box->prompt.x + 8;\r
+ box->cursor.y = box->prompt.y;\r
+ return;\r
+}\r
+\r
+void InputBox_Reset_Input_Buffer(UI_InputBox *box)\r
+{\r
+ box->input_buf[0] = 0x00;\r
+ box->input_count = 0;\r
+ return;\r
+}\r
+\r
+void InputBox_Change_Cursor_State(UI_InputBox *box)\r
+{\r
+ if(box->cursor_state){\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ box->cursor_state = false;\r
+ } else{\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->forecol, box->cursor.x, box->cursor.y, box->cursor.x + 8 - 1, box->cursor.y + 16 - 1);\r
+ box->cursor_state = true;\r
+ }\r
+ return;\r
+}\r
+\r
+void InputBox_Clear(UI_InputBox *box)\r
+{\r
+ InputBox_Reset_Input_Buffer(box);\r
+ box->cursor.x = 0;\r
+ box->cursor.y = 0;\r
+ box->prompt.x = -8;\r
+ box->prompt.y = 0;\r
+ Sheet_Draw_Fill_Rectangle(box->sheet, box->backcol, 0, 0, box->sheet->size.x - 1, box->sheet->size.y - 1);\r
+ return;\r
+}\r
+\r
+void InputBox_Set_Record(UI_InputBox *box, bool record)\r
+{\r
+ box->record = record;\r
+ return;\r
+}\r