Skip to content

Commit

Permalink
window
Browse files Browse the repository at this point in the history
  • Loading branch information
wxggg committed Oct 18, 2017
1 parent 8c91aa0 commit b42d36f
Show file tree
Hide file tree
Showing 32 changed files with 1,586 additions and 295 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ KINCLUDE += kern/debug/ \
kern/font \
kern/component \
kern/mm \
kern/init
kern/init \
kern/sync

KSRCDIR += kern/init \
kern/libs \
Expand All @@ -144,7 +145,7 @@ kernel = $(call totarget,kernel)

$(kernel): tools/kernel.ld

$(kernel): $(KOBJS)
$(kernel): $(KOBJS)
@echo + ld $@
$(V)$(LD) $(LDFLAGS) -T tools/kernel.ld -o $@ $(KOBJS)
@$(OBJDUMP) -S $@ > $(call asmfile,kernel)
Expand Down Expand Up @@ -285,4 +286,3 @@ handin: packall
packall: clean
@$(RM) -f $(HANDIN)
@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`

35 changes: 35 additions & 0 deletions kern/component/component.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <component.h>

void draw_frame(graphic_t *g, context_t *contex, frame_t *frame)
{
int x = contex->rect.p.x;
int y = contex->rect.p.y;
rect_t frect = frame->rect;
rect_t realrect = RECT(x+frect.p.x, y+frect.p.y, frect.width, frect.height);
g->fill_rect(realrect, frame->bgc);
g->draw_rect(realrect, frame->frc);
}

void draw_button(graphic_t *g, context_t *contex, button_t *button)
{
draw_frame(g, contex, &button->frame);
rect_t frect = button->frame.rect;
int x1 = contex->rect.p.x + frect.p.x;
int y1 = contex->rect.p.y + frect.p.y;
int x2 = x1 + frect.width-1;
int y2 = y1 + frect.height-1;
g->draw_line(POINT(x1, y1),POINT(x2, y2), button->btc);
g->draw_line(POINT(x1, y2),POINT(x2, y1), button->btc);
}

void draw_list(graphic_t *g, context_t *contex, list_t *list)
{
draw_frame(g, contex, &list->frame);
rect_t frect = list->frame.rect;
int x1 = contex->rect.p.x + frect.p.x;
int y1 = contex->rect.p.y + frect.p.y;
for (size_t i = 0; i < list->n; i++) {
g->draw_line(POINT(x1, y1), POINT(x1+frect.width, y1), list->sepc);
y1 += LIST_H;
}
}
36 changes: 36 additions & 0 deletions kern/component/component.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <types.h>
#include <graphic.h>
#include <window.h>

/*
point or rect of the component are all relative
for example:
if the point of window is (xw, yw) and the point of frame is (xf, yf)
then the real position of frame is (xw+xf, yw+yf)
*/


typedef struct frame_s
{
rect_t rect; // relative rect
rgb_t bgc; // background color
rgb_t frc; // frame color
} frame_t;
void draw_frame(graphic_t *g, context_t *contex, frame_t *frame);

typedef struct button_s
{
frame_t frame; // button frame
rgb_t btc; // button color
} button_t;
void draw_button(graphic_t *g, context_t *contex, button_t *button);

typedef struct list_s
{
frame_t frame; // list frame
rgb_t sepc; // separator color
uint32_t n; // n list item
} list_t;
void draw_list(graphic_t *g, context_t *contex, list_t *list);
30 changes: 16 additions & 14 deletions kern/component/editbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@
#include <stringbuffer.h>
#include <string.h>
#include <bitmap.h>
#include <stdio.h>

keybuf_t kb;

void getcontent(editbox_t *peb)
void getcontent(editbox_t *peb)
{
keybuf_init(&kb);
while(1) {
edit_readline(peb);
edit_runcmd(peb);
}
while(1) {
edit_readline(peb);
edit_runcmd(peb);
}
}

void edit_putchar(char ch, editbox_t *peb)
void edit_putchar(char ch, editbox_t *peb)
{
if(ch == '\n' || ch == '\t') {
peb->cur_y ++;
peb->cur_x = 0;
if(peb->cur_y >= peb->ch_y)
peb->cur_y = 0;
return;
}
}
int x = peb->point.x + peb->cur_x*ASC16_WIDTH;
int y = peb->point.y + peb->cur_y*ASC16_HEIGHT;

draw_asc16(ch, (point_t){x, y}, peb->text_c);
peb->cur_x ++;
if(peb->cur_x >= peb->ch_x) {
peb->cur_x = 0;
peb->cur_y ++;
}
if(peb->cur_y >= peb->ch_y)
if(peb->cur_y >= peb->ch_y)
peb->cur_y = 0;
}
void edit_putstr(char *str, editbox_t *peb)
Expand All @@ -45,12 +46,13 @@ void edit_putstr(char *str, editbox_t *peb)
}
}

void edit_readline(editbox_t *peb)
void edit_readline(editbox_t *peb)
{
int i = 0 , c;
memset(peb->ch,'\0',peb->ch_size);
while (1) {
while((c=keybuf_pop(&kb)) == 0);
cprintf("c:%c\n", c);
if (c < 0) {
return;
}
Expand All @@ -62,7 +64,7 @@ void edit_readline(editbox_t *peb)
i --;
}
else if (c == '\n' || c == '\r') {
peb->ch[i] = '\0';
peb->ch[i] = '\0';
peb->cur_x = 0;
peb->cur_y ++;
if(peb->cur_y >= peb->ch_y-1) peb->ch_y = 0;
Expand All @@ -72,14 +74,14 @@ void edit_readline(editbox_t *peb)
}

void edit_runcmd(editbox_t *peb)
{
{
if(strcmp(peb->ch, "hello") == 0)
edit_putstr("great\n", peb);
else if(strcmp(peb->ch, "system") == 0)
draw_bmp_test();
print_kerninfo();
else if(strcmp(peb->ch, "who are you") == 0)
edit_putstr("I am joker\n", peb);
else if(strcmp(peb->ch, "kerninfo") == 0)
print_kerninfo();
else;
}
}
8 changes: 3 additions & 5 deletions kern/component/editbox.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _KERN_EDITBOX_H
#define _KERN_EDITBOX_H
#pragma once

#include <types.h>
#include <stringbuffer.h>
#include <graphic.h>

extern keybuf_t kb;

Expand All @@ -12,7 +12,7 @@ typedef struct editbox_s
int ch_x; //num of width
int ch_y; // num of height
rgb_t bg_c;
rgb_t text_c;
rgb_t text_c;
int cur_x, cur_y;
char * ch;
int ch_size;
Expand All @@ -21,5 +21,3 @@ typedef struct editbox_s
void getcontent(editbox_t * peb);
void edit_readline(editbox_t *peb);
void edit_runcmd(editbox_t *peb);

#endif
18 changes: 8 additions & 10 deletions kern/debug/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ monitor(struct trapframe *tf) {
if (runcmd(buf, tf) < 0) {
break;
}
}
}
}

}
}

Expand All @@ -112,7 +112,7 @@ mon_help(int argc, char **argv, struct trapframe *tf) {
draw_str16((char*)commands[i].name, (point_t){20, 40+i*16}, (rgb_t){43,43,43});
}
cputchar('*');
_gfillrect2(MediumBlue, (rect_t){200,200,500,500});
// _gfillrect2(MediumBlue, (rect_t){200,200,500,500});
return 0;
}

Expand All @@ -132,12 +132,11 @@ mon_kerninfo(int argc, char **argv, struct trapframe *tf) {
* */
int
mon_bootinfo(int argc, char **argv, struct trapframe *tf) {
struct BOOTINFO* pboot = get_bootinfo();
cprintf("uint8_t: cyls=%d leds=%x ", pboot->cyls, pboot->leds);
cprintf("vmode=%x reserve=%x\n", pboot->vmode, pboot->reserve);
cprintf("uint16_t: scrnx=%d scrny=%d\n", pboot->scrnx, pboot->scrny);
cprintf("uint8_t: bitspixel=%d mem_model=%d\n", pboot->bitspixel, pboot->mem_model);
cprintf("uint8_t: vram=%x\n", pboot->vram);
cprintf("uint8_t: cyls=%d leds=%x ", binfo->cyls, binfo->leds);
cprintf("vmode=%x reserve=%x\n", binfo->vmode, binfo->reserve);
cprintf("uint16_t: scrnx=%d scrny=%d\n", binfo->scrnx, binfo->scrny);
cprintf("uint8_t: bitspixel=%d mem_model=%d\n", binfo->bitspixel, binfo->mem_model);
cprintf("uint8_t: vram=%x\n", binfo->vram);
return 0;
}

Expand All @@ -151,4 +150,3 @@ mon_backtrace(int argc, char **argv, struct trapframe *tf) {
print_stackframe();
return 0;
}

4 changes: 2 additions & 2 deletions kern/font/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ static uint8_t* p_font_asc16_b = (uint8_t*)(FONT_ASC16_ADDR+KERNBASE);
BOOL draw_asc16(char ch, point_t point, rgb_t c)
{
uint8_t * p_asc = p_font_asc16_b + (uint8_t)ch * 16;

graphic_t * g = get_graphic();
for(int y=0; y<ASC16_HEIGHT; y++){
uint8_t testbit = 1 << 7;
for(int x=0; x<ASC16_WIDTH; x++)
{
if(*p_asc & testbit)
setpixel(point.x+x, point.y+y, c);
g->set_pixel(point.x+x, point.y+y, c);
testbit >>= 1;
}
p_asc ++;
Expand Down
38 changes: 0 additions & 38 deletions kern/graphic/bitmap.c

This file was deleted.

5 changes: 1 addition & 4 deletions kern/graphic/bitmap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _KERN_BITMAP_H_
#define _KERN_BITMAP_H_
#pragma once

#include <types.h>

Expand Down Expand Up @@ -34,5 +33,3 @@ typedef struct bitmap24_t
} bitmap_t;

void draw_bmp_test();

#endif
Loading

0 comments on commit b42d36f

Please sign in to comment.