Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6864 → Rev 6865

/contrib/sdk/samples/freetype/txview/winlib/button.c
0,0 → 1,158
#include <stdio.h>
#include <string.h>
#include "winlib.h"
 
typedef struct
{
ctrl_t ctrl;
 
uint32_t state;
 
char *caption;
int capt_len;
}button_t;
 
static void button_on_draw(button_t *btn)
{
color_t color = 0xFFD7D7D7;
char t = (char)btn->ctrl.id;
rect_t rc, rci;
 
if(btn->ctrl.style & 1)
{
send_message(btn->ctrl.parent, MSG_OWNERDRAW, btn, 0);
return;
}
 
if(btn->state & bPressed)
color = 0xFFB0B0B0;
else if(btn->state & bHighlight)
color = 0xFFE7E7E7;
 
rc = rci = btn->ctrl.rc;
rci.l++;
rci.t++;
 
px_hline(btn->ctrl.ctx, rc.l, rc.t, btn->ctrl.w, 0xFF646464);
px_fill_rect(btn->ctrl.ctx, &rci, color);
px_hline(btn->ctrl.ctx, rc.l, rc.b-1, btn->ctrl.w, 0xFF646464);
px_vline(btn->ctrl.ctx, rc.l, rc.t+1, btn->ctrl.h-2, 0xFF646464);
px_vline(btn->ctrl.ctx, rc.r-1, rc.t+1, btn->ctrl.h-2, 0xFF646464);
 
rc.l+= 4;
rc.t+= 6;
 
draw_text_ext(btn->ctrl.ctx, btn->ctrl.font, btn->caption, btn->capt_len, &rc, 0xFF000000);
};
 
static void button_on_mouseenter(button_t *btn)
{
btn->state|= bHighlight;
send_message(&btn->ctrl, MSG_DRAW, 0, 0);
}
 
static void button_on_mouseleave(button_t *btn)
{
if( (ctrl_t*)btn != mouse_capture) {
btn->state &= ~bHighlight;
send_message(&btn->ctrl, MSG_DRAW, 0, 0);
};
}
 
static void button_on_lbuttondown(button_t *btn, int x, int y)
{
capture_mouse((ctrl_t*)btn);
btn->state|= bPressed;
send_message(&btn->ctrl, MSG_DRAW, 0, 0);
};
 
static void button_on_lbuttonup(button_t *btn, int x, int y)
{
int action;
 
action = (btn->state & bPressed) ? MSG_COMMAND : 0;
 
release_mouse();
 
if( pt_in_rect( &btn->ctrl.rc, x, y) )
btn->state = bHighlight;
else
btn->state = 0;
 
send_message(&btn->ctrl, MSG_DRAW, 0, 0);
 
if(action)
send_message(btn->ctrl.parent,MSG_COMMAND,btn->ctrl.id,(int)btn);
};
 
static void button_on_mousemove(button_t *btn, int x, int y)
{
int old_state;
 
if( !(btn->state & bHighlight))
{
btn->state|= bHighlight;
send_message(&btn->ctrl, MSG_DRAW, 0, 0);
};
 
if( (ctrl_t*)btn != mouse_capture)
return;
 
old_state = btn->state;
 
if( pt_in_rect(&btn->ctrl.rc, x, y) )
btn->state |= bPressed;
else
btn->state &= ~bPressed;
 
if( old_state ^ btn->state)
send_message(&btn->ctrl, MSG_DRAW, 0, 0);
}
 
int button_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
{
button_t *btn = (button_t*)ctrl;
 
switch( msg )
{
HANDLE_MSG(btn, MSG_DRAW, button_on_draw);
HANDLE_MSG(btn, MSG_MOUSEENTER, button_on_mouseenter);
HANDLE_MSG(btn, MSG_MOUSELEAVE, button_on_mouseleave);
HANDLE_MSG(btn, MSG_LBTNDOWN, button_on_lbuttondown);
HANDLE_MSG(btn, MSG_LBTNDBLCLK, button_on_lbuttondown);
HANDLE_MSG(btn, MSG_LBTNUP, button_on_lbuttonup);
HANDLE_MSG(btn, MSG_MOUSEMOVE, button_on_mousemove);
}
return 0;
};
 
ctrl_t *create_button(char *caption, uint32_t style, int id, int x, int y,
int w, int h, ctrl_t *parent)
{
button_t *btn;
int len;
 
if( !parent )
return NULL;
 
btn = create_control(sizeof(button_t), id, x, y, w, h, parent);
btn->ctrl.style = style;
btn->ctrl.handler = button_proc;
btn->state = 0;
btn->caption = caption;
 
if( !caption )
btn->capt_len = 0;
else
{
len = strlen(caption);
btn->capt_len = len;
if( len )
btn->caption = strdup(caption);
else
btn->caption = NULL;
}
 
return &btn->ctrl;
};
 
/contrib/sdk/samples/freetype/txview/winlib/control.h
0,0 → 1,109
#ifndef __CONTROL_H__
#define __CONTROL_H_
 
#include <stdint.h>
#include <pxdraw.h>
#include "link.h"
 
typedef struct font font_t;
 
typedef struct control ctrl_t;
 
typedef int (handler_t)(ctrl_t*, uint32_t, uint32_t, uint32_t);
 
struct control
{
link_t link;
link_t child;
 
handler_t *handler;
ctrl_t *parent;
 
ctx_t *ctx;
font_t *font;
uint32_t id;
uint32_t style;
 
rect_t rc;
int w;
int h;
};
 
void *create_control(size_t size, int id, int x, int y,
int w, int h, ctrl_t *parent);
 
#define bPressed 2
#define bHighlight 1
 
 
ctrl_t *create_button(char *caption, uint32_t style, int id, int x, int y,
int w, int h, ctrl_t *parent);
 
typedef struct
{
ctrl_t ctrl;
 
uint32_t state;
 
int pix_range;
int min_range;
int max_range;
int page_size;
int thumb_pos;
 
rect_t tl_rect;
rect_t br_rect;
 
ctrl_t *btn_up;
ctrl_t *btn_down;
ctrl_t *thumb;
}scroller_t;
 
 
#define MSG_SYS_PAINT 0x001
#define MSG_SYS_KEY 0x002
#define MSG_SYS_BUTTON 0x003
#define MSG_SYS_MOUSE 0x006
 
#define MSG_LBTNDOWN 0x010
#define MSG_LBTNUP 0x011
#define MSG_RBTNDOWN 0x012
#define MSG_RBTNUP 0x013
#define MSG_MBTNDOWN 0x014
#define MSG_MBTNUP 0x015
#define MSG_WHEELDOWN 0x016
#define MSG_WHEELUP 0x017
 
#define MSG_LBTNDBLCLK 0x018
 
#define MSG_MOUSEMOVE 0x019
#define MSG_MOUSEENTER 0x01A
#define MSG_MOUSELEAVE 0x01B
 
#define MSG_CREATE 0x020
#define MSG_SIZE 0x021
#define MSG_DRAW 0x022
#define MSG_OWNERDRAW 0x023
#define MSG_POSCHANGING 0x024
#define MSG_POSCHANGE 0x025
 
#define MSG_COMMAND 0x030
 
static inline int pt_in_rect(rect_t *rc, int x, int y)
{
if( (x >= rc->l) && (x < rc->r) &&
(y >= rc->t) && (y < rc->b) )
return 1;
return 0;
};
 
 
#define send_message( ctrl, msg, arg1, arg2) \
(ctrl)->handler( (ctrl_t*)(ctrl), \
(uint32_t)(msg), (uint32_t)(arg1), (uint32_t)(arg2))
 
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
 
 
#endif /* __CONTROL_H_ */
/contrib/sdk/samples/freetype/txview/winlib/link.h
0,0 → 1,64
#ifndef __LINK_H__
#define __LINK_H__
 
typedef struct link
{
struct link *prev;
struct link *next;
}link_t;
 
#define LIST_INITIALIZE(name) \
link_t name = { .prev = &name, .next = &name }
 
#define list_get_instance(link, type, member) \
((type *)(((u8_t *)(link)) - ((u8_t *)&(((type *)NULL)->member))))
 
static inline void link_initialize(link_t *link)
{
link->prev = NULL;
link->next = NULL;
}
 
static inline void list_initialize(link_t *head)
{
head->prev = head;
head->next = head;
}
 
static inline void list_append(link_t *link, link_t *head)
{
link->prev = head->prev;
link->next = head;
head->prev->next = link;
head->prev = link;
}
 
static inline void list_remove(link_t *link)
{
link->next->prev = link->prev;
link->prev->next = link->next;
link_initialize(link);
}
 
static inline int list_empty(link_t *head)
{
return head->next == head ? 1 : 0;
}
 
static inline void list_prepend(link_t *link, link_t *head)
{
link->next = head->next;
link->prev = head;
head->next->prev = link;
head->next = link;
}
 
static inline void list_insert(link_t *new, link_t *old)
{
new->prev = old->prev;
new->next = old;
new->prev->next = new;
old->prev = new;
}
 
#endif /* __LINK_H__ */
/contrib/sdk/samples/freetype/txview/winlib/winlib.c
0,0 → 1,615
#include <stdio.h>
#include <string.h>
#include "winlib.h"
 
#define ID_SCROLLER_UP 0x30
#define ID_SCROLLER_DOWN 0x31
#define ID_SCROLLER_THUMB 0x32
 
typedef int v2si __attribute__ ((vector_size (8)));
 
font_t *create_font(void *face, int size);
 
static pos_t old_pos;
ctrl_t *mouse_capture = NULL;
 
 
 
void show_window(window_t *win)
{
BeginDraw();
DrawWindow(0,0,0,0,NULL,0,0x73);
if( (win->win_state != MINIMIZED) &&
(win->win_state != ROLLED) )
show_context(win->ctx);
EndDraw();
}
 
window_t *create_window(char *caption, int style, int x, int y,
int w, int h, handler_t handler)
{
char proc_info[1024];
window_t *win;
 
if(handler==NULL)
return NULL;
 
win = malloc(sizeof(*win));
if(win == NULL)
return NULL;
 
BeginDraw();
DrawWindow(x, y, w+TYPE_3_BORDER_WIDTH*2,
h+TYPE_3_BORDER_WIDTH+get_skin_height(), caption, 0x000000, 0x73);
EndDraw();
 
GetProcInfo(proc_info);
 
x = *(uint32_t*)(proc_info+34);
y = *(uint32_t*)(proc_info+38);
w = *(uint32_t*)(proc_info+42)+1;
h = *(uint32_t*)(proc_info+46)+1;
 
win->handler = handler;
 
list_initialize(&win->link);
list_initialize(&win->child);
 
win->rc.l = x;
win->rc.t = y;
win->rc.r = x + w;
win->rc.b = y + h;
 
win->w = w;
win->h = h;
 
win->client.l = TYPE_3_BORDER_WIDTH;
win->client.t = get_skin_height();
win->client.r = w - TYPE_3_BORDER_WIDTH;
win->client.b = h - TYPE_3_BORDER_WIDTH;
win->clw = win->client.r - win->client.l;
win->clh = win->client.b - win->client.t;
 
win->caption_txt = caption;
win->style = style;
 
win->child_over = NULL;
win->child_focus = NULL;
 
win->ctx = create_context(win->client.l, win->client.t, win->clw, win->clh);
clear_context(win->ctx, 0xFFFFFFFF);
 
win->font = create_font(NULL, 14);
 
send_message((ctrl_t*)win, MSG_CREATE, 0, 0);
send_message((ctrl_t*)win, MSG_DRAW, 0, 0);
 
ctrl_t *child;
 
child = (ctrl_t*)win->child.next;
 
while( &child->link != &win->child)
{
send_message(child, MSG_DRAW, 0, 0);
child = (ctrl_t*)child->link.next;
};
 
show_window(win);
 
return win;
};
 
 
void handle_sys_paint(window_t *win)
{
char proc_info[1024];
int winx, winy, winw, winh;
uint8_t state;
 
GetProcInfo(proc_info);
 
winx = *(uint32_t*)(proc_info+34);
winy = *(uint32_t*)(proc_info+38);
winw = *(uint32_t*)(proc_info+42)+1;
winh = *(uint32_t*)(proc_info+46)+1;
 
state = *(uint8_t*)(proc_info+70);
 
if(state & 2)
{
win->win_state = MINIMIZED;
return;
}
else if(state & 4)
{
win->win_state = ROLLED;
show_window(win);
return;
};
 
if(state & 1)
state = MAXIMIZED;
else
state = NORMAL;
 
if( (win->w != winw) ||
(win->h != winh) )
{
ctrl_t *child;
 
win->client.l = TYPE_3_BORDER_WIDTH;
win->client.t = get_skin_height();
win->client.r = winw - TYPE_3_BORDER_WIDTH;
win->client.b = winh - TYPE_3_BORDER_WIDTH;
win->clw = win->client.r - win->client.l;
win->clh = win->client.b - win->client.t;
 
resize_context(win->ctx, win->clw, win->clh);
 
clear_context(win->ctx, 0xFFFFFFFF);
 
send_message((ctrl_t*)win, MSG_SIZE, 0, 0);
send_message((ctrl_t*)win, MSG_DRAW, 0, 0);
 
child = (ctrl_t*)win->child.next;
 
while( &child->link != &win->child)
{
send_message(child, MSG_DRAW, 0, 0);
child = (ctrl_t*)child->link.next;
};
}
 
win->rc.l = winx;
win->rc.t = winy;
win->rc.r = winx + winw;
win->rc.b = winy + winh;
win->w = winw;
win->h = winh;
win->win_state = state;
 
show_window(win);
};
 
 
ctrl_t *get_child(ctrl_t *ctrl, int x, int y)
{
ctrl_t *child = NULL;
 
ctrl_t *tmp = (ctrl_t*)ctrl->child.next;
 
while( &tmp->link != &ctrl->child )
{
if(pt_in_rect(&tmp->rc, x, y))
{
child = get_child(tmp, x, y);
return child == NULL ? tmp : child;
};
tmp = (ctrl_t*)tmp->link.next;
};
return child;
};
 
 
int send_mouse_message(window_t *win, uint32_t msg)
{
ctrl_t *child;
 
if(mouse_capture)
return send_message(mouse_capture, msg, 0, old_pos.val);
 
child = get_child((ctrl_t*)win, old_pos.x, old_pos.y);
 
if(msg == MSG_MOUSEMOVE)
{
if( win->child_over )
{
if(child == win->child_over)
send_message(child, MSG_MOUSEMOVE, 0, old_pos.val);
else
send_message(win->child_over, MSG_MOUSELEAVE, 0, old_pos.val);
}
else if( child )
send_message(child, MSG_MOUSEENTER, 0, old_pos.val);
 
win->child_over = child;
};
 
if( child )
return send_message(child, msg, 0, old_pos.val);
 
if(pt_in_rect(&win->client, old_pos.x, old_pos.y))
return send_message((ctrl_t*)win, msg, 0, old_pos.val);
 
};
 
#define DBG(x)
 
static void handle_sys_mouse(window_t *win)
{
static uint32_t mouse_click_time;
static int mouse_action;
static int old_buttons;
int buttons;
uint32_t wheels;
uint32_t click_time;
int action;
 
pos_t pos;
 
mouse_action = 0;
pos = get_mouse_pos(POS_WINDOW);
 
if(pos.val != old_pos.val)
{
mouse_action = 0x80000000;
old_pos = pos;
};
// printf("pos x%d y%d\n", pos.x, pos.y);
 
buttons = get_mouse_buttons();
wheels = get_mouse_wheels();
 
// if( wheels & 0xFFFF){
// wheels = (short)wheels>0 ? MSG_WHEELDOWN : MSG_WHEELUP;
// send_mouse_message(win, wheels);
// }
 
if((action = (buttons ^ old_buttons))!=0)
{
mouse_action|= action<<3;
mouse_action|= buttons & ~old_buttons;
}
old_buttons = buttons;
 
if(mouse_action & 0x80000000) {
DBG("mouse move \n\r");
send_mouse_message(win, MSG_MOUSEMOVE);
};
 
if(mouse_action & 0x09)
{
if((mouse_action & 0x09)==0x09)
{
// printf("left button down x= %d y= %d\n\r", old_x.x, old_x.y);
click_time = get_tick_count();
if(click_time < mouse_click_time+35) {
mouse_click_time = click_time;
send_mouse_message(win,MSG_LBTNDBLCLK);
}
else {
mouse_click_time = click_time;
send_mouse_message(win,MSG_LBTNDOWN);
};
}
else {
// printf("left button up \n\r");
send_mouse_message(win,MSG_LBTNUP);
}
};
 
if(mouse_action & 0x12)
{
if((mouse_action & 0x12)==0x12) {
DBG("right button down \n\r");
send_mouse_message(win,MSG_RBTNDOWN);
}
else {
DBG("right button up \n\r");
send_mouse_message(win,MSG_RBTNUP);
};
};
if(mouse_action & 0x24)
{
if((mouse_action & 0x24)==0x24){
DBG("middle button down \n\r");
send_mouse_message(win,MSG_MBTNDOWN);
}
else {
DBG("middle button up \n\r");
send_mouse_message(win,MSG_MBTNUP);
};
};
};
 
 
int handle_system_events(window_t *win)
{
oskey_t key;
 
for (;;)
{
switch (get_os_event())
{
case MSG_SYS_PAINT:
handle_sys_paint(win);
break;
 
case MSG_SYS_KEY:
key = get_key();
printf("key %d\n", key.code);
break;
 
case MSG_SYS_BUTTON:
// button pressed; we have only one button, close
return 0;
 
case MSG_SYS_MOUSE:
handle_sys_mouse(win);
break;
};
 
if( (win->win_state != MINIMIZED) &&
(win->win_state != ROLLED) )
show_context(win->ctx);
}
 
return 0;
}
 
void *create_control(size_t size, int id, int x, int y,
int w, int h, ctrl_t *parent)
{
 
ctrl_t *ctrl;
 
if( !parent )
return NULL;
 
ctrl = (ctrl_t*)malloc(size);
 
link_initialize(&ctrl->link);
list_initialize(&ctrl->child);
 
ctrl->parent = parent;
 
ctrl->ctx = parent->ctx;
ctrl->font = parent->font;
ctrl->id = id;
 
ctrl->rc.l = x;
ctrl->rc.t = y ;
 
ctrl->rc.r = x + w;
ctrl->rc.b = y + h;
 
ctrl->w = w;
ctrl->h = h;
 
list_append(&ctrl->link, &parent->child);
 
return ctrl;
};
 
 
int move_ctrl(ctrl_t *ctrl, int x, int y, int w, int h)
{
rect_t rc;
rc.l = x;
rc.t = y;
rc.r = w;
rc.b = h;
 
send_message(ctrl, MSG_POSCHANGING, 0, &rc);
 
ctrl->rc.l = rc.l;
ctrl->rc.t = rc.t;
ctrl->rc.r = rc.l + rc.r;
ctrl->rc.b = rc.t + rc.b;
ctrl->w = rc.r;
ctrl->h = rc.b;
 
send_message(ctrl, MSG_POSCHANGE, 0, &rc);
 
return 1;
};
 
 
 
/*
*
*
*
*
*
*
*
*
*/
 
int def_ctrl_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
{
switch( msg )
{
 
};
 
return 0;
}
 
/*
*
*
*
*
*
*
*
*
*/
 
 
static void scroller_on_draw(scroller_t *scrl)
{
if(scrl->btn_up)
send_message((ctrl_t*)scrl->btn_up, MSG_DRAW, 0, 0);
 
if(scrl->btn_down)
send_message((ctrl_t*)scrl->btn_down, MSG_DRAW, 0, 0);
 
if(scrl->thumb)
send_message((ctrl_t*)scrl->thumb, MSG_DRAW, 0, 0);
 
if(scrl->tl_rect.t != scrl->tl_rect.b)
px_fill_rect(scrl->ctrl.ctx, &scrl->tl_rect, 0xFFE1D8D0);
 
if(scrl->br_rect.t != scrl->br_rect.b)
px_fill_rect(scrl->ctrl.ctx, &scrl->br_rect, 0xFFE1D8D0);
}
 
static void scroller_on_ownerdraw(scroller_t *scrl, ctrl_t *child)
{
typedef struct
{
ctrl_t ctrl;
 
uint32_t state;
 
char *caption;
int capt_len;
}button_t;
 
button_t *btn;
color_t color = 0xFFD7D7D7;
char t = (char)child->id;
rect_t rc;
 
switch(child->id)
{
case ID_SCROLLER_UP:
case ID_SCROLLER_DOWN:
btn = (button_t*)child;
if(btn->state & bPressed)
color = 0xFFB0B0B0;
else if(btn->state & bHighlight)
color = 0xFFE7E7E7;
 
rc = btn->ctrl.rc;
px_fill_rect(btn->ctrl.ctx, &rc, color);
rc.l+= 3;
rc.t+= 5;
draw_text_ext(btn->ctrl.ctx, sym_font, &t, 1, &rc, 0xFF000000);
break;
 
case ID_SCROLLER_THUMB:
btn = (button_t*)child;
color = 0xFFB0B0B0;
if(btn->state & bPressed)
color = 0xFF707070;
else if(btn->state & bHighlight)
color = 0xFF909090;
 
rc = btn->ctrl.rc;
px_fill_rect(btn->ctrl.ctx, &rc, color);
}
};
 
static void scroller_update_layout(scroller_t *scrl)
{
 
// th_size = scrl->pix_range*scrl->page_size/
// (scrl->max_range-scrl->min_range);
 
// if(th_size > scrl->pix_range)
// th_size = scrl->pix_range;
 
scrl->tl_rect.l = scrl->ctrl.rc.l;
scrl->br_rect.l = scrl->ctrl.rc.l;
 
scrl->tl_rect.r = scrl->ctrl.rc.r;
scrl->br_rect.r = scrl->ctrl.rc.r;
 
scrl->tl_rect.t = scrl->btn_up->rc.b;
scrl->tl_rect.b = scrl->thumb->rc.t;
 
scrl->br_rect.t = scrl->thumb->rc.b;
scrl->br_rect.b = scrl->btn_down->rc.t;
 
scrl->pix_range = scrl->ctrl.h - 40 - 20;
};
 
static void scroller_on_poschange(scroller_t *scrl, rect_t *pos)
{
move_ctrl(scrl->btn_up, pos->l, pos->t, pos->r, pos->r);
move_ctrl(scrl->btn_down, pos->l, pos->t+pos->b-pos->r, pos->r, pos->r);
move_ctrl(scrl->thumb, pos->l, pos->t+pos->r, pos->r, pos->r);
 
scroller_update_layout(scrl);
scroller_on_draw(scrl);
};
 
static void scroller_on_command(scroller_t *ctrl, int id, ctrl_t *child, int notify)
{
scroller_t *scrl = (scroller_t*)ctrl;
int thumb_pos = scrl->thumb_pos;
 
switch(id)
{
case ID_SCROLLER_UP:
if(scrl->thumb_pos > scrl->min_range)
scrl->thumb_pos--;
printf("scroll up\n");
break;
case ID_SCROLLER_DOWN:
if(scrl->thumb_pos < scrl->max_range)
scrl->thumb_pos++;
printf("scroll down\n");
break;
};
 
if(thumb_pos != scrl->thumb_pos)
{
rect_t rc = scrl->thumb->rc;
int offset = scrl->pix_range*scrl->thumb_pos;
offset /= scrl->max_range - scrl->min_range;
rc.t = scrl->ctrl.rc.t + scrl->btn_up->h + offset;
rc.r = scrl->thumb->w;
rc.b = scrl->thumb->h;
move_ctrl(scrl->thumb, rc.l, rc.t, rc.r, rc.b);
scroller_update_layout(scrl);
scroller_on_draw(scrl);
}
}
 
int scroller_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
{
scroller_t *scrl = (scroller_t*)ctrl;
 
switch( msg )
{
HANDLE_MSG(scrl, MSG_DRAW, scroller_on_draw);
HANDLE_MSG(scrl, MSG_COMMAND, scroller_on_command);
HANDLE_MSG(scrl, MSG_OWNERDRAW, scroller_on_ownerdraw);
HANDLE_MSG(scrl, MSG_POSCHANGE, scroller_on_poschange);
};
 
return 0;
};
 
 
scroller_t *create_scroller(uint32_t style, int id, int x, int y,
int w, int h, ctrl_t *parent)
{
scroller_t *scrl;
 
if( !parent )
return NULL;
 
scrl = create_control(sizeof(scroller_t), id, x, y, w, h, parent);
scrl->ctrl.handler = scroller_proc;
 
scrl->min_range = 0;
scrl->max_range = 100;
scrl->thumb_pos = 0;
scrl->page_size = 1;
 
scrl->btn_up = create_button(NULL, 1, ID_SCROLLER_UP, x, y, w, w, (ctrl_t*)scrl);
scrl->btn_down = create_button(NULL, 1, ID_SCROLLER_DOWN, x, y+h-w, w, w, (ctrl_t*)scrl);
scrl->thumb = create_button(NULL, 1, ID_SCROLLER_THUMB, x, w, w, w, (ctrl_t*)scrl);
 
scroller_update_layout(scrl);
 
return scrl;
};
 
 
/contrib/sdk/samples/freetype/txview/winlib/winlib.h
0,0 → 1,124
#ifndef __WINLIB_H__
#define __WINLIB_H__
 
#include <stdlib.h>
#include <kos32sys.h>
#include "control.h"
 
enum win_state{
NORMAL, MINIMIZED, ROLLED, MAXIMIZED, FULLSCREEN
};
 
 
typedef struct
{
link_t link;
link_t child;
 
handler_t *handler;
ctrl_t *parent;
 
ctx_t *ctx;
font_t *font;
 
uint32_t id;
uint32_t style;
 
rect_t rc;
int w;
int h;
 
rect_t saved;
rect_t client;
int clw;
int clh;
 
char *caption_txt;
ctrl_t *child_over;
ctrl_t *child_focus;
 
enum win_state win_state;
enum win_state saved_state;
 
}window_t;
 
 
#define HANDLE_MSG(ctrl, message, fn) \
case (message): return HANDLE_##message((ctrl), (arg1), (arg2), (fn))
 
/* void ctrl_on_draw(ctrl_t *ctrl) */
#define HANDLE_MSG_DRAW(ctrl, arg1, arg2, fn) \
((fn)(ctrl),0)
 
/* void ctrl_on_ownerdraw(ctrl_t *ctrl, ctrl_t *child) */
#define HANDLE_MSG_OWNERDRAW(ctrl, arg1, arg2, fn) \
((fn)((ctrl),((ctrl_t*)arg1)),0)
 
/* void ctrl_on_poschanging(ctrl_t *ctrl, rect_t *pos) */
#define HANDLE_MSG_POSCHANGING(ctrl, arg1, arg2, fn) \
((fn)((ctrl),((rect_t*)arg2)),0)
 
/* void ctrl_on_poschange(ctrl_t *ctrl, rect_t *pos) */
#define HANDLE_MSG_POSCHANGE(ctrl, arg1, arg2, fn) \
((fn)((ctrl),((rect_t*)arg2)),0)
 
/* void ctrl_on_mouseenter(ctrl_t *ctrl) */
#define HANDLE_MSG_MOUSEENTER(ctrl, arg1, arg2, fn) \
((fn)(ctrl),0)
 
/* void ctrl_on_mouseleave(ctrl_t *ctrl) */
#define HANDLE_MSG_MOUSELEAVE(ctrl, arg1, arg2, fn) \
((fn)(ctrl),0)
 
/* void ctrl_on_lbuttondown(ctrl_t *ctrl, int x, int y) */
#define HANDLE_MSG_LBTNDOWN(ctrl, arg1, arg2, fn) \
((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
 
#define HANDLE_MSG_LBTNDBLCLK(ctrl, arg1, arg2, fn) \
((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
 
/* void ctrl_on_lbuttonup(ctrl_t *ctrl, int x, int y) */
#define HANDLE_MSG_LBTNUP(ctrl, arg1, arg2, fn) \
((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
 
/* void ctrl_on_mousemove(ctrl_t *ctrl, int x, int y) */
#define HANDLE_MSG_MOUSEMOVE(ctrl, arg1, arg2, fn) \
((fn)((ctrl), ((pos_t)arg2).x, ((pos_t)arg2).y), 0L)
 
/* void ctrl_on_command(ctrl_t *ctrl, int id, ctrl_t *child, int notify) */
#define HANDLE_MSG_COMMAND(ctrl,arg1,arg2,fn) \
((fn)((ctrl),(int)(arg1 & 0xFFFF),(ctrl_t*)(arg2),(int)(arg1>>16)),0)
 
window_t *create_window(char *caption, int style, int x, int y,
int w, int h, handler_t handler);
int handle_system_events(window_t *win);
void show_window(window_t *win);
 
extern ctrl_t *mouse_capture;
 
static inline ctrl_t *capture_mouse(ctrl_t *newm)
{
ctrl_t *old = mouse_capture;
 
mouse_capture = newm;
 
__asm__ __volatile__(
"int $0x40"
::"a"(40), "b"(0x80000027));
 
return old;
}
 
static void release_mouse(void)
{
mouse_capture = NULL;
__asm__ __volatile__(
"int $0x40"
::"a"(40), "b"(0xC0000027));
}
 
extern font_t *sym_font;
 
int draw_text_ext(ctx_t *ctx, font_t *font, char *text, int len, rect_t *rc, color_t color);
 
#endif /* __WINLIB_H__ */